Skip to content
This repository has been archived by the owner on Feb 29, 2020. It is now read-only.

feat(system-addon): Implement SectionsManager for custom sections #3122

Merged
merged 1 commit into from
Aug 11, 2017

Conversation

AdamHillier
Copy link
Contributor

Closes #3119

@coveralls
Copy link

Coverage Status

Coverage remained the same at 86.407% when pulling af2d381 on AdamHillier:gh3119 into 8a0aa23 on mozilla:master.

sections: new Map(),
listeners: new Map(), // Subscribed to a specific event
feedListeners: new Set(), // Subscribed to all events
addListener(event, callback) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to use resource://gre/modules/EventEmitter.jsm instead of reimplementing this pattern?

const listeners = (this.listeners.get(event) || this.listeners.set(event, new Set()).get(event));
listeners.add(callback);
},
addFeedListener(callback) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the distinction between addListener and addFeedListener?

onUpdateRows({id, shouldBroadcast}) {
const {rows} = SectionsManager.sections.get(id);
if (rows) {
const action = {type: at.SECTION_ROWS_UPDATE, data: Object.assign({id}, {rows})};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can just be data: {id, rows}, no?

this.init();
break;
}
SectionsManager.notifyListeners(action.type);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you might want to pass the entire action for certain events – additionally, it might be easier to manage these kind of events as a single event type (maybe SectionManager.ACTION_DISPATCHED or something like that?)

@coveralls
Copy link

Coverage Status

Coverage remained the same at 86.407% when pulling 779ce11 on AdamHillier:gh3119 into 621c3d9 on mozilla:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 86.407% when pulling ff65d68 on AdamHillier:gh3119 into 0af0980 on mozilla:master.

Copy link
Contributor

@k88hudson k88hudson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, just fix that one nit and this is R+

this.init();
break;
}
if (SectionsManager.ACTIONS_TO_PROXY.includes(action.type)) {
Copy link
Contributor

@k88hudson k88hudson Aug 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to suggest that Set might make more sense for ACTIONS_TO_PROXY here since Set.has is faster, but after running a couple of jsperf tests it looks like that's only true for large lists;.includes is actually quite a bit faster (in Firefox) for small lists.
https://jsperf.com/set-has-or-array-includes https://jsperf.com/array-includes-and-find-methods-vs-set-has

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also check SectionsManager.sections.size, since emitting won't be necessary if no sections are installed

@as-pine-proxy
Copy link
Collaborator

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

Successfully merging this pull request may close these issues.

4 participants