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

enhancement: store.subscribe(listener, filter) #2814

Closed
wants to merge 3 commits into from

Conversation

warren-bank
Copy link

new (optional) input parameter: filter

  • its purpose is to conditionally filter when listener is called
  • when its value is:
    • undefined:
      • listener is called as normal
    • function:
      • input: (oldState, newState)
      • output: boolean
        • when truthy, listener is not informed of this state change
    • boolean && true:
      • listener is not informed when newState
        is equal (by reference) to oldState

new (optional) input parameter: `filter`

* its purpose is to conditionally filter when `listener` is called
* when its value is:
  * undefined:
    * `listener` is called as normal
  * `function`:
    * input: (oldState, newState)
    * output: boolean
      * when truthy, `listener` is not informed of this state change
  * `boolean` && true:
    * `listener` is not informed when `newState`
      is equal (by reference) to `oldState`
@warren-bank
Copy link
Author

warren-bank commented Jan 28, 2018

Hi.

I was just thinking..

  • maybe the name filter wasn't the absolute best choice?
    • normally, a filter function returns true to include and false to exclude..
      • whereas this is the other way around
    • would ignore or skip be preferable?
    • of course, this is strictly internal..
      • users passing a function into subscribe can call it anything they like..
      • or make it anonymous (for that matter)

Do you have any opinion?

npm install
node_modules/.bin/prettier "src/createStore.js" >"src/createStore.js"
@markerikson
Copy link
Contributor

markerikson commented Jan 29, 2018

This is very similar to the frequently-requested idea of having state and/or action passed to listeners, and we have no plans to implement this. If you'd like to do it yourself, you can implement it as a store enhancer.

For more info, see the FAQ entry on why state and action are not passed to subscribers, and the many prior discussions listed in issue #580 .

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

Successfully merging this pull request may close these issues.

2 participants