
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
backbone.nativeview
Advanced tools
A drop-in replacement for Backbone.View that uses only native DOM methods for element selection and event delegation. It has no dependency on jQuery.
NOTE: Backbone.NativeView relies on version 1.2.0 of Backbone. Backbone 1.1.2 is not compatible with Backbone.NativeView.
Load Backbone.NativeView with your favorite module loader or add as a script tag after you have loaded Backbone in the page. Wherever you had previously inherited from Backbone.View, you will now inherit from Backbone.NativeView.
var MyView = Backbone.NativeView.extend({
initialize: function(options) {
// ...
}
});
As an alternative, you may extend an existing View's prototype to use native methods, or even replace Backbone.View itself:
var MyBaseView = Backbone.View.extend(Backbone.NativeViewMixin);
or
var MyBaseView = Backbone.View.extend({
initialize: function(options) {
// If you go the prototype extension route be sure to set _domEvents in
// initialize yourself.
this._domEvents = [];
}
});
_.extend(MyBaseView.prototype, Backbone.NativeViewMixin);
or
Backbone.View = Backbone.NativeView;
var MyView = Backbone.View.extend({
initialize: function(options) {
// ...
}
});
Delegation:
var view = new MyView({el: '#my-element'});
view.delegate('click', view.clickHandler);
Undelegation with event names or listeners,
view.undelegate('click', view.clickHandler);
view.undelegate('click');
View-scoped element finding:
// for one matched element
_.first(view.$('.box')).focus();
// for multiple matched elements
_.each(view.$('.item'), function(el) {
el.classList.remove('active')
});
var fields = _.pluck(view.$('.field'), 'innerHTML');
NativeView makes use of querySelector
and querySelectorAll
. For IE7 and
below you must include a polyfill.
$el
property no longer exists on Views. Use el
instead.View#$
returns a NodeList instead of a jQuery context. You can
iterate over either using _.each
.With many thanks to @wyuenho for his initial code.
FAQs
A Backbone View powered by native DOM methods
The npm package backbone.nativeview receives a total of 26 weekly downloads. As such, backbone.nativeview popularity was classified as not popular.
We found that backbone.nativeview 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.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.