Skip to content

Enhance the subscribe api #86

Description

@ArrayZoneYour

I have a:

  1. Idea:

    • 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!'))
    • Do you think others will benefit from this change as well and it should in core package? 💡 Yes

    • Are you willing to (attempt) a PR yourself? ⚔
      Yes

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions