Browse Source

feature(return store from Spruce.store)

Ryan Chandler 5 years ago
parent
commit
be68a002e3
8 changed files with 10 additions and 6 deletions
  1. 0 0
      dist/spruce.js
  2. 0 0
      dist/spruce.js.map
  3. 0 0
      dist/spruce.module.js
  4. 0 0
      dist/spruce.module.js.map
  5. 0 0
      dist/spruce.umd.js
  6. 0 0
      dist/spruce.umd.js.map
  7. 6 2
      src/index.js
  8. 4 4
      tests/store.spec.js

File diff suppressed because it is too large
+ 0 - 0
dist/spruce.js


File diff suppressed because it is too large
+ 0 - 0
dist/spruce.js.map


File diff suppressed because it is too large
+ 0 - 0
dist/spruce.module.js


File diff suppressed because it is too large
+ 0 - 0
dist/spruce.module.js.map


File diff suppressed because it is too large
+ 0 - 0
dist/spruce.umd.js


File diff suppressed because it is too large
+ 0 - 0
dist/spruce.umd.js.map


+ 6 - 2
src/index.js

@@ -1,4 +1,4 @@
-import { domReady, buildInitExpression } from './utils'
+import { domReady, buildInitExpression, isNullOrUndefined } from './utils'
 import { createObservable } from './observable'
 import EventBus from './bus'
 
@@ -38,7 +38,11 @@ const Spruce = {
         }
     },
 
-    store: function (name, state = {}) {
+    store: function (name, state) {
+        if (state === undefined && this.stores[name]) {
+            return this.stores[name]
+        }
+
         if (! this.stores[name]) {
             this.stores[name] = state
         }

+ 4 - 4
tests/store.spec.js

@@ -9,11 +9,11 @@ test('Spruce.store() > namespace and data set correctly', () => {
         foo: 'bar'
     })
 
-    expect(Spruce.stores.testing).toEqual({
+    expect(Spruce.store('testing')).toEqual({
         foo: 'bar'
     })
 
-    expect(Spruce.stores.testing.foo).toEqual('bar')
+    expect(Spruce.store('testing').foo).toEqual('bar')
 })
 
 test('Spruce.store() > existing namespace will not be overwritten', () => {
@@ -21,7 +21,7 @@ test('Spruce.store() > existing namespace will not be overwritten', () => {
         foo: 'bar'
     })
 
-    expect(Spruce.stores.testing).toEqual({
+    expect(Spruce.store('testing')).toEqual({
         foo: 'bar'
     })
 
@@ -29,7 +29,7 @@ test('Spruce.store() > existing namespace will not be overwritten', () => {
         bob: 'car'
     })
 
-    expect(Spruce.stores.testing).toEqual({
+    expect(Spruce.store('testing')).toEqual({
         foo: 'bar'
     })
 })

Some files were not shown because too many files changed in this diff