소스 검색

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