-
Notifications
You must be signed in to change notification settings - Fork 15
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
Channels #5
Comments
Hi @jaetask 👋 I think this is a great idea. I have some things in mind base on that: 1. CompatibilityIt would be better if we can keep both API, so someone that don't want to bother with channels can still use this lib as it is right now. Maybe we can do this by testing if the second parameter is a function? 2. How about dispatch?What do you have in mind for the dispatcher?
3. Register a function?If we implement this, you can do whatever you can imagine: #3 const isMatching = (channel, type) => action => action.channel === channel && action.type === type
useBus(
isMatching('ui', 'ADD_ITERATION'),
() => setIterations(iterations + 1),
[iterations],
)
dispatch({ channel: 'ui', type: 'ADD_ITERATION' })
// or if you want to do it "better"
const dispatchUi = action => ({ ...action, channel: 'ui' })
dispatchUi({ type: 'ADD_ITERATION' }) I have a preference for the 3rd version, we then can add some helper like (matchChannelAndType(channel)(type)), and more. |
1. CompatibilityI agree, keeping both APIs is important. 2. dispatchYes, absolutely, I like the shorthand, longhand ability 3. SimplicityThe
|
3rd point is just example of how can achieve channels and more with the resolution of the issue #3 Do you want to take a look at #3 ? Thank you for your interest @jaetask :) |
@jaetask Hey 👋 With the last version (2.2.0 -or latest-) you can use your own functions. You can do something like this: const isMatching = (channel, type) => (event) => event.channel === channel && event.type === type
useBus(
isMatching('ui', 'ADD_ITERATION'),
() => setIterations(iterations + 1),
[iterations],
)
dispatch({
channel: 'ui',
type: 'ADD_ITERATION',
}) You can use lodash/isMatch too: import { isMatch } from 'lodash-es'
useBus(
isMatch({ channel: 'ui', type: 'ADD_ITERATION' }),
() => setIterations(iterations + 1),
[iterations],
)
dispatch({
channel: 'ui',
type: 'ADD_ITERATION',
}) |
HI, I really like where you are going with this idea. Would you consider extending the Map to a Map of Maps to enable channels?
Instead of strings
You could pass the channel which would reducer the listeners affected in a large system.
This would enable messages to be sent on a single channel
This is how apps used to communicate in systems like backbone, enabling nesting of comms to avoid global chatter.
Just an idea.
The text was updated successfully, but these errors were encountered: