react-model icon indicating copy to clipboard operation
react-model copied to clipboard

Enhance the subscribe api

Open ArrayZoneYour opened this issue 5 years ago • 0 comments

I have a:

  1. [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

ArrayZoneYour avatar Mar 26 '19 14:03 ArrayZoneYour