feature: closure generated stores
@@ -53,6 +53,10 @@ const Spruce = {
},
store(name, state, persist = false) {
+ if (typeof state === 'function') {
+ state = state()
+ }
+
if (persist) {
try {
this.stores[name] = this.retrieveFromLocalStorage(name, getMethods(state))
@@ -29,6 +29,28 @@ test('Spruce.store() > existing namespace will not be overwritten', () => {
bob: 'car'
})
+ expect(Spruce.store('testing')).toEqual({
+ foo: 'bar'
+ })
+})
+test('Spruce.store() > can be used with functions that generate stores', () => {
+ Spruce.store('testing', function () {
+ return {
+ bar: 'car'
expect(Spruce.store('testing')).toEqual({
foo: 'bar'