Sha256: 8191e54f4b77f3e786bb9f77c70c179d5c84b7db7a863bca835ee95ce4456c82

Contents?: true

Size: 974 Bytes

Versions: 8

Compression:

Stored size: 974 Bytes

Contents

rio.CollectionEntity = {
	create: function(options) {
		options = Object.extend({
			values: [],
			condition: function() { return true; }
		}, options);
		var collectionEntity = $A(options.values);
		
		collectionEntity.getModel = function() {
			return options.model;
		};
		
		collectionEntity.add = function(val) {
			if (val.__model == this.getModel() && !this.include(val) && options.condition(val)) {
				return this.push(val);
			}
		};
		
		collectionEntity.update = function(val) {
			var index = this.indexOf(val);
			if (val.__model == this.getModel() && options.condition(val)) {
				if (index < 0) {
					if (!val.__destroying) {
						this.push(val);
					}
				}
			} else {
				if (index >= 0) {
					this.splice(index, 1);
				}
			}
		};
		
		collectionEntity.remove = function(val) {
			if (this.include(val)) {
				this.splice(this.indexOf(val), 1);
			}
		};
		
		return collectionEntity;
	},

	toString: function() {
		return "CollectionEntity";
	}
};

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
riojs-0.0.7 public/javascripts/lib/collection_entity.js
riojs-0.0.6 public/javascripts/lib/collection_entity.js
riojs-0.0.5 public/javascripts/lib/collection_entity.js
riojs-0.0.4 public/javascripts/lib/collection_entity.js
riojs-0.0.3 public/javascripts/lib/collection_entity.js
riojs-0.0.2 public/javascripts/lib/collection_entity.js
riojs-0.0.1 public/javascripts/lib/collection_entity.js
riojs-0.0.0 public/javascripts/lib/collection_entity.js