Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ampersand-view

Package Overview
Dependencies
Maintainers
2
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ampersand-view - npm Package Compare versions

Comparing version 5.0.0 to 5.1.0

32

ampersand-view.js

@@ -19,2 +19,3 @@ var State = require('ampersand-state');

this._initializeBindings();
this._initializeSubviews();
this.initialize.apply(this, arguments);

@@ -219,3 +220,2 @@ this.set(_.pick(attrs, viewOptions));

// this is the replacement for method below potentially
_initializeBindings: function () {

@@ -230,2 +230,32 @@ if (!this.bindings) return;

_initializeSubviews: function () {
if (!this.subviews) return;
for (var item in this.subviews) {
this._parseSubview(this.subviews[item]);
}
},
_parseSubview: function (subview) {
var self = this;
var opts = {
selector: subview.container || '[role=' + subview.role + ']',
waitFor: subview.waitFor || '',
prepareView: subview.prepareView || function (el) {
return new subview.constructor({
el: el,
parent: self
});
}
};
function action() {
if (this.el && (!opts.waitFor || (opts.waitFor && getPath(this, opts.waitFor)))) {
var el = this.get(opts.selector);
this[name] = opts.prepareView(el);
this[name].render();
this.off('change', action);
}
}
this.on('change', action, this);
},
// ## getByRole

@@ -232,0 +262,0 @@ // Gets an element within a view by its role attribute.

2

package.json
{
"name": "ampersand-view",
"description": "A smart base view for Backbone apps, to make it easy to bind collections and properties to the DOM.",
"version": "5.0.0",
"version": "5.1.0",
"author": "Henrik Joreteg <henrik@andyet.net>",

@@ -6,0 +6,0 @@ "browser": "./ampersand-view.js",

require('./main');
require('./renderCollection');
//require('./renderCollection');

@@ -42,3 +42,2 @@ var test = require('tape');

test('registerSubview', function (t) {

@@ -549,1 +548,60 @@ var removeCalled = 0;

});
test('declarative subViews basics', function (t) {
var Sub = AmpersandView.extend({
template: '<span></span>'
});
var View = AmpersandView.extend({
template: '<div><div class="container"></div></div>',
autoRender: true,
subviews: {
sub1: {
container: '.container',
constructor: Sub
}
}
});
var view = new View();
t.equal(view.el.innerHTML, '<span></span>');
t.end();
});
test('make sure subviews dont fire until their `waitFor` is done', function (t) {
var Sub = AmpersandView.extend({
template: '<span>yes</span>'
});
var View = AmpersandView.extend({
template: '<div><span class="container"></span><span role="sub"></span></div>',
autoRender: true,
props: {
model2: 'state'
},
subviews: {
sub1: {
waitFor: 'model',
container: '.container',
constructor: Sub
},
sub2: {
waitFor: 'model2',
role: 'sub',
constructor: Sub
}
}
});
var view = new View();
t.equal(view._events.change.length, 2);
t.equal(view.el.outerHTML, '<div><span class="container"></span><span role="sub"></span></div>');
view.model = new Model();
t.equal(view._events.change.length, 1);
t.equal(view.el.outerHTML, '<div><span>yes</span><span role="sub"></span></div>');
view.model2 = new Model();
t.equal(view.el.outerHTML, '<div><span>yes</span><span>yes</span></div>');
t.notOk(view._events.change);
t.end();
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc