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.1.2 to 5.1.3

78

ampersand-view.js
var State = require('ampersand-state');
var Events = require('backbone-events-standalone');
var CollectionView = require('ampersand-collection-view');
var domify = require('domify');

@@ -341,70 +342,11 @@ var _ = require('underscore');

renderCollection: function (collection, ViewClass, container, opts) {
var self = this;
var views = [];
var options = _.defaults(opts || {}, {
filter: null,
viewOptions: {},
reverse: false
});
container = (typeof container === 'string') ? this.get(container) : container;
// store a reference on the view to it's collection views
// so we can clean up memory references when we're done
this.registerSubview(views);
function getViewBy(model) {
return _.find(views, function (view) {
return model === view.model;
});
}
function addView(model, collection, opts) {
var matches = options.filter ? options.filter(model) : true;
var view;
if (matches) {
view = getViewBy(model);
if (!view) {
view = new ViewClass(_({model: model, collection: collection}).extend(options.viewOptions));
views.push(view);
view.parent = self;
view.renderedByParentView = true;
if (!view.rendered) view.render({containerEl: container});
}
// give the option for the view to choose where it's inserted if you so choose
if (!view.insertSelf) {
if (options.reverse) {
container.insertBefore(view.el, container.firstChild);
} else {
container.appendChild(view.el);
}
}
view.delegateEvents();
}
}
function reRender() {
// empty without using jQuery's empty (which removes jQuery handlers)
container.innerHTML = '';
collection.each(function (model) {
addView(model);
});
}
this.listenTo(collection, 'add', addView);
this.listenTo(collection, 'remove', function (model) {
var index = views.indexOf(getViewBy(model));
if (index !== -1) {
// remove it if we found it calling animateRemove
// to give user option of gracefully destroying.
views.splice(index, 1)[0].animateRemove();
}
});
this.listenTo(collection, 'move sort', reRender);
this.listenTo(collection, 'refresh reset', function () {
// empty array calling `remove` on each
// without re-defining `views`
while (views.length) {
views.pop().remove();
}
reRender();
});
reRender();
var containerEl = (typeof container === 'string') ? this.get(container) : container;
var config = _.extend({
collection: collection,
el: containerEl,
view: ViewClass
}, opts);
var collectionView = new CollectionView(config);
collectionView.render();
this.registerSubview(collectionView);
}

@@ -411,0 +353,0 @@ });

8

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.1.2",
"version": "5.1.3",
"author": "Henrik Joreteg <henrik@andyet.net>",

@@ -18,3 +18,4 @@ "browser": "./ampersand-view.js",

"matches-selector": "1.x.x",
"underscore": "1.x.x"
"underscore": "1.x.x",
"ampersand-collection-view": "~1.0.0"
},

@@ -45,3 +46,4 @@ "devDependencies": {

"validate": "jshint .",
"start": "run-browser test/index.js"
"start": "run-browser test/index.js",
"test": "browserify test/index.js | tape-run"
},

@@ -48,0 +50,0 @@ "testling": {

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

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

t.ok(extraInfo.containerEl);
this.renderWithTemplate();
};

@@ -193,0 +194,0 @@

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