Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offer utility for state subscriptions, i.e. when a selector's value changes #3

Open
devinivy opened this issue Aug 30, 2019 · 2 comments
Labels
enhancement New feature or request

Comments

@devinivy
Copy link
Contributor

No description provided.

@devinivy devinivy added the enhancement New feature or request label Aug 30, 2019
@wswoodruff
Copy link
Contributor

Are we imagining a callback similar to store.subscribe?

Howbout an interface like this?

subscribeSelector(M.selectors.something, (newSelectorVal) => console.log('newSelectorVal', newSelectorVal));

@devinivy
Copy link
Contributor Author

devinivy commented Jul 8, 2020

I think something like that would be good. There is a reference implementation here: https://github.com/devinivy/fishbowl/blob/d0a535db41db15f39fffffd43ef8c02a9b8d51bf/packages/frontend/src/middle-end/helpers.js#L1-L17

  • How do we feel about immediately firing onChange?
  • How do we want to receive current and previous values, particularly for the initial call if onChange is fired immediately.
  • Should we offer an alterate equality comparison?
  • If so should the API work more like hook dependencies (compute a hash for direct comparison) or more like memoize-one's equality comparator (implement a function that receives two arguments and tells you if they're the same)?
  • Should there be an additional interface to this utility baked into the middle-end's startup, or will these always be setup by hand in the initializer?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants