소스 검색

Merge pull request #112 from ryangjchandler/revert-106-fix/regression-watchers

Revert "fix(watchers): not running on reset and thereafter"
Ryan Chandler 4 년 전
부모
커밋
92460c5071
8개의 변경된 파일1개의 추가작업 그리고 38개의 파일을 삭제
  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. 0 26
      examples/watchers-reset.html
  8. 1 12
      src/index.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


+ 0 - 26
examples/watchers-reset.html

@@ -1,26 +0,0 @@
-<html>
-    <head>
-        <script src="https://cdn.jsdelivr.net/gh/alpinejs/alpine@v2.x.x/dist/alpine.js" defer></script>
-    </head>
-    <body x-data>
-        <button>Reset store</button>
-
-        <template x-for="item in $store.todo">
-            <p x-text="item"></p>
-        </template>
-
-        <script src="/dist/spruce.umd.js"></script>
-
-        <script>
-            Spruce.store('todo', [])
-
-            Spruce.watch('todo', value => {
-                console.log(`Todo updated: ${value}.`)
-            })
-
-            document.querySelector('button').addEventListener('click', e => {
-                Spruce.reset('todo', [])
-            })
-        </script>
-    </body>
-</html>

+ 1 - 12
src/index.js

@@ -114,17 +114,6 @@ const Spruce = {
     },
 
     reset(name, state) {
-        // This line is needed to ensure any watchers on
-        // the store itself are run when reset.
-        this.runWatchers(this.stores[name], '__self', state)
-
-        // This conditional will take any existing watchers on
-        // the store being reset and apply them back to the new
-        // state (see issue #105).
-        if (! state['__watchers']) {
-            state['__watchers'] = this.stores[name].__watchers
-        }
-        
         this.stores[name] = state
     },
 
@@ -242,7 +231,7 @@ const Spruce = {
             return
         }
 
-        if (target.__watchers.has(key) && key !== '__self') {
+        if (target.__watchers.has(key)) {
             target.__watchers.get(key).forEach(f => f(value))
         }
 

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.