浏览代码

feature: allow using callbacks to generate state

Ryan Chandler 4 年之前
父节点
当前提交
e2ea6ec92c
共有 1 个文件被更改,包括 4 次插入0 次删除
  1. 4 0
      src/index.js

+ 4 - 0
src/index.js

@@ -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))