Created
August 26, 2013 17:11
-
-
Save richsoni/6343963 to your computer and use it in GitHub Desktop.
Put your backbone zombies through the woodchipper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#keep tabs on your vent bindings. If you dont kill them they will slowly walk toward your app, and suck its brains (memory) out | |
################# | |
# INSTEAD OF | |
# App.Vent.bind('some_event', _.bind(some_callback, this)) | |
# App.Vent.bind('other_event', _.bind(other_callback, this)) | |
# Do | |
@bindGlobalEvents | |
some_event: 'someCallback' | |
other_event |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Behind the scenes this will create a global array of pointers to your new Vent objects | |
# It also will bind these events to @ for you | |
bindGlobalEvents: (events) -> | |
@globalEvents ||= [] | |
for vent, callback of events | |
fun = _.bind @[callback], @ | |
@globalEvents.push App.Vent.bind(vent, fun) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# use a global variable to hold the view, and close that sucker before making a new one. | |
# if you dont it will come back and suck your brains | |
myView.close if myView | |
myView = new Backbone.View() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# |