arida
v0.1.1
Published
一个用于数据订阅的工具库,尤其适用于扩展react,以允许子组件可以订阅父组件的数据,当父组件的数据更新时,及时更新子组件数据。
Downloads
2
Readme
Introduction
A libabry for subcribing data what you'r interesting. when the part of data what you have subcibed has changed, the callback you have registered will be triggered. This is a data flow libary extends flux or reflux, you can pass data from compontents to its children or sibings.
Install
npm install arida
Usage example
import arida from 'arida';
const source = {name: 'aa', id: 2, dept: 'math'};
arida.init(source);
arida.subcribe(['name', 'id'], (payload) => {
console.log(payload);
});
arida.update({
name: 'lucy',
});
arida.update({
dept: 'chinese',
});
Run the example above, you will get {name: 'lucy'} on your console.
API
The following is an incomplete list of arida API. It should give you a general concept of arida's usage.
.init(object)
: Returns target object;.subcribe(keys, callback)
: subcribe the key(string) or keys(array), even an object that you'r interesting;.update(data)
: update date and dispatch its changes to observers;.get()
: Returns target object;
Contributing
We welcome all contributions, please submit any ideas as pull requests or as a GitHub issue.
Licence
MIT