Skip to content
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

Implement Context.unsubscribe() method #18

Open
dev101 opened this issue Jan 11, 2013 · 6 comments
Open

Implement Context.unsubscribe() method #18

dev101 opened this issue Jan 11, 2013 · 6 comments

Comments

@dev101
Copy link
Contributor

dev101 commented Jan 11, 2013

Don't you feel the need for Context.unsubscribe() method?
E.g. I want my component to listen for event only if it is active. So i call Context.listen() in component's .activate() function (imagine I don't use viewmodels). Currently there is no way to unsubscribe when the component is deactivated, meaning the event handler will be called anyway. But i don't want to handle this event when the component is hidden because e.g. it changes look&feel of component based on event data - it's a waste of resources.

@hasith
Copy link
Collaborator

hasith commented Jan 11, 2013

You are correct here. Do you have an implementation already for it, which we may pull?

Meanwhile try not to depend on the events too much.. i believe it is much better to use URLController as much as possible as that will let you to bookmark and use browser back button.

@dev101
Copy link
Contributor Author

dev101 commented Jan 11, 2013

I don't have implementation yet, though it's straightforward. Will prepare next week.
URLController is not always applicable, e.g. several components working on the same page without any transitions. Imagine gmail-like application, with a StatusBar component listening for notifications from Inbox and Chat components to update its contents. When a new message arrives via ajax, there no URL change, it is just displayed in the inbox, but the status bar has to be changed to "now you have one more unread message".

@dev101
Copy link
Contributor Author

dev101 commented Jan 11, 2013

Btw is unsubscribe the best name for this method?
You chose to have names in Context different from their pubsub's counterparts, so maybe you'd like to continue:

  • publish - notify
  • subscribe - listen
  • unsubscribe - ???

what are the alternatives? deafen ? unbind? off?

@hasith
Copy link
Collaborator

hasith commented Jan 11, 2013

Imagine gmail-like application, with a StatusBar component listening for notifications
You are spot-on here

Yes, publish, subscribe, unsubscribe style is a better use of names

@dev101
Copy link
Contributor Author

dev101 commented Jan 11, 2013

do you mean we should rename Context.notify() to Context.publish(), etc? That would break backward compatibility...

@hasith
Copy link
Collaborator

hasith commented Jan 15, 2013

Yes.. but BoilerplateJS is not intended to be used as a typical JS library, but as a reference architecture. It is just your own startup code.. you will be changing it a lot to suit your needs. When you do changes to that level, there is no simple way to upgrade to latest versions, unless someone do it manually. Therefore I dont think it has to be backward compatible.

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

No branches or pull requests

2 participants