Beispiel #1
0
	onremove: function (obj, old) {
		var fn = invoke('onremove', obj, old);
		oForEach(this.uindexes, fn);
		oForEach(this.filters, invoke('forEach', fn));
		if (!obj._destroyed) {
			obj._off('update', this.onupdate);
		}
	},
Beispiel #2
0
	create: e(function (id, schema, methods) {
		var ns, foreigns;
		if (this[id]) {
			throw new Error("Can't create namespace with that name");
		} else if (!id.match(nsIdRe)) {
			throw new Error("Invalid namespace id");
		}
		defineProperty(this, id, v(defineProperties(ns = create(nsp, {
			id: v(id),
			schema: v(processSchema(schema)),
			relations: v({}),
			foreigns: v(foreigns = {}),
			lists: v({ methods: [], lists: [] }),
			filters: c(null),
			implementation: v(this),
			length: c(0),
			waste: v({}),
			data: v(extend(datap, methods || {}))
		}), {
			onObjectDestroy: v(ns.onObjectDestroy.bind(ns)),
			onObjectUpdate: v(ns.onObjectUpdate.bind(ns))
		})));
		defineProperty(ns.schema, '_ns', v(ns));
		ns.on('update', this.updateObject);

		oForEach(schema, function (data, name) {
			if (typeof data.type === 'object') {
				foreigns[name] = data.type;
				data.type.createRelation(this, name);
			}
		}, ns);
		return ns;
	}),
Beispiel #3
0
	updateElement: function (el, data) {
		var attrs = data[0], children = data[1];
		oForEach(attrs, function (value, name) {
			this.setAttribute(el, name, value);
		}, this);
		this.processChildren(children).forEach(el.appendChild, el);
		return el;
	},
Beispiel #4
0
	Object.defineProperties = function (obj, props) {
		if (!obj || !props) {
			return _native2(obj, props);
		}
		oForEach(props, function (value, key) {
			defineProperty(obj, key, value);
		});
		return obj;
	};
Beispiel #5
0
		init: v(function (_super, cond, parent, name) {
			var length = 0;
			_super(this, parent, name || '');
			defineProperty(this, 'cond', v(cond));
			oForEach(parent.data, function (obj) {
				if (this.isValid(obj)) {
					this[obj._id] = obj;
					++length;
				}
			}, this);
			return defineProperty(this, 'length', c(length));
		}),
Beispiel #6
0
	_set: e(function (name, value, emitter) {
		var changed = [], old = copy(this), tmp;
		if (typeof name === 'object') {
			emitter = value;
			this._ns.validate(name, false, this);
			oForEach(name, setProperty.bind(this, changed));
		} else {
			tmp = {}; tmp[name] = value;
			this._ns.validate(tmp, false, this);
			setProperty.call(this, changed, value, name);
		}
		return changed.length ? defineProperty(this, '_updated',
			c(new Date))._emit(emitter, 'update', changed, old, this, emitter): this;
	}),
Beispiel #7
0
module.exports = function (data, ns) {
	var f = createp(filterFactory, {
		indexes: {},
		uindexes: {},
		filters: {},
		data: data,
		ns: ns
	});
	f.onupdate = f.onupdate.bind(f);
	oForEach(ns.schema, function (value, name) {
		if (value.filtered) {
			f.indexes[name] = isFunction(indexes[value.type]) ?
				indexes[value.type](f, name) :
				createp(indexes[value.type]).init(f, name);
		}
	});
	data.on('add', f.onadd.bind(f));
	data.on('remove', f.onremove.bind(f));
	oForEach(data, function (obj) {
		obj._on('update', this);
	}, f.onupdate);
	return f;
};
Beispiel #8
0
		init: function (f, name) {
			this.name = name;
			this.data = oMap(f.ns.schema[name].options, lock(Object));
			oForEach(f.data, this.onadd, this);
			return f.uindexes[name] = this;
		},
Beispiel #9
0
	onadd: function (obj) {
		var fn = invoke('onadd', obj);
		oForEach(this.uindexes, fn);
		oForEach(this.filters, invoke('forEach', fn));
		obj._on('update', this.onupdate);
	},