btford / btford/angular-socket-io

Preventing duplicate listeners

Open
#100 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
1.5k
Forks
225
PR merge metrics
No merged PRs in 30d

Description

Hi,
GREAT service! Thanks!
I have 2 questions:
1) In the docs you write: `Avoid duplicating event handlers when a user navigates back and forth between routes:`
I've found this part in the code:
`scope.$on('$destroy', function () {
socket.removeListener(eventName, forwardBroadcast);
});`
Did you mean this part is taking care of the duplicate issue? So I can create as many listeners as I want without fearing they would somehow remain?

2) When I inject the factory, it instantiates it. So now in my controller I have this `mySocket` which is actually `socketFactory()`. If I inject `mySocket` again, in a directive for instance, would it retrieve the same object or create a new instance? And if it is a new instance, would it create a new listener?

Thanks

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.