项目
在 GitHub 查看
ivantsov/redux-subscriber
关于
Subscribe to changes in any part of redux state
网站与应用开发实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 0
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文redux-subscriber
This package allows you to subscribe to changes in any part of Redux state.
Installation
npm install redux-subscriber --save
Usage
store.js
import {createStore} from 'redux';
import initSubscriber from 'redux-subscriber';
const store = createStore(...);
// "initSubscriber" returns "subscribe" function, so you can use it
const subscribe = initSubscriber(store);
somewhere-else.js
// or you can just import "subscribe" function from the package
import {subscribe} from 'redux-subscriber';
const unsubscribe = subscribe('user.messages.count', state => {
// do something
});
// if you want to stop listening to changes
unsubscribe();
Examples
- https://github.com/ivantsov/yandex-mail-notifier-chrome - real app that uses
redux-subscriber
API
initSubscriber(store) (default export) - initialize redux-subscriber, so after that you can use subscribe method.
Options
store- instance of Redux store.
Returns subscribe function.
subscribe(key, callbackFunction) - subscribe callbackFunction to changes.
Options
key- string which specified the part of state (e.g.user.message.count) to listen to.callbackFunction- function which will be called when the part of state has changed. New state is passed as a parameter.
Returns unsubscribe function which can be called to unsubscribe from changes.
探索相关项目
加载中…