react-model
react-model copied to clipboard
Enhance the subscribe api
I have a:
-
[x] Idea:
-
[x] What problem would it solve for you? 🐛 Developer can subscribe the state changes.
v2.x api
// subscribe actions // (storeName, actionList, callback) => void subscribe('Counter', ['increment'], () => (count += 1)) // subscribe properties changes // (storeName, mapStateFunction, callback) => void subscribe('Counter', state => state.count, () => alert('counter count change!'))
v3.x api
const store = Store({ // ... actions: { updateA: (s, payload) => { ... }, updateC: (s, payload) => { ... }, updateD: (s, payload) => { ... } } }) // subscribe actions store.subscribe(['updateA'], () => (count += 1)) // subscribe properties changes store.subscribe(state => state.A, () => alert('A change!'))
-
[x] Do you think others will benefit from this change as well and it should in core package? 💡 Yes
-
[x] Are you willing to (attempt) a PR yourself? ⚔ Yes
-