JSFiddle - React, Tailwind, and code Playground
by Ryan Duffy
JavaScript
// enyo.Store doesn't have a useful implementation of it's find success callback ... patching that
enyo.store.extend({name:"ImplementsDidFind", didFind:function (opts, res) {
if (opts) {
if (opts.success) { opts.success(res); }
}
}});
// "interface" for a cache provider. basic operations to manage a cache scoped by a className
enyo.kind({
name: "enyo.CacheProvider",
kind: "Component",
get: function(className, key) {},
set: function(className, key, value) {},
remove: function(className, key) {},
removeAll: function(className) {}
});
// in-memory implementation of enyo.CacheProvider
// overlaps the records collection of enyo.Store but stores the raw
// version rather than the enyo.Model. Not sure if this makes sense yet.
enyo.kind({
name: "enyo.InMemoryCache",
kind: "enyo.CacheProvider",
statics: {
cache: {}
},
cache: function(className) {
var c = enyo.InMemoryCache.cache;
if(!className) return c;
var classCache = c[className];
if(!classCache) {
classCache = c[className] = {};
}
return classCache;
},
get: function(className, key) {
var c = this.cache(className);
return c[key];
},
set: function(className, key, value) {
return this.cache(className)[key] = value;
},
remove: function(className, key) {
var c = this.cache(className);
var v = c[key];
delete c[key];
return v;
},
removeAll: function(className) {
var c = enyo.InMemoryCache.cache[className];
delete enyo.InMemoryCache.cache[className];
return c;
}
});
// provides localStorage backing for a InMemoryCache
enyo.kind({
name: "enyo.LocalStorageCache",
kind: "enyo.InMemoryCache",
//* @public
//* overrride local storage key prefix
keyPrefix: "enyo.LocalStorageCache",
//* delay to persisting...