Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subscribe (subscriber, actionSubscriber) 这里有点问题 #26

Open
18657769868 opened this issue Jun 1, 2020 · 0 comments
Open

subscribe (subscriber, actionSubscriber) 这里有点问题 #26

18657769868 opened this issue Jun 1, 2020 · 0 comments

Comments

@18657769868
Copy link

// 实现 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant