Pārlūkot izejas kodu

feature(watchers): new method for getting all watchers

Ryan Chandler 4 gadi atpakaļ
vecāks
revīzija
6e0980e73b

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
dist/spruce.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
dist/spruce.js.map


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
dist/spruce.module.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
dist/spruce.module.js.map


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
dist/spruce.umd.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
dist/spruce.umd.js.map


+ 2 - 0
examples/persisted-watchers.html

@@ -13,6 +13,8 @@
                 enabled: false,
                 enabled: false,
             }, true);
             }, true);
 
 
+            Spruce.watch('test', () => {})
+
             const [unwatch] = Spruce.watch('test.enabled', function (enabled) {
             const [unwatch] = Spruce.watch('test.enabled', function (enabled) {
                 console.log(enabled)
                 console.log(enabled)
             });
             });

+ 22 - 0
src/index.js

@@ -255,6 +255,28 @@ const Spruce = {
         watchers.get(part).delete(callback)
         watchers.get(part).delete(callback)
     },
     },
 
 
+    watchers(name) {
+        const nameParts = name.split('.')
+
+        const target = nameParts.reduce((target, part) => {
+            const sub = target[part]
+
+            if (! isNullOrUndefined(sub) && (isObject(sub) || isArray(sub))) {
+                return sub
+            }
+
+            return target
+        }, this.stores)
+
+        const part = Object.is(target, this.get(name)) ? '__self' : nameParts[nameParts.length - 1]
+
+        if (! target.__watchers) {
+            return {}
+        }
+
+        return target.__watchers.get(part)
+    },
+
     runWatchers(target, key, value) {
     runWatchers(target, key, value) {
         if (! target.__watchers) {
         if (! target.__watchers) {
             return
             return

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels