-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
unstableSubscribeStore: support store descriptors #45481
Conversation
Open in CodeSandbox Web Editor | VS Code | VS Code Insiders |
Size Change: 0 B Total Size: 1.28 MB ℹ️ View Unchanged
|
Thanks for the ping. Yeah I agree, I would love to see the registry |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
What if we, instead of adding a new method, just overloaded the existing subscribe?
Or we could add a second argument to subscribe
to specify which store(s) we want to subscribe to.
subscribe( listener, [ shopStore, profileStore ] );
Pros:
- The first argument is the same, the API is easier to type and less confusing.
Cons:
- Kind of not what we're used to for a "subscribe"-like API.
I'm okay with both approaches though, just want to throw an idea out 😜 .
Specifying the store as a second argument is probably better, because we don't need to do tricks in the implementation like: function subscribe( store, listener ) {
if ( typeof store === 'function' ) {
listener = store;
store = undefined;
}
/* ... */
} This is also hard to type. I don't like the list of stores, though, because, first, I'd like to have consistency with other registry APIs that also take the store as an argument: registry.select( storeName );
registry.dispatch( storeName );
registry.subscribe( listener, storeName ); Second, |
Sounds reasonable to me! 👍 |
If we want to stabilize the
__unstableSubscribeStore
method, one of the requirements is to support store descriptors (objects) instead of just string store names. This PR adds that support.What if we, instead of adding a new method, just overloaded the existing
subscribe
?subscribe( listener: () => void ): () => void
subscribes to all storessubscribe( storeName: StoreNameOrDescriptor, listener )
would subscribe just to one storeThis way the
subscribe
method is symmetrical to the existingregistry.select( storeName )
andregistry.dispatch( storeName )
. Every store, no matter how it's implemented, must support selecting, dispatching, and subscribing, and the registry methods are the standard way to access the individual stores.CC @alexflorisca