Fix bad imports
This commit is contained in:
parent
f78d651a8f
commit
0624c5c8ab
|
|
@ -1,8 +1,8 @@
|
|||
import { un_entity } from './utils/index';
|
||||
import { setCache, getCache } from '~/utils/cache';
|
||||
import Cache from './utils/cache';
|
||||
|
||||
function draw_canvas(code, width, height, random) {
|
||||
let result = getCache(code);
|
||||
let result = Cache.get(code);
|
||||
if (result) {
|
||||
return Promise.resolve(result);
|
||||
}
|
||||
|
|
@ -24,7 +24,7 @@ function draw_canvas(code, width, height, random) {
|
|||
} catch(e) {
|
||||
// ignore
|
||||
}
|
||||
return Promise.resolve(setCache(code, canvas.toDataURL()));
|
||||
return Promise.resolve(Cache.set(code, canvas.toDataURL()));
|
||||
}
|
||||
|
||||
export {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import { uniform_time } from './uniform';
|
|||
|
||||
import get_props from './utils/get-props';
|
||||
import { get_variable, get_all_variables } from './utils/variables';
|
||||
import { clearCache } from './utils/cache';
|
||||
import Cache from './utils/cache';
|
||||
|
||||
import {
|
||||
make_tag_function,
|
||||
|
|
@ -39,7 +39,7 @@ class Doodle extends HTMLElement {
|
|||
}
|
||||
|
||||
update(styles) {
|
||||
clearCache();
|
||||
Cache.clear();
|
||||
let use = this.get_use();
|
||||
if (!styles) styles = un_entity(this.innerHTML);
|
||||
this.innerHTML = styles;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import { un_entity } from './utils/index';
|
||||
import { getCache, setCache } from '~/utils/cache';
|
||||
import Cache from './utils/cache';
|
||||
|
||||
let counter = 1;
|
||||
|
||||
function make_paint(code, random) {
|
||||
let result = getCache(code);
|
||||
function make_paint(code) {
|
||||
let result = Cache.get(code);
|
||||
if (result) {
|
||||
return Promise.resolve(result);
|
||||
}
|
||||
|
|
@ -22,7 +22,7 @@ function make_paint(code, random) {
|
|||
}
|
||||
} catch(e) {}
|
||||
|
||||
return Promise.resolve(setCache(code, `paint(${name})`));
|
||||
return Promise.resolve(Cache.set(code, `paint(${name})`));
|
||||
}
|
||||
|
||||
export {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { setCache, getCache } from './utils/cache';
|
||||
import Cache from './utils/cache';
|
||||
|
||||
function create_shader(gl, type, source) {
|
||||
let shader = gl.createShader(type);
|
||||
|
|
@ -56,7 +56,7 @@ function load_texture(gl, image, i) {
|
|||
}
|
||||
|
||||
function draw_shader(shaders, width, height) {
|
||||
let result = getCache(shaders);
|
||||
let result = Cache.get(shaders);
|
||||
if (result) {
|
||||
return Promise.resolve(result);
|
||||
}
|
||||
|
|
@ -110,7 +110,7 @@ function draw_shader(shaders, width, height) {
|
|||
gl.drawArrays(gl.TRIANGLES, 0, 6);
|
||||
|
||||
// resolve image data in 72dpi :(
|
||||
return Promise.resolve(setCache(shaders, canvas.toDataURL()));
|
||||
return Promise.resolve(Cache.set(shaders, canvas.toDataURL()));
|
||||
}
|
||||
|
||||
export {
|
||||
|
|
|
|||
|
|
@ -1,26 +1,28 @@
|
|||
import { hash, is_nil } from './index';
|
||||
import { hash, is_nil } from './index.js';
|
||||
|
||||
let _cache = {};
|
||||
|
||||
export function clearCache() {
|
||||
_cache = {};
|
||||
}
|
||||
|
||||
export function setCache(input, value) {
|
||||
if (is_nil(input)) {
|
||||
return '';
|
||||
class CacheValue {
|
||||
constructor() {
|
||||
this.cache = {};
|
||||
}
|
||||
clear() {
|
||||
this.cache = {};
|
||||
}
|
||||
set(input, value) {
|
||||
if (is_nil(input)) {
|
||||
return '';
|
||||
}
|
||||
let key = this.getKey(input);
|
||||
return this.cache[key] = value;
|
||||
}
|
||||
get(input) {
|
||||
let key = this.getKey(input);
|
||||
return this.cache[key];
|
||||
}
|
||||
getKey(input) {
|
||||
return (typeof input === 'string')
|
||||
? hash(input)
|
||||
: hash(JSON.stringify(input));
|
||||
}
|
||||
let key = getKey(input);
|
||||
return _cache[key] = value;
|
||||
}
|
||||
|
||||
export function getCache(input) {
|
||||
let key = getKey(input);
|
||||
return _cache[key];
|
||||
}
|
||||
|
||||
function getKey(input) {
|
||||
return (typeof input === 'string')
|
||||
? hash(input)
|
||||
: hash(JSON.stringify(input));
|
||||
}
|
||||
export default new CacheValue();
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { getCache, setCache } from './cache';
|
||||
import Cache from './cache';
|
||||
|
||||
export default function(prefix, fn) {
|
||||
return (...args) => {
|
||||
let key = prefix + args.join('-');;
|
||||
return getCache(key) || setCache(key, fn.apply(null, args));
|
||||
return Cache.get(key) || Cache.set(key, fn.apply(null, args));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue