8000 subscribe (subscriber, actionSubscriber) 这里有点问题 · Issue #26 · herculesJS/herculex · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
subscribe (subscriber, actionSubscriber) 这里有点问题 #26
Open
@18657769868

Description

@18657769868

// 实现 store.subscribe
subscribe (subscriber, actionSubscriber) {
const emitter = this.$emitter;
const originViewInstance = getCurrentPages().pop() || {};
if (subscriber) {
this.storeUpdateLisitenerDispose = emitter.addListener('updateState', ({ state, mutation, prevState }) => {
const currentPageInstance = getCurrentPages().pop() || {};
const instanceView = originViewInstance.$viewId || -1;
const currentView = currentPageInstance.$viewId || -1;
// 已经不在当前页面的不再触发
if (instanceView === currentView) {
subscriber(mutation, wrapState({ ...this.storeInstance.data }), wrapState({ ...prevState }));
}
});
}
if (actionSubscriber) {
this.storeDispatchActionLisitenerDispose = emitter.addListener('dispatchAction', (action, next) => {
actionSubscriber(action, next);
});
}
};

如果这个方法 subscribe 调用2次了,那么在unload 生命周期里面 this.storeUpdateLisitenerDispose 只有一个被执行注销掉Listener

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0