Selaa lähdekoodia

Revert "fix(watchers): not running on reset and thereafter"

Ryan Chandler 4 vuotta sitten
vanhempi
commit
8bb1ed90a5

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 0 - 0
dist/spruce.js


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 0 - 0
dist/spruce.js.map


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 0 - 0
dist/spruce.module.js


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 0 - 0
dist/spruce.module.js.map


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 0 - 0
dist/spruce.umd.js


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 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))
         }
 

Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä