소스 검색

tests(Spruce.watch)

Ryan Chandler 5 년 전
부모
커밋
031ad14f03
9개의 변경된 파일25개의 추가작업 그리고 6개의 파일을 삭제
  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. 5 1
      src/bus.js
  8. 0 5
      src/index.js
  9. 20 0
      tests/bus.spec.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


+ 5 - 1
src/bus.js

@@ -37,6 +37,10 @@ export default {
     runWatchers(stores, target, key) {
         const self = this
 
+        if (self.watchers[key]) {
+            return self.watchers[key].forEach(callback => callback(target[key]))
+        }
+
         Object.keys(self.watchers)
             .filter(watcher => watcher.includes('.'))
             .forEach(fullDotNotationKey => {
@@ -45,7 +49,7 @@ export default {
                 if (key !== dotNotationParts[dotNotationParts.length - 1]) return
 
                 dotNotationParts.reduce((comparison, part) => {
-                    if (Object.is(target, comparison)) {
+                    if (comparison[key] === target[key] || Object.is(target, comparison)) {
                         self.watchers[fullDotNotationKey].forEach(callback => callback(target[key]))
                     }
 

+ 0 - 5
src/index.js

@@ -4,7 +4,6 @@ import EventBus from './bus'
 
 const Spruce = {
     options: {
-        enableUpdateEvents: true,
         globalStoreVariable: false,
     },
 
@@ -27,10 +26,6 @@ const Spruce = {
                 this.events.runWatchers(this.stores, target, key)
 
                 this.updateSubscribers(key, value)
-
-                if (this.options.enableUpdateEvents) {
-                    this.emit('updated')
-                }
             }
         })
 

+ 20 - 0
tests/bus.spec.js

@@ -64,4 +64,24 @@ test('.emit() > will dispatch browser event to window with spruce: prefix', asyn
     await waitFor(() => {
         expect(document.querySelector('span').innerText).toEqual('car')
     })
+})
+
+test('.watch() > can listen for changes to property', async () => {
+    let fixture = undefined
+    
+    Spruce.store('example', {
+        cool: 'stuff'
+    })
+
+    Spruce.watch('example.cool', (value) => {
+        fixture = value
+    })
+
+    await Spruce.start()
+
+    expect(fixture).toBeUndefined()
+
+    Spruce.stores.example.cool = 'amazing'
+
+    expect(fixture).toEqual('amazing')
 })

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