瀏覽代碼

feature(return store from Spruce.store)

Ryan Chandler 5 年之前
父節點
當前提交
be68a002e3
共有 8 個文件被更改,包括 10 次插入6 次删除
  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

文件差異過大導致無法顯示
+ 0 - 0
dist/spruce.js


文件差異過大導致無法顯示
+ 0 - 0
dist/spruce.js.map


文件差異過大導致無法顯示
+ 0 - 0
dist/spruce.module.js


文件差異過大導致無法顯示
+ 0 - 0
dist/spruce.module.js.map


文件差異過大導致無法顯示
+ 0 - 0
dist/spruce.umd.js


文件差異過大導致無法顯示
+ 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'
     })
 })

部分文件因文件數量過多而無法顯示