Esempio n. 1
0
	conf.on('clear' + postfix, function () {
		forEach(timeouts, function (id) { clearTimeout(id); });
		timeouts = {};
		if (preFetchTimeouts) {
			forEach(preFetchTimeouts, function (id) {
				if (id !== 'nextTick') clearTimeout(id);
			});
			preFetchTimeouts = {};
		}
	});
Esempio n. 2
0
File: base.js Progetto: dlpc/domjs
	_elementProto: d(function (name) {
		var proto = create(getPrototypeOf(this.document.createElement(name)));
		forEach(ext._element, function (value, name) {
			defineProperty(proto, name, d(value));
		});
		if (ext[name]) {
			forEach(ext[name], function (value, name) {
				defineProperty(proto, name, d(value));
			});
		}
		defineProperties(proto, {
			domjs: d(this),
			_directives: d(this.getDirectives(name))
		});
		return proto;
	}),
Esempio n. 3
0
module.exports = function self(fn/*, options */) {
	var options, length, conf;

	callable(fn);
	options = Object(arguments[1]);

	if (options.async && options.promise) {
		throw new Error("Options 'async' and 'promise' cannot be used together");
	}

	// Do not memoize already memoized function
	if (hasOwnProperty.call(fn, '__memoized__') && !options.force) return fn;

	// Resolve length;
	length = resolveLength(options.length, fn.length, options.async && extensions.async);

	// Configure cache map
	conf = configure(fn, length, options);

	// Bind eventual extensions
	forEach(extensions, function (fn, name) {
		if (options[name]) fn(options[name], conf, options);
	});

	if (self.__profiler__) self.__profiler__(conf);

	conf.updateEnv();
	return conf.memoized;
};
Esempio n. 4
0
module.exports = Input = function (document, type/*, options*/) {
	var options = arguments[2], onChange = this.onChange.bind(this);
	this.document = document;
	this.type = type;
	options = resolveOptions(options, type);
	if (options.observable) this.observable = options.observable;
	this.onChange = once(onChange);
	this._resolveDbAttributes(options);
	this._render(options);
	this.dom._dbjsInput = this;
	if (options.name) this.name = options.name;
	this.required = (options.required != null)
		? Boolean(options.required) : options.dbOptions.required;
	forEach(options, function (value, name) {
		if (name === 'class') {
			mergeClass.call(this.dom, value);
		} else if (htmlAttrs[name] || startsWith.call(name, 'data-')) {
			castAttr.call(this.dom, name, value);
		} else if (name === 'control') {
			forEach(value, function (value, name) {
				this.castControlAttribute(name, value);
			}, this);
		} else {
			this.castControlAttribute(name, value);
		}
	}, this);
	onChange();
	if (this.control) this.control.addEventListener('change', this.onChange, false);
};
Esempio n. 5
0
		fromInputValue: d(function (value) {
			var empty, result, owner, index, resolvedPath;
			if (value == null) return null;
			if (isPlainObject(value)) {
				empty = true;
				forEach(value, function (subValue, name) {
					var sKey = this._serialize_(name)
					  , desc = this._getDescriptor_(sKey);
					subValue = desc.type.fromInputValue(subValue);
					value[name] = subValue;
					if (subValue != null) empty = false;
				}, this.prototype);
				return empty ? null : value;
			}
			value = value.trim();
			if (!value) return null;
			result = this.getById(value);
			if (result) return result;
			if (db.objects.getById(value)) return null;
			// If it's about nested, it might be that it's not loaded into memory
			// Below logic ensures it's retrieved properly
			index = value.indexOf('/');
			if (index === -1) return null;
			owner = db.objects.getById(value.slice(0, index));
			if (!owner) return null;
			resolvedPath = owner.resolveSKeyPath(value.slice(index + 1));
			if (!resolvedPath) return null;
			value = resolvedPath.value;
			if (value && (value instanceof this)) return value;
			return null;
		}),
Esempio n. 6
0
	handler.notify = function (senderId, data) {
		forEach(clients, function (client, id) {
			if (senderId === id) return;
			if (log) console.log("Notified: " + id);
			client.res.write('data: ' + data + '\nid:' + (++count) + '\n\n');
		});
	};
Esempio n. 7
0
	return (b[index - 1] = function (props) {
		forEach(props, function (desc, name) {
			var value = callable(desc.value);
			desc.value = function (options) { return fn(value.bind(this), options); };
		});
		return lazy(props);
	});
Esempio n. 8
0
			promise.close = function () {
				if (promises) {
					if (!def.resolved) def.reject(new Error("Operation aborted"));
					forEach(promises, invoke("close"));
					promises = null;
					paths.close();
				}
			};
Esempio n. 9
0
	name: d.gs(getName, function (name) {
		this._name = name;
		name = this.name;
		if (name) {
			if (this.obj) {
				this.objInput.setAttribute('name', name);
			} else {
				forEach(this.items, function (item, propName) {
					item.name = name + '.' + propName;
				});
			}
		} else if (this.obj) {
			this.objInput.removeAttribute('name');
		} else {
			forEach(this.items, function (item) { item.name = null; });
		}
	}),
Esempio n. 10
0
File: base.js Progetto: dlpc/domjs
	_textProto: d(function () {
		var proto = create(getPrototypeOf(this.document.createTextNode('')), {
			domjs: d(this)
		});
		forEach(ext._text, function (value, name) {
			defineProperty(proto, name, d(value));
		});
		return proto;
	})
Esempio n. 11
0
	close: function () {
		if (this.readers) {
			forEach(this.readers, function (data) {
				data.files.close();
				if (data.dirs) data.dirs.close();
			});
			delete this.readers;
		}
	},
Esempio n. 12
0
addPath = function (conf, path, opts) {
	if (!conf.hasOwnProperty(path)) {
		conf[path] = copy(opts);
		return;
	}
	forEach(opts, function (value, name) {
		extendOption(conf[path], name, value);
	});
};
Esempio n. 13
0
	syncComputedSet: d(function (source, target, event) {
		var sourceIterator, targetIterator, item, isDifferent, stamp, sourceKeys, targetKeys;

		if (source.size === target.size) {
			if (!source.size) return;
			sourceIterator = source.values();
			targetIterator = target.values();
			item = sourceIterator.next();
			while (!item.done) {
				if (item.value !== targetIterator.next().value) {
					isDifferent = true;
					break;
				}
				item = sourceIterator.next();
			}
			if (sourceIterator._destroy) sourceIterator._destroy();
			if (targetIterator._destroy) targetIterator._destroy();
			if (!isDifferent) return;
		}
		stamp = (event && event.stamp) || 0;
		forEach(target.__setData__, function (item) {
			var event = item._lastOwnEvent_;
			if (!event) return;
			if (event.stamp >= stamp) stamp = event.stamp + 1;
		});
		target.forEach(function (item) {
			var sObj;
			if (!source.has(item)) {
				if (item.hasOwnProperty('__id__')) {
					sObj = source.object.database.objects.getById(item.__id__);
					if (!sObj) {
						throw new TypeError("Could not find '" + item.__id__ + "' object in source database");
					}
					this.syncExternal(target.dbId, sObj, true, undefined);
				}
				propagateComputedItem.call(this, stamp++, target.dbId, undefined, item);
			}
		}, this);
		source.forEach(function (item) {
			if (item.hasOwnProperty('__id__')) this.syncExternal(target.dbId, item, true, true);
			propagateComputedItem.call(this, stamp++, target.dbId, true, item);
		}, this);
		if (source.size !== target.size) {
			sourceKeys = [];
			targetKeys = [];
			source.forEach(function (item) { sourceKeys.push(serializeKey(item)); });
			target.forEach(function (item) { targetKeys.push(serializeKey(item)); });
			throw new Error("Database reduction error:\n" +
				"\tComputed set (" + source.dbId + ") of size \"" + target.size +
				"\" in result database after propagation didn't match one in source (size: \"" +
				source.size + "\"\n" +
				"\tKeys not found in target: " + diff.call(sourceKeys, targetKeys) + "\n" +
				"\tMost likely it's caused by model not being completely tagged for propagation\n" +
				"\t(type of propagated set values doesn't match defined type)");
		}
	}),
Esempio n. 14
0
	maps.forEach(function (map) {
		forEach(map.map, function (rules, path) {
			if (!rules.length) return;
			if (!data[path]) {
				paths.push(path);
				data[path] = [];
			}
			data[path].push(rules);
		});
	});
Esempio n. 15
0
			paths.on("end", function (data, err) {
				if (!promises) return;
				forEach(promises, invoke("close"));
				promises = null;
				if (!def.resolved) {
					def.reject(err);
					return;
				}
				promise.emit("end", result, err);
			});
Esempio n. 16
0
	close: function () {
		if (this.promises) {
			forEach(this.promises, invoke("close"));
			this.known = true;
			delete this.promises;
		}
		if (!this.promise.resolved) {
			this.reject(new Error("Find root action cancelled"));
		}
	},
Esempio n. 17
0
	setTimeout(function () {
		if (tests.length) {
			tests.shift()();
		} else {
			def.resolve();
			forEach(data, function (value, name, obj, index) {
				console.log(pad.call(index + 1 + ":", " ", 3),
					pad.call(value, " ", 5) + "ms ", name);
			}, null, function (a, b) { return this[a] - this[b]; });
		}
	}, 100);
Esempio n. 18
0
	forEach(options, function (value, name) {
		if (name === 'class') {
			mergeClass.call(this.dom, value);
		} else if (htmlAttrs[name] || startsWith.call(name, 'data-')) {
			castAttr.call(this.dom, name, value);
		} else if (name === 'control') {
			forEach(value, function (value, name) {
				this.castControlAttribute(name, value);
			}, this);
		} else {
			this.castControlAttribute(name, value);
		}
	}, this);
Esempio n. 19
0
module.exports = exports = function (str) {
	var variables = create(null);
	str = str.replace(rootRuleRe, function (all, first, data) {
		data.replace(varsDefineRe, function (property, name, value) {
			variables[name] = value.trim();
		});
		return first;
	});
	forEach(variables, function (value, name) {
		str = str.replace(new RegExp('(\\s|:)var\\(\\s*--' + reEscape(name) + '\\s*\\)', 'g'),
			'$1' + value);
	});
	return str;
};
Esempio n. 20
0
				lint(function (data) {
					if (!stream) {
						forEach(data, function (report, subname) {
							subname = name + sep + subname;
							if (result[subname]) {
								// Duplicate
								ignores[subname] = true;
								return;
							}
							result[subname] = report;
							names.push(subname);
						});
					}
				}, function () {
Esempio n. 21
0
								function (dir) {
									var path = rootPath + dir + sep, reader = this.readers[path];
									if (reader) {
										reader.files.close();
										if (reader.dirs) reader.dirs.close();
										reader.files.onend(reader.files.value);
										forEach(this.readers, function (newReader, key) {
											if (startsWith.call(key, path)) {
												newReader.files.close();
												if (newReader.dirs) newReader.dirs.close();
												newReader.files.onend(newReader.files.value);
											}
										});
									}
								}.bind(this)
Esempio n. 22
0
parseOptions = function (goptions, id) {
	var options = {};
	id = id.toLowerCase();
	forEach(goptions, function (value, name) {
		var oid;
		if (contains.call(name, '.')) {
			oid = name.split('.', 1)[0];
			if (oid !== id) {
				return;
			}
			name = name.slice(oid.length + 1);
		}
		options[name] = value;
	});
	return options;
};
Esempio n. 23
0
	return function (props) {
		forEach(props, function (desc, name) {
			var fn = callable(desc.value), length;
			desc.value = function (options) {
				if (options.getNormalizer) {
					options = normalizeOpts(options);
					if (length === undefined) {
						length = resolveLength(options.length, fn.length, options.async && extensions.async);
					}
					options.normalizer = options.getNormalizer(length);
					delete options.getNormalizer;
				}
				return memoize(fn.bind(this), options);
			};
		});
		return lazy(props);
	};
Esempio n. 24
0
	syncProperties: d(function (object) {
		var sKey, desc, observable, event;

		for (sKey in object.__descriptors__) {
			desc = object.__descriptors__[sKey];
			if (desc.reverse != null) continue;
			if (desc.nested) {
				if (object.hasOwnProperty('__objects__') && object.__objects__[desc._sKey_]) {
					this.syncProperties(object.__objects__[desc._sKey_]);
				}
				continue;
			}
			if (!desc[this.base.propertyName]) continue;

			// Export!
			if (!desc._resolveValueGetter_()) {

				// Static
				this.namesToSync[object.__id__ + '/' + sKey] = true;
				if (desc.multiple) {
					if (!object.hasOwnProperty('__multiples__')) continue;
					if (!hasOwnProperty.call(object.__multiples__, sKey)) continue;
					forEach(object.__multiples__[sKey], this.syncObjectDirectly, this);
					continue;
				}
				if (desc.object !== object) continue;
				this.syncObjectDirectly(desc);
				continue;
			}

			// Computable
			if (desc.multiple) {
				this.observed.push(observable = object._get_(sKey));
				event = object._getPropertyLastEvent_(sKey);
				this.groundComputedSet(observable, event);
				this.syncComputedSet(observable, resolveTargetValue(this.base.db, object.__id__, sKey),
					event);
				observable.on('change', this.onSetChangeEvent);
				continue;
			}
			this.observed.push(observable = object._getObservable_(sKey));
			this.syncComputedValue(observable, object._getPropertyLastEvent_(sKey));
			observable.on('change', this.onChangeEvent);
		}
	}),
Esempio n. 25
0
exports.log = function () {
	var initial, cached, ordered, ipad, cpad, ppad, toPrc, log;

	initial = cached = 0;
	ordered = [];

	toPrc = function (initial, cached) {
		if (!initial && !cached) {
			return '0.00';
		}
		return ((cached / (initial + cached)) * 100).toFixed(2);
	};

	log = "------------------------------------------------------------\n";
	log += "Memoize statistics:\n\n";

	forEach(stats, function (data, name) {
		initial += data.initial;
		cached += data.cached;
		ordered.push([name, data]);
	}, null, function (a, b) {
		return (this[b].initial + this[b].cached) -
			(this[a].initial + this[a].cached);
	});

	ipad = partial.call(pad, " ",
		max(String(initial).length, "Init".length));
	cpad = partial.call(pad, " ", max(String(cached).length, "Cache".length));
	ppad = partial.call(pad, " ", "%Cache".length);
	log += ipad.call("Init") + "  " +
		cpad.call("Cache") + "  " +
		ppad.call("%Cache") + "  Source location\n";
	log += ipad.call(initial) + "  " +
		cpad.call(cached) + "  " +
		ppad.call(toPrc(initial, cached)) + "  (all)\n";
	ordered.forEach(function (data) {
		var name = data[0];
		data = data[1];
		log += ipad.call(data.initial) + "  " +
			cpad.call(data.cached) + "  " +
			ppad.call(toPrc(data.initial, data.cached)) + "  " + name + "\n";
	});
	log += "------------------------------------------------------------\n";
	return log;
};
Esempio n. 26
0
	inputValue: d.gs(function () {
		var mock = setPrototypeOf({}, this.observable.object.master), context = mock
		  , path, current, dbjsObj;
		forEach(getInputValue.call(this), function (value, keyPath) {
			var names = tokenize(keyPath.slice()), propName = names.pop(), name
			  , obj = mock, dbjsObj = this.observable.object.master;
			names.shift(); // clear object id
			while ((name = names.shift())) {
				if (!obj.hasOwnProperty(name)) {
					defineProperty(obj, name, d('cew', {}));
					if (dbjsObj[name]) {
						setPrototypeOf(obj[name], dbjsObj[name]);
						defineProperty(obj[name], 'owner', d('cew', obj));
						defineProperty(obj[name], 'master', d('cew', mock));
						dbjsObj = dbjsObj[name];
					}
				}
				obj = obj[name];
			}
			defineProperty(obj, propName, d('cew', value));
			defineProperty(obj, '_' + propName, d('cew', value));
		}, this);
		if (this.observable.object !== this.observable.object.master) {
			path = [];
			current = this.observable.object;
			while (current && (current !== this.observable.object.master)) {
				path.push(current.key);
				current = current.owner;
			}
			dbjsObj = this.observable.object.master;
			path.reverse().forEach(function (name) {
				if (!context.hasOwnProperty(name)) {
					defineProperty(context, name, d('cew', {}));
					if (dbjsObj[name]) {
						setPrototypeOf(context[name], dbjsObj[name]);
						dbjsObj = dbjsObj[name];
					}
				}
				context = context[name];
			});
		}
		return this.getValue.call(context, observeMock);
	}, noop)
Esempio n. 27
0
module.exports = function (e1, e2) {
	var data;
	(validValue(e1) && validValue(e2));
	if (!hasOwnProperty.call(e1, '__ee__')) {
		if (!hasOwnProperty.call(e2, '__ee__')) {
			d.value = create(null);
			defineProperty(e1, '__ee__', d);
			defineProperty(e2, '__ee__', d);
			d.value = null;
			return;
		}
		d.value = e2.__ee__;
		defineProperty(e1, '__ee__', d);
		d.value = null;
		return;
	}
	data = d.value = e1.__ee__;
	if (!hasOwnProperty.call(e2, '__ee__')) {
		defineProperty(e2, '__ee__', d);
		d.value = null;
		return;
	}
	if (data === e2.__ee__) return;
	forEach(e2.__ee__, function (listener, name) {
		if (!data[name]) {
			data[name] = listener;
			return;
		}
		if (typeof data[name] === 'object') {
			if (typeof listener === 'object') push.apply(data[name], listener);
			else data[name].push(listener);
		} else if (typeof listener === 'object') {
			listener.unshift(data[name]);
			data[name] = listener;
		} else {
			data[name] = [data[name], listener];
		}
	});
	defineProperty(e2, '__ee__', d);
	d.value = null;
};
Esempio n. 28
0
	_resolveDbAttributes: d(function (options) {
		if (this._dbAttributesResolved) return;
		options.dbOptions = Object(options.dbOptions);
		forEach(this.dbAttributes, function (name, dbName) {
			var value;
			if (!name) return;
			if (name === true) name = dbName;
			if (options[name] != null) return;
			if (options.dbOptions[dbName] != null) {
				value = options.dbOptions[dbName];
			} else if (this.type[dbName] != null) {
				value = this.type[dbName];
			} else {
				if (dbName === 'required') return;
				if (this.type[dbName] != null) value = this.type[dbName];
				else return;
			}
			options[name] = value;
		}, this);
		defineProperty(this, '_dbAttributesResolved', d(true));
	}),
Esempio n. 29
0
Fieldset = function (document, list/*, options*/) {
	var options = Object(arguments[2]);

	this.document = document;
	this.list = list;
	this.items = {};
	this.options = Object(options.control);
	this.customOptions = Object(options.controls);
	this.prepend = options.prepend;
	this.append = options.append;

	this.list = list.map(this.renderItem, this);
	if (isObservable(this.list)) this.list.on('change', this.reload);

	this.render();
	forEach(options, function (value, name) {
		if (!htmlAttributes[name] && !startsWith.call(name, 'data-')) return;
		castAttribute.call(this.dom, name, value);
	}, this);
	this.dom.classList.add('dbjs');
	this.dom._dbjsFieldset = this;

	this.reload();
};
Esempio n. 30
0
	value: d.gs(function () { return this.inputValue; }, function (value) {
		var obj;
		if (value === undefined) value = null;
		if (this.obj === value) return;
		obj = value || this.type.prototype;
		forEach(this.items, function (oldInput, name) {
			var nuInput, observable = obj._get(name);
			oldInput.destroy();
			nuInput = observable.toDOMInput(this.document,
				this.getOptions(observable.descriptor));
			replace.call(oldInput.dom, nuInput.dom);
			if (!value) nuInput.name = this.name + '.' + name;
			this.addItem(nuInput, name);
		}, this);
		if (value && !isNested(value)) {
			this.objInput.setAttribute('value', value.__id__);
			include.call(this.objInput);
		} else {
			this.objInput.removeAttribute('value');
			exclude.call(this.objInput);
		}
		this.obj = value;
		this.name = this._name;
	})