/
eb
/
js-excel
Обзор
Документация
Войти
/
eb
/
js-excel
Код
Запросы
0
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/core/StoreSubscriber.js
36 строк
869 B
Evgeniy Budaev
Routing implemented
17 июн 2020, 10:58
17 июн 2020, 10:58
6622668
Код
Авторство
О чём код?
import {isEqual} from "@core/utils"; export class StoreSubscriber { constructor(store) { this.store = store this.sub = null this.prevState = {} } subscribeComponents(components) { this.prevState = this.store.getState() this.sub = this.store.subscribe(state => { Object.keys(state).forEach(key => { // console.log(key) if (!isEqual(this.prevState [key], state[key])) { components.forEach(component => { if (component.isWatching(key)) { const changes = {[key]: state[key]} component.storeChanged(changes) } }) } }) this.prevState = this.store.getState() if (process.env.NODE_ENV === 'development') { window['redux'] = this.prevState } }) } unsubscribeFromStore() { this.sub.unsubscribe() } }