Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
backbone-bind-to
Advanced tools
Backbone.js extension for automatic binding and unbinding of model events to views.
Backbone.js extension for automatic binding and unbinding of model events to views.
In a lot of Backbone.js applications when you want to react to model events you have to write:
window.UserCardView = Backbone.View.extend({
initialize: function() {
this.model.bind('change:name', this.renderName, this);
this.model.bind('change:email', this.renderEmail, this);
},
remove: function() {
this.model.unbind('change:name', this.renderName, this);
this.model.unbind('change:email', this.renderEmail, this);
Backbone.View.prototype.remove.apply(this, arguments);
},
renderName: function() { /* ... code ... */ },
renderEmail: function() { /* ... code ... */ }
});
With Backbone.BindTo you can just do:
window.UserCardView = Backbone.View.extend({
bindToModel: {
'change:name': 'renderName',
'change:email': 'renderEmail'
},
renderName: function() { /* ... code ... */ },
renderEmail: function() { /* ... code ... */ }
});
Of course, there is a similar method for binding to collection events:
window.TodoListView = Backbone.View.extend({
bindToCollection: {
'add': 'renderNewTask'
},
renderNewTask: function() { /* ... code ... */ }
});
You can also use a generic bind function:
window.CommentView = Backbone.View.extend({
initialize: function() {
this.parentView.on('editing:start', this.onEditingStart, this);
},
remove: function() {
this.parentView.off('editing:start', this.onEditingStart, this);
Backbone.View.prototype.remove.apply(this, arguments);
},
onEditingStart: function() { /* ... code ... */ }
});
Can be simplified as:
window.CommentView = Backbone.View.extend({
initialize: function() {
this.bindTo(this.parentView, 'editing:start', 'onEditingStart');
},
onEditingStart: function() { /* ... code ... */ }
});
It can also accept a raw function:
window.CommentView = Backbone.View.extend({
initialize: function() {
this.bindTo(this.parentView, 'editing:start', function() {
console.log('editing has started');
});
}
});
DOM/jQuery elements are also supported:
window.CommentView = Backbone.View.extend({
initialize: function() {
this.bindTo(window, 'click', windowClicked)
},
windowClicked: function() { /* ... code ... */ }
});
Backbone.BindTo automatically unbinds
from all model and collection events when the view element is removed via Backbone.View#remove
. Also unbinds from all events binded via #bindTo
.
If extending directly Backbone.View
bothers you. You can use the Backbone.BindTo.noConflict
method. It restores Backbone.View
to its original value. And returns the Backbone.BindTo.View
object which has the bindToModel
and bindToCollection
helpers.
window.BindToView = Backbone.BindTo.noConflict()
You can get Backbone.BindTo
in several ways:
lib/backone_bind_to.js
into your projectsrc/backbone_bind_to.coffee
into your project if you are using CoffeeScriptbower install Backbone.BindTo
from your consoleBackbone.BindTo
as your bower dependencyBackbone.js - 0.9.2+
Install bower developer dependencies - bower install
.
Just open - test/runner.html
.
Every fresh idea and contribution will be highly appreciated.
If you are making changes please do so in the coffee
files. And then compile them with:
cake build
MIT License.
FAQs
Backbone.js extension for automatic binding and unbinding of model events to views.
The npm package backbone-bind-to receives a total of 0 weekly downloads. As such, backbone-bind-to popularity was classified as not popular.
We found that backbone-bind-to demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.