Ejemplo n.º 1
0
	unserialize: function(data) {
		// Make sure we have an array
		if (! _.isArray(data)) {
			return this.emit('error', 'Collection::unserialize expects an array');
		}

		// Get a copy of the old model array so we can keep repeats
		var old = this.models.slice();

		// Empty out the models array (while keeping the same array object)
		this.models.length = 0;

		// Iterate through the contained data
		for (var i = 0, c = data.length; i < c; i++) {
			// Make sure we have a standardized object and then fetch the ID from it
			var value = cloak.idObj(data[i]);
			var id = value[cloak.config.idKey];

			// Check if we already have a model matching these results
			var model = _.find(old, function(model) {
				return (model.id() === id);
			});

			// Put the model we found (or the new model) into the model array
			this.models.push(model || this.model.create(value));
		}

		return this;
	},
Ejemplo n.º 2
0
	_deferToSubRouters: function() {
		var temp = this._currentUrl;
		this._currentUrl = null;

		var sub = _.find(this._subRouters, function(subRouter) {
			return subRouter._onstatechange();
		});

		this._currentUrl = temp;

		if (sub) {
			this._currentRoute = sub._currentRoute;
		}

		return !! sub;
	}
Ejemplo n.º 3
0
		this.on(cloak.event('change.*'), function(value, old, attr) {
			if (! _.find(this._changedLocally, attr)) {
				this._changedLocally.push(attr);
			}
		});
Ejemplo n.º 4
0
		this.models = _.rejectInPlace(this.models, function(model) {
			return !! _.find(models, function(matchAgainst) {
				return model.is(matchAgainst) && removed.push(model);
			});
		});
Ejemplo n.º 5
0
	find: function(what) {
		return _.find(this.models, function(model) {
			return model.is(what);
		});
	},