Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
backbone-base-view
Advanced tools
Baseview is a extended backbone view with convenient methods for manipulating subviews and events.
Backbone view extension with enhanced event handling and convenient helpers for handling sub-views. Compose view components with simple and easy to use api. Weighs less than 3KB.
BaseView extends backbone view events functionality so you can bind one time events, inject variables into event strings and setup global window and document listeners that will be properly unbound once view is removed. Enables easy composition of views with simple parent-child and model binding api that keeps you safe from memory leaks.
Define one time events, inject variables and add window and document listeners.
events: {
'click .selector': 'handler',
'click {{this.someVariable}}': 'handler', // variable will be injected
'one:submit form': 'oneSubmit', // handler will run only once
'resize window': 'onWindowResize',
'keyup document': 'onDocumentKeyup'
}
If defined user passed options will be merged with defaults and written to viewInstance.options. False by default.
var View = BaseView.extend({
assignOptions: true,
defaults: {test: 1},
initialize: function() {
console.log(this.options); // outputs {foo:'bar', test: 1}
}
});
var view = new View({foo:'bar'});
Options provided by type defaults and and constructor parameters can be type checked and validated.
var MusicianView = BaseView.extend({
optionRules: {
instrument: String,
age: {type: Number, default: 18, validator: function(age) {
return age >= 18;
}},
mentorView: {type: BaseView, required: false}
url: [String, Function]
}
});
View event handlers are delegated to instance element by default. Set to false to bind directly to elements found via event string selector.
var View = BaseView.extend({
delegatedEvents: false,
events: {
'click .selector': 'handler'
}
});
var view = new View({foo:'bar'});
When escape key is pressed or something outside of view.$el is clicked view.listenerName will be invoked.
...
open: function() {
this.$el.addClass('active');
this.addDismissListener('close');
}
close: function() {
this.$el.removeClass('active');
this.removeDismissListener('close');
}
...
Use to remove dismiss listeners. See example above.
Use to setup parent-child view relationship. Child view is added to parent view group if groupName is specified.
...
initialize: function() {
this.collection.each(function(model) {
this.addView(new ChildView, 'itemList');
}, this);
}
...
Retrieve child views stored in parent group as array.
...
render: function() {
_.each(this.getGroupViews('itemList'), function(subView) {
subView.render();
});
}
...
Removes all sub views. If viewGroup is specified removes only group views.
parentView.removeViews('itemList');
Does extended cleanup and triggers "beforeRemove" and "afterRemove" events on view instance.
view.remove();
Get parent sub-view by providing it's model instance.
var childView = parentView.getViewByModel(model);
Close sub-view by providing it's model instance.
parentView.removeViewByModel(model);
Check if parent view has child sub-view.
console.log(parentView.hasView(childView));
Detach view from parent sub-view registry.
childView.detachView();
Detach view from parent sub-view registry and attach to another view.
childView.attachToView(parentView)
Append view.$el to another view.$el. Other available methods are 'prependTo', 'insertBefore', 'insertAfter'.
view.appendTo(parentView);
Shortcut for $.when with default context set to view instance for all callbacks. Additionally adds all deferreds to view instance deferreds stack so effective cleanup can be performed on view removal. Accepts resources as single or array of deferreds.
Backbone base view is packaged as UMD library so you can use it in CommonJS and AMD environment or with browser globals.
npm install backbone-base-view --save
// with bundlers
var BaseView = require('backbone-base-view');
// with browser globals
var BaseView = window.BaseView;
FAQs
Baseview is a extended backbone view with convenient methods for manipulating subviews and events.
We found that backbone-base-view 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
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.