浏览代码

remove(event bus)

Ryan Chandler 4 年之前
父节点
当前提交
acdf64f075
共有 1 个文件被更改,包括 0 次插入72 次删除
  1. 0 72
      src/bus.js

+ 0 - 72
src/bus.js

@@ -1,72 +0,0 @@
-export default {
-    watchers: {},
-
-    events: {},
-
-    on(name, callback, once = false) {
-        if (! this.events[name]) {
-            this.events[name] = []
-        }
-
-        this.events[name].push({ callback, once })
-
-        return () => this.off(name, callback)
-    },
-
-    once(name, callback) {
-        this.on(name, callback, true)
-    },
-
-    off(name, callback) {
-        this.events[name] = this.events[name].filter(registerCallback => {
-            return registerCallback.callback !== callback && registerCallback.once !== true
-        })
-    },
-
-    emit(name, data = {}) {
-        (this.events[name] || []).forEach(callback => {
-            callback.callback(data)
-
-            if (callback.once) {
-                this.off(name, callback)
-            }
-        })
-
-        window.dispatchEvent(new CustomEvent(`spruce:${name}`, {
-            detail: data,
-            bubbles: true
-        }))
-    },
-
-    watch(dotNotation, callback) {
-        if (! this.watchers[dotNotation]) {
-            this.watchers[dotNotation] = []
-        }
-
-        this.watchers[dotNotation].push(callback)
-    },
-
-    runWatchers(stores, target, key, value) {
-        const self = this
-
-        if (self.watchers[key]) {
-            return self.watchers[key].forEach(callback => callback(value))
-        }
-
-        Object.keys(self.watchers)
-            .filter(watcher => watcher.includes('.'))
-            .forEach(fullDotNotationKey => {
-                let dotNotationParts = fullDotNotationKey.split('.')
-
-                if (key !== dotNotationParts[dotNotationParts.length - 1]) return
-
-                dotNotationParts.reduce((comparison, part) => {
-                    if (comparison[key] === target[key] || Object.is(target, comparison)) {
-                        self.watchers[fullDotNotationKey].forEach(callback => callback(value))
-                    }
-
-                    return comparison[part]
-                }, stores)
-            })
-    }
-}