-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Support the Channel as listener #12
Conversation
@vitalets И кстати что там с документацией? Надо что-то поправлять, чтобы здесь https://vitalets.github.io/chnl/ появился мой добавленный метод? |
src/channel.js
Outdated
* @param {Channel} channel | ||
*/ | ||
addProxyChannel(channel) { | ||
this._proxyChannels.push(channel); |
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.
channel instanceof Channel
?
And also this._proxyChannels.includes(channel)
src/channel.js
Outdated
* Register the channel to which events should be proxied | ||
* @param {Channel} channel | ||
*/ | ||
addProxyChannel(channel) { |
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.
I also propose to add removeProxyChannel
/removeAllProxyChannels
?
Please, use English ) |
src/channel.js
Outdated
@@ -1,8 +1,12 @@ | |||
const innerEvents = [ | |||
'onListenerAdded', | |||
'onListenerRemoved', | |||
'onProxyChannelAdded', |
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.
All of these is not needed:
'onProxyChannelAdded',
'onProxyChannelRemoved',
'onFirstProxyChannelAdded',
'onLastProxyChannelRemoved'
Proxying is just adding special listener.
Please update pr.
src/channel.js
Outdated
@@ -24,6 +28,7 @@ const innerEvents = [ | |||
export default class Channel { | |||
constructor(name, noInnerEvents) { | |||
this._listeners = []; | |||
this._proxyChannels = []; |
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.
Not needed.
test/channel.test.js
Outdated
proxyChannel.addListener(spy); | ||
channel.proxyTo(proxyChannel); | ||
t.is(spy.callCount, 0); | ||
channel.dispatch(); |
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.
Let's pass some data to ensure that data also proxied.
src/channel.js
Outdated
*/ | ||
_ensureChannel(channel) { | ||
if (!(channel instanceof Channel)) { | ||
throw new Error('Channel ' + this._name + ': proxyChannel doesn\'t instance of Channel'); |
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.
`Channel ${this._name}: proxyChannel doesn't instance of Channel`
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.
doesn't
-> is not
@vitalets @stamoern const channel1 = new Channel();
const channel2 = new Channel();
const channel3 = new Channel();
channel1.addListener(channel2);
channel1.addOnceListener(channel3);
channel1.hasListener(channel2);
new Channel.ReactSubscription(component, [
{ channel: channel1, listener: channel2 }
]) |
src/subscription-item.js
Outdated
@@ -55,8 +57,8 @@ export default class SubscriptionItem { | |||
if (event && typeof event !== 'string') { | |||
throw new Error('Event should be string'); | |||
} | |||
if (!listener || typeof listener !== 'function') { | |||
throw new Error('Listener should be function'); | |||
if (!listener || (typeof listener !== 'function' && !(listener instanceof Channel))) { |
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.
lets add static Channel.isValidListener()
to avoid repeating typeof listener !== 'function' && !(listener instanceof Channel)
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 👍
No description provided.