Comparing version 0.14.0 to 0.15.0
{ | ||
"name": "deepjs", | ||
"main": "index.js", | ||
"version" : "0.13.0", | ||
"homepage" : "https://github.com/deepjs/deepjs.git", | ||
"version": "0.15.0", | ||
"homepage": "https://github.com/deepjs/deepjs.git", | ||
"authors": [ | ||
"Gilles Coomans <gilles.coomans@gmail.com>" | ||
], | ||
"description" : "atomic tools for better programming", | ||
"description": "atomic tools for better programming", | ||
"moduleType": [ | ||
@@ -14,3 +14,3 @@ "amd", | ||
], | ||
"keywords" : ["util", "promise", "asynch", "AOP", "query", "composition", "server", "client", "browser", "restful", "OCM"], | ||
"keywords": ["util", "promise", "asynch", "AOP", "query", "composition", "server", "client", "browser", "restful", "OCM"], | ||
"license": "LGPL 3.0", | ||
@@ -24,2 +24,2 @@ "ignore": [ | ||
] | ||
} | ||
} |
364
deep.js
@@ -1,8 +0,2 @@ | ||
/** | ||
* @module deep | ||
* @author Gilles Coomans <gilles.coomans@gmail.com> | ||
* TODO : adding events on : | ||
* modes : changed | ||
* | ||
*/ | ||
/** @author Gilles Coomans <gilles.coomans@gmail.com> */ | ||
if (typeof define !== 'function') { | ||
@@ -12,218 +6,178 @@ var define = require('amdefine')(module); | ||
define([ | ||
"require", | ||
"./lib/utils", | ||
"./lib/nodes/query", | ||
"./lib/nodes/dq-protocol", | ||
"./lib/compose", | ||
"./lib/collider", | ||
"./lib/compiler", | ||
"./lib/classes", | ||
"./lib/utils/interpret", | ||
"./lib/emitter", | ||
"./lib/errors", | ||
"./lib/nodes/rql", | ||
"./lib/promise", | ||
"./lib/context", | ||
"./lib/nodes/nodes", | ||
"./lib/utils/logs", | ||
"./lib/nodes/deep-load", | ||
"./lib/utils/deep-equal", | ||
"./lib/ocm", | ||
"./lib/nodes/traversal", | ||
"./lib/flatten", | ||
"./lib/protocol", | ||
"./lib/sheet", | ||
"./lib/nodes/nodes-composer", | ||
"./lib/nodes/nodes-chain", | ||
"./lib/restrictions", | ||
"./lib/validator" | ||
//"./lib/schema" | ||
], function(require, utils, query, dq, composer, collider, compiler, classes, interpret, emitter, errors, rql,promise, context, nodes, logs, deepLoader, deepEqual, ocm, traversal, flattener, protocol, sheets, NodesComposer, NodesChain, restrictions, Validator) { | ||
"deep-compiler/index", | ||
"deep-compiler/lib/classes", | ||
"deep-compiler/lib/restrictions", | ||
"deep-protocols/index", | ||
"./lib/cache", | ||
"./lib/promise", | ||
"deep-modes/index", | ||
"decompose/index", | ||
"./lib/nodes", | ||
"deep-nodes/lib/query", | ||
"deep-nodes/lib/rql", | ||
"deep-nodes/lib/traversal", | ||
"deep-nodes/lib/chained-api", | ||
"deep-ocm/index", | ||
"deep-flatten/index", | ||
"deep-sheets/index", | ||
"deep-utils/index", | ||
"deep-utils/lib/string", | ||
"deep-utils/lib/errors", | ||
"./lib/validator", | ||
"./lib/deepequal", | ||
"./lib/emitter", | ||
"./lib/logs", | ||
"deep-utils/lib/interpret" | ||
], | ||
function( | ||
compiler, | ||
Classes, | ||
restrictions, | ||
protocol, | ||
cache, | ||
promise, | ||
modes, | ||
decompose, | ||
nodes, | ||
Querier, | ||
rql, | ||
traversal, | ||
nodesChainedApi, | ||
ocm, | ||
flattener, | ||
sheeter, | ||
utils, | ||
stringUtils, | ||
errors, | ||
Validator, | ||
deepEqual, | ||
emitter, | ||
logger | ||
) { | ||
/*if (typeof deep !== 'undefined') { | ||
console.log("***********************************************************************************"); | ||
console.warn("You trying to load deepjs modules two times (maybe from two differents node_modules (or bower) module)"); | ||
console.warn("It could be voluntary. If not : you should think it twice. Protocols and context are local to deep instances (by examples)."); | ||
console.log("***********************************************************************************"); | ||
}*/ | ||
function copyTo(what, where) { | ||
for (var i in what) | ||
where[i] = what[i]; | ||
} | ||
var deep = {}; | ||
var deep = { | ||
Classes: Classes, | ||
compose: decompose, | ||
Querier: Querier, | ||
rql: rql, | ||
ocm: ocm, | ||
flatten: flattener.flatten, | ||
sheet: sheeter.sheet, | ||
utils: utils, | ||
cache: cache, | ||
Arguments: decompose.Arguments, | ||
errors: errors, | ||
query: Querier.query, | ||
isNode: (typeof process !== 'undefined' && process.versions && process.versions.node) | ||
}; | ||
deep.utils = utils; | ||
utils.nodes = nodes; | ||
utils.deepEqual = deepEqual; | ||
deep.transformers = {}; | ||
copyTo(promise, deep); | ||
copyTo(compiler, deep); | ||
copyTo(restrictions, deep); | ||
copyTo(protocol, deep); | ||
copyTo(traversal, deep); | ||
copyTo(modes, deep); | ||
copyTo(stringUtils, utils); | ||
copyTo(emitter, deep); | ||
copyTo(logger, deep); | ||
deep.log = logs.log; | ||
deep.warn = logs.warn; | ||
deep.error = logs.error; | ||
deep.setLogger = logs.setMain; | ||
delete deep.setModesIn; | ||
//___________________________________________________ | ||
// deepjs cross module definitions | ||
//___________________________________________________ | ||
deep.nodes = NodesChain.start; | ||
deep.utils.nodes = nodes; | ||
/** | ||
* are you on nodejs or not | ||
* @static | ||
* @property isNode | ||
* @type {Boolean} | ||
*/ | ||
deep.isNode = (typeof process !== 'undefined' && process.versions && process.versions.node); | ||
deep.context = function(name, value) { | ||
if (!name) | ||
return deep.Promise.context; | ||
if (!value) | ||
return deep.Promise.context[name]; | ||
return deep.Promise.context[name] = value; | ||
}; | ||
deep.contextualise = function(arg) { | ||
return new deep.Promise().contextualise(arg).fromContext().resolve(); | ||
}; | ||
/** | ||
* where to place YOUR globals (deep does'nt have any globals) | ||
* @static | ||
* @property globals | ||
*/ | ||
deep.globals = {}; | ||
/** | ||
* where to place YOUR globals headers to set on each store call (deep does'nt have any globals) | ||
* @static | ||
* @property globals | ||
*/ | ||
deep.globalHaders = {}; | ||
//require("./lib/utils")(deep); | ||
deep.errors = errors; | ||
deep.rql = rql; | ||
deep.collider = collider; | ||
for (var i in traversal) | ||
deep[i] = traversal[i]; | ||
/** | ||
* equal test strict equality on success value against provided object | ||
* If equal, forward success (it's transparent). | ||
* If not equal, inject 412 error with report | ||
*/ | ||
nodes.equal = function(s, needed) { | ||
var tmp = s; | ||
if (tmp && (tmp._deep_query_node_ || tmp._deep_array_)) | ||
tmp = nodes.val(s); | ||
if (deepEqual(tmp, needed)) | ||
return s; | ||
return deep.errors.PreconditionFail("deep.equal failed ! ", { | ||
equal: false, | ||
value: tmp, | ||
needed: needed | ||
}); | ||
}; | ||
/** | ||
* final namespace for deepjs/query | ||
* @static | ||
* @property Querier | ||
* @type {DeepQuery} | ||
*/ | ||
var Querier = deep.Querier = query; | ||
/** | ||
* perform a (synched) query query | ||
* @example | ||
* | ||
* deep.query({ hello:"world", test:1 }, "/*?=world"); // will return ["world"] | ||
* | ||
* @method query | ||
* @param {Object} object any object to query | ||
* @param {String} query the query | ||
* @static | ||
* @return {Array} the result aray | ||
*/ | ||
deep.query = Querier.query; | ||
nodesChainedApi.equal = function(obj) { | ||
return this.done(function(s) { | ||
return nodes.equal(s, needed); | ||
}); | ||
}; | ||
deep.ui = {}; | ||
deep.Promise._up({ | ||
equal: nodesChainedApi.equal, | ||
modes: function(arg, arg2) { | ||
var self = this; | ||
return this.done(function(s, e) { | ||
if (!self._contextualised) | ||
deep.contextualisePromise(self); | ||
self._context.modes = self._context.modes || {}; | ||
modes.setModesIn(self._context.modes, arg, arg2); | ||
return s; | ||
}); | ||
} | ||
}); | ||
for (var i in compiler) | ||
deep[i] = compiler[i]; | ||
for (var i in classes) | ||
deep[i] = classes[i]; | ||
deep.modes = function(arg, arg2) { | ||
return new deep.Promise().resolve(undefined).modes(arg, arg2); | ||
}; | ||
deep.compose = composer.compose; | ||
deep.Composition = composer.Composition; | ||
deep.Composer = composer.Composer; | ||
deep.compose.Classes = deep.Classes; // for backward compatibility | ||
deep.compose.ClassFactory = deep.ClassFactory; // for backward compatibility | ||
deep.Arguments = deep.compose.Arguments; | ||
// ____________________ SHEETS | ||
//deep.extendsChilds = flatten.extendsChilds; | ||
//deep.extendsBackgrounds = flatten.extendsBackgrounds; | ||
//utils.flatten = deep.flatten = flatten.flatten; | ||
ocm.applySheet = deep.sheet; | ||
Classes.applySheet = deep.sheet; | ||
deep.protocol = protocol.protocol; | ||
deep.protocols = protocol.protocols; | ||
deep.get = protocol.get; | ||
deep.getAll = protocol.getAll; | ||
sheeter.methods = { | ||
up: function(catched, toApply, options) { | ||
return protocol.getAll(toApply) | ||
.done(function(objects) { | ||
return nodes.up.apply(nodes, [catched].concat(objects)); | ||
}); | ||
}, | ||
bottom: function(catched, toApply, options) { | ||
return protocol.getAll(toApply) | ||
.done(function(objects) { | ||
return nodes.bottom.apply(nodes, [catched].concat(objects)); | ||
}); | ||
}, | ||
map: function(catched, toApply, options) { | ||
return nodes.map(catched, toApply); | ||
} | ||
}; | ||
deep.ocm = ocm; | ||
deep.Modes = ocm.Modes; | ||
deep.modes = ocm.modes; | ||
deep.currentModes = ocm.currentModes; | ||
deep.Event = emitter.Event; | ||
deep.Emitter = emitter.Emitter; | ||
//______________________ VALIDATOR | ||
deep.Validator = Validator; | ||
deep.validate = Validator.validate; | ||
deep.partialValidation = Validator.partialValidation; | ||
for (var i in sheets) | ||
deep[i] = sheets[i]; | ||
for (var i in promise) | ||
deep[i] = promise[i]; | ||
deep.NodesChain = NodesChain; | ||
deep.delay = function(ms) { | ||
return deep.nodes({}).delay(ms); | ||
}; | ||
for (var i in restrictions) | ||
deep[i] = restrictions[i]; | ||
//_________________________________________________________________________________ | ||
deep.contextualise = context.contextualise; | ||
deep.fromContext = context.fromContext; | ||
deep.context = context.context; | ||
deep.flatten = flattener.flatten; | ||
deep.extendsGrounds = flattener.extendsGrounds; | ||
/** | ||
* the deep schema validator | ||
* @static | ||
* @property Validator | ||
*/ | ||
deep.Validator = Validator; | ||
/** | ||
* perform a schema validation | ||
* @static | ||
* @method validate | ||
* @param object the object to validate | ||
* @param schema the schema | ||
* @return {deep.validate.Report} the validation report | ||
*/ | ||
deep.validate = Validator.validate; | ||
/** | ||
* perform a schema partial validation (only on certain field) | ||
* @static | ||
* @method partialValidation | ||
* @param object the object to validate | ||
* @param fields the array of properties paths to validate | ||
* @param schema the schema | ||
* @return {deep.validate.Report} the validation report | ||
*/ | ||
deep.partialValidation = Validator.partialValidation; | ||
// deep chain's mode management | ||
deep.modes = function(name, modes) { // local roles (i.e. in chain's context) | ||
return deep.nodes({}).modes(name, modes); | ||
}; | ||
deep.coreUnits = deep.coreUnits || []; | ||
deep.coreUnits.push( | ||
"js::deepjs/units/equals", | ||
"js::deepjs/units/queries", | ||
"js::deepjs/units/collisions", | ||
"js::deepjs/units/colliders", | ||
"js::deepjs/units/compositions", | ||
"js::deepjs/units/classes", | ||
"js::deepjs/units/protocols", | ||
"js::deepjs/units/flatten", | ||
"js::deepjs/units/promises", | ||
"js::deepjs/units/chain", | ||
"js::deepjs/units/replace", | ||
"js::deepjs/units/remove", | ||
"js::deepjs/units/interpret", | ||
//"js::deepjs/units/relations", | ||
"js::deepjs/units/context", | ||
"js::deepjs/units/ocm", | ||
"js::deepjs/units/sheets", | ||
"js::deepjs/units/shared", | ||
"js::deepjs/units/parcours", | ||
//"js::deepjs/units/deepload", | ||
"js::deepjs/units/utils", | ||
"js::deepjs/units/custom-chain" | ||
); | ||
//_________________________________________________________________________________ | ||
return deep; | ||
}); | ||
return deep; | ||
}); |
582
ie-hacks.js
@@ -1,327 +0,327 @@ | ||
'use strict'; | ||
// Add ECMA262-5 method binding if not supported natively | ||
(function(){ | ||
var _slice = Array.prototype.slice; | ||
(function() { | ||
'use strict'; | ||
try { | ||
// Can't be used with DOM elements in IE < 9 | ||
_slice.call(document.documentElement); | ||
} catch (e) { // Fails in IE < 9 | ||
Array.prototype.slice = function(begin, end) { | ||
var i, arrl = this.length, | ||
a = []; | ||
// Although IE < 9 does not fail when applying Array.prototype.slice | ||
// to strings, here we do have to duck-type to avoid failing | ||
// with IE < 9's lack of support for string indexes | ||
if (this.charAt) { | ||
for (i = 0; i < arrl; i++) { | ||
a.push(this.charAt(i)); | ||
var _slice = Array.prototype.slice; | ||
try { | ||
// Can't be used with DOM elements in IE < 9 | ||
_slice.call(document.documentElement); | ||
} catch (e) { // Fails in IE < 9 | ||
Array.prototype.slice = function(begin, end) { | ||
var i, arrl = this.length, | ||
a = []; | ||
// Although IE < 9 does not fail when applying Array.prototype.slice | ||
// to strings, here we do have to duck-type to avoid failing | ||
// with IE < 9's lack of support for string indexes | ||
if (this.charAt) { | ||
for (i = 0; i < arrl; i++) { | ||
a.push(this.charAt(i)); | ||
} | ||
} | ||
} | ||
// This will work for genuine arrays, array-like objects, | ||
// NamedNodeMap (attributes, entities, notations), | ||
// NodeList (e.g., getElementsByTagName), HTMLCollection (e.g., childNodes), | ||
// and will not fail on other DOM objects (as do DOM elements in IE < 9) | ||
else { | ||
// IE < 9 (at least IE < 9 mode in IE 10) does not work with | ||
// node.attributes (NamedNodeMap) without a dynamically checked length here | ||
for (i = 0; i < this.length; i++) { | ||
a.push(this[i]); | ||
// This will work for genuine arrays, array-like objects, | ||
// NamedNodeMap (attributes, entities, notations), | ||
// NodeList (e.g., getElementsByTagName), HTMLCollection (e.g., childNodes), | ||
// and will not fail on other DOM objects (as do DOM elements in IE < 9) | ||
else { | ||
// IE < 9 (at least IE < 9 mode in IE 10) does not work with | ||
// node.attributes (NamedNodeMap) without a dynamically checked length here | ||
for (i = 0; i < this.length; i++) { | ||
a.push(this[i]); | ||
} | ||
} | ||
} | ||
// IE < 9 gives errors here if end is allowed as undefined | ||
// (as opposed to just missing) so we default ourselves | ||
return _slice.call(a, begin, end || a.length); | ||
}; | ||
} | ||
// IE < 9 gives errors here if end is allowed as undefined | ||
// (as opposed to just missing) so we default ourselves | ||
return _slice.call(a, begin, end || a.length); | ||
}; | ||
} | ||
if (!('bind' in Function.prototype)) { | ||
Function.prototype.bind = function(owner) { | ||
var that = this; | ||
if (arguments.length <= 1) { | ||
return function() { | ||
return that.apply(owner, arguments); | ||
}; | ||
} else { | ||
var args = Array.prototype.slice.call(arguments, 1); | ||
return function() { | ||
return that.apply(owner, arguments.length === 0 ? args : args.concat(Array.prototype.slice.call(arguments))); | ||
}; | ||
} | ||
}; | ||
} | ||
if (!Date.now) | ||
Date.now = Date.now || function() { | ||
return +new Date; | ||
}; | ||
if (!('bind' in Function.prototype)) { | ||
Function.prototype.bind = function(owner) { | ||
var that = this; | ||
if (arguments.length <= 1) { | ||
return function() { | ||
return that.apply(owner, arguments); | ||
}; | ||
} else { | ||
var args = Array.prototype.slice.call(arguments, 1); | ||
return function() { | ||
return that.apply(owner, arguments.length === 0 ? args : args.concat(Array.prototype.slice.call(arguments))); | ||
}; | ||
} | ||
}; | ||
} | ||
if (!Date.now) | ||
Date.now = Date.now || function() { | ||
return +new Date; | ||
}; | ||
if (!Object.create) { | ||
Object.create = (function() { | ||
function F() {} | ||
if (!Object.create) { | ||
Object.create = (function() { | ||
function F() {} | ||
return function(o) { | ||
if (arguments.length != 1) { | ||
throw new Error('Object.create implementation only accepts one parameter.'); | ||
return function(o) { | ||
if (arguments.length != 1) { | ||
throw new Error('Object.create implementation only accepts one parameter.'); | ||
} | ||
F.prototype = o | ||
return new F() | ||
} | ||
F.prototype = o | ||
return new F() | ||
} | ||
})(); | ||
} | ||
if (!Object.keys) { | ||
Object.keys = (function() { | ||
'use strict'; | ||
var hasOwnProperty = Object.prototype.hasOwnProperty, | ||
hasDontEnumBug = !({ | ||
toString: null | ||
}).propertyIsEnumerable('toString'), | ||
dontEnums = [ | ||
'toString', | ||
'toLocaleString', | ||
'valueOf', | ||
'hasOwnProperty', | ||
'isPrototypeOf', | ||
'propertyIsEnumerable', | ||
'constructor' | ||
], | ||
dontEnumsLength = dontEnums.length; | ||
})(); | ||
} | ||
if (!Object.keys) { | ||
Object.keys = (function() { | ||
'use strict'; | ||
var hasOwnProperty = Object.prototype.hasOwnProperty, | ||
hasDontEnumBug = !({ | ||
toString: null | ||
}).propertyIsEnumerable('toString'), | ||
dontEnums = [ | ||
'toString', | ||
'toLocaleString', | ||
'valueOf', | ||
'hasOwnProperty', | ||
'isPrototypeOf', | ||
'propertyIsEnumerable', | ||
'constructor' | ||
], | ||
dontEnumsLength = dontEnums.length; | ||
return function(obj) { | ||
if (typeof obj !== 'object' && (typeof obj !== 'function' || obj === null)) { | ||
throw new TypeError('Object.keys called on non-object'); | ||
} | ||
return function(obj) { | ||
if (typeof obj !== 'object' && (typeof obj !== 'function' || obj === null)) { | ||
throw new TypeError('Object.keys called on non-object'); | ||
} | ||
var result = [], | ||
prop, i; | ||
var result = [], | ||
prop, i; | ||
for (prop in obj) { | ||
if (hasOwnProperty.call(obj, prop)) { | ||
result.push(prop); | ||
for (prop in obj) { | ||
if (hasOwnProperty.call(obj, prop)) { | ||
result.push(prop); | ||
} | ||
} | ||
} | ||
if (hasDontEnumBug) { | ||
for (i = 0; i < dontEnumsLength; i++) { | ||
if (hasOwnProperty.call(obj, dontEnums[i])) { | ||
result.push(dontEnums[i]); | ||
if (hasDontEnumBug) { | ||
for (i = 0; i < dontEnumsLength; i++) { | ||
if (hasOwnProperty.call(obj, dontEnums[i])) { | ||
result.push(dontEnums[i]); | ||
} | ||
} | ||
} | ||
} | ||
return result; | ||
return result; | ||
}; | ||
}()); | ||
} | ||
if (!Array.isArray) { | ||
Array.isArray = function(vArg) { | ||
return vArg instanceof Array; | ||
}; | ||
}()); | ||
} | ||
if (!Array.isArray) { | ||
Array.isArray = function(vArg) { | ||
return vArg instanceof Array; | ||
}; | ||
} | ||
var split; | ||
} | ||
var split; | ||
// Avoid running twice; that would break the `nativeSplit` reference | ||
split = split || function(undef) { | ||
// Avoid running twice; that would break the `nativeSplit` reference | ||
split = split || function(undef) { | ||
var nativeSplit = String.prototype.split, | ||
compliantExecNpcg = /()??/.exec("")[1] === undef, // NPCG: nonparticipating capturing group | ||
self; | ||
var nativeSplit = String.prototype.split, | ||
compliantExecNpcg = /()??/.exec("")[1] === undef, // NPCG: nonparticipating capturing group | ||
self; | ||
self = function(str, separator, limit) { | ||
// If `separator` is not a regex, use `nativeSplit` | ||
if (Object.prototype.toString.call(separator) !== "[object RegExp]") { | ||
return nativeSplit.call(str, separator, limit); | ||
} | ||
var output = [], | ||
flags = (separator.ignoreCase ? "i" : "") + | ||
self = function(str, separator, limit) { | ||
// If `separator` is not a regex, use `nativeSplit` | ||
if (Object.prototype.toString.call(separator) !== "[object RegExp]") { | ||
return nativeSplit.call(str, separator, limit); | ||
} | ||
var output = [], | ||
flags = (separator.ignoreCase ? "i" : "") + | ||
(separator.multiline ? "m" : "") + | ||
(separator.extended ? "x" : "") + // Proposed for ES6 | ||
(separator.sticky ? "y" : ""), // Firefox 3+ | ||
lastLastIndex = 0, | ||
// Make `global` and avoid `lastIndex` issues by working with a copy | ||
separator = new RegExp(separator.source, flags + "g"), | ||
separator2, match, lastIndex, lastLength; | ||
str += ""; // Type-convert | ||
if (!compliantExecNpcg) { | ||
// Doesn't need flags gy, but they don't hurt | ||
separator2 = new RegExp("^" + separator.source + "$(?!\\s)", flags); | ||
} | ||
/* Values for `limit`, per the spec: | ||
* If undefined: 4294967295 // Math.pow(2, 32) - 1 | ||
* If 0, Infinity, or NaN: 0 | ||
* If positive number: limit = Math.floor(limit); if (limit > 4294967295) limit -= 4294967296; | ||
* If negative number: 4294967296 - Math.floor(Math.abs(limit)) | ||
* If other: Type-convert, then use the above rules | ||
*/ | ||
limit = limit === undef ? -1 >>> 0 : // Math.pow(2, 32) - 1 | ||
limit >>> 0; // ToUint32(limit) | ||
while (match = separator.exec(str)) { | ||
// `separator.lastIndex` is not reliable cross-browser | ||
lastIndex = match.index + match[0].length; | ||
if (lastIndex > lastLastIndex) { | ||
output.push(str.slice(lastLastIndex, match.index)); | ||
// Fix browsers whose `exec` methods don't consistently return `undefined` for | ||
// nonparticipating capturing groups | ||
if (!compliantExecNpcg && match.length > 1) { | ||
match[0].replace(separator2, function() { | ||
for (var i = 1; i < arguments.length - 2; i++) { | ||
if (arguments[i] === undef) { | ||
match[i] = undef; | ||
(separator.sticky ? "y" : ""), // Firefox 3+ | ||
lastLastIndex = 0, | ||
// Make `global` and avoid `lastIndex` issues by working with a copy | ||
separator = new RegExp(separator.source, flags + "g"), | ||
separator2, match, lastIndex, lastLength; | ||
str += ""; // Type-convert | ||
if (!compliantExecNpcg) { | ||
// Doesn't need flags gy, but they don't hurt | ||
separator2 = new RegExp("^" + separator.source + "$(?!\\s)", flags); | ||
} | ||
/* Values for `limit`, per the spec: | ||
* If undefined: 4294967295 // Math.pow(2, 32) - 1 | ||
* If 0, Infinity, or NaN: 0 | ||
* If positive number: limit = Math.floor(limit); if (limit > 4294967295) limit -= 4294967296; | ||
* If negative number: 4294967296 - Math.floor(Math.abs(limit)) | ||
* If other: Type-convert, then use the above rules | ||
*/ | ||
limit = limit === undef ? -1 >>> 0 : // Math.pow(2, 32) - 1 | ||
limit >>> 0; // ToUint32(limit) | ||
while (match = separator.exec(str)) { | ||
// `separator.lastIndex` is not reliable cross-browser | ||
lastIndex = match.index + match[0].length; | ||
if (lastIndex > lastLastIndex) { | ||
output.push(str.slice(lastLastIndex, match.index)); | ||
// Fix browsers whose `exec` methods don't consistently return `undefined` for | ||
// nonparticipating capturing groups | ||
if (!compliantExecNpcg && match.length > 1) { | ||
match[0].replace(separator2, function() { | ||
for (var i = 1; i < arguments.length - 2; i++) { | ||
if (arguments[i] === undef) { | ||
match[i] = undef; | ||
} | ||
} | ||
} | ||
}); | ||
}); | ||
} | ||
if (match.length > 1 && match.index < str.length) { | ||
Array.prototype.push.apply(output, match.slice(1)); | ||
} | ||
lastLength = match[0].length; | ||
lastLastIndex = lastIndex; | ||
if (output.length >= limit) { | ||
break; | ||
} | ||
} | ||
if (match.length > 1 && match.index < str.length) { | ||
Array.prototype.push.apply(output, match.slice(1)); | ||
if (separator.lastIndex === match.index) { | ||
separator.lastIndex++; // Avoid an infinite loop | ||
} | ||
lastLength = match[0].length; | ||
lastLastIndex = lastIndex; | ||
if (output.length >= limit) { | ||
break; | ||
} | ||
if (lastLastIndex === str.length) { | ||
if (lastLength || !separator.test("")) { | ||
output.push(""); | ||
} | ||
} else { | ||
output.push(str.slice(lastLastIndex)); | ||
} | ||
if (separator.lastIndex === match.index) { | ||
separator.lastIndex++; // Avoid an infinite loop | ||
} | ||
} | ||
if (lastLastIndex === str.length) { | ||
if (lastLength || !separator.test("")) { | ||
output.push(""); | ||
} | ||
} else { | ||
output.push(str.slice(lastLastIndex)); | ||
} | ||
return output.length > limit ? output.slice(0, limit) : output; | ||
}; | ||
// For convenience | ||
String.prototype.split = function(separator, limit) { | ||
return self(this, separator, limit); | ||
}; | ||
return output.length > limit ? output.slice(0, limit) : output; | ||
}; | ||
// For convenience | ||
String.prototype.split = function(separator, limit) { | ||
return self(this, separator, limit); | ||
}; | ||
return self; | ||
}(); | ||
if (!Object.getOwnPropertyNames) { | ||
Object.getOwnPropertyNames = function(obj) { | ||
var keys = []; | ||
for (var i in obj) { | ||
if (obj.hasOwnProperty(i)) { | ||
keys.push(i); | ||
return self; | ||
}(); | ||
if (!Object.getOwnPropertyNames) { | ||
Object.getOwnPropertyNames = function(obj) { | ||
var keys = []; | ||
for (var i in obj) { | ||
if (obj.hasOwnProperty(i)) { | ||
keys.push(i); | ||
} | ||
} | ||
} | ||
return keys; | ||
}; | ||
} | ||
// Add ECMA262-5 string trim if not supported natively | ||
// | ||
if (!('trim' in String.prototype)) { | ||
String.prototype.trim = function() { | ||
return this.replace(/^\s+/, '').replace(/\s+$/, ''); | ||
}; | ||
} | ||
return keys; | ||
}; | ||
} | ||
// Add ECMA262-5 string trim if not supported natively | ||
// | ||
if (!('trim' in String.prototype)) { | ||
String.prototype.trim = function() { | ||
return this.replace(/^\s+/, '').replace(/\s+$/, ''); | ||
}; | ||
} | ||
// Add ECMA262-5 Array methods if not supported natively | ||
// | ||
if (!('indexOf' in Array.prototype)) { | ||
Array.prototype.indexOf = function(find, i /*opt*/ ) { | ||
if (i === undefined) i = 0; | ||
if (i < 0) i += this.length; | ||
if (i < 0) i = 0; | ||
for (var n = this.length; i < n; i++) | ||
if (this[i] === find) | ||
return i; | ||
return -1; | ||
}; | ||
} | ||
if (!('lastIndexOf' in Array.prototype)) { | ||
Array.prototype.lastIndexOf = function(find, i /*opt*/ ) { | ||
if (i === undefined) i = this.length - 1; | ||
if (i < 0) i += this.length; | ||
if (i > this.length - 1) i = this.length - 1; | ||
for (i++; i-- > 0;) /* i++ because from-argument is sadly inclusive */ | ||
if (this[i] === find) | ||
return i; | ||
return -1; | ||
}; | ||
} | ||
if (!('forEach' in Array.prototype)) { | ||
Array.prototype.forEach = function(action, that /*opt*/ ) { | ||
for (var i = 0, n = this.length; i < n; i++) | ||
//if (i in this) | ||
action.call(that, this[i], i, this); | ||
}; | ||
} | ||
if (!('map' in Array.prototype)) { | ||
Array.prototype.map = function(mapper, that /*opt*/ ) { | ||
var other = new Array(this.length); | ||
for (var i = 0, n = this.length; i < n; i++) | ||
//if (i in this) | ||
other[i] = mapper.call(that, this[i], i, this); | ||
return other; | ||
}; | ||
} | ||
if (!('filter' in Array.prototype)) { | ||
Array.prototype.filter = function(filter, that /*opt*/ ) { | ||
var other = [], | ||
v; | ||
for (var i = 0, n = this.length; i < n; i++) | ||
if (filter.call(that, v = this[i], i, this)) | ||
other.push(v); | ||
return other; | ||
}; | ||
} | ||
if (!('every' in Array.prototype)) { | ||
Array.prototype.every = function(tester, that /*opt*/ ) { | ||
for (var i = 0, n = this.length; i < n; i++) | ||
if (!tester.call(that, this[i], i, this)) | ||
return false; | ||
return true; | ||
}; | ||
} | ||
if (!('some' in Array.prototype)) { | ||
Array.prototype.some = function(tester, that /*opt*/ ) { | ||
for (var i = 0, n = this.length; i < n; i++) | ||
if (tester.call(that, this[i], i, this)) | ||
return true; | ||
return false; | ||
}; | ||
} | ||
if (!Array.prototype.reduce) { | ||
Array.prototype.reduce = function(fun /*, initial*/ ) { | ||
var len = this.length; | ||
if (typeof fun !== 'function') | ||
throw new TypeError(); | ||
// Add ECMA262-5 Array methods if not supported natively | ||
// | ||
if (!('indexOf' in Array.prototype)) { | ||
Array.prototype.indexOf = function(find, i /*opt*/ ) { | ||
if (i === undefined) i = 0; | ||
if (i < 0) i += this.length; | ||
if (i < 0) i = 0; | ||
for (var n = this.length; i < n; i++) | ||
if (this[i] === find) | ||
return i; | ||
return -1; | ||
}; | ||
} | ||
if (!('lastIndexOf' in Array.prototype)) { | ||
Array.prototype.lastIndexOf = function(find, i /*opt*/ ) { | ||
if (i === undefined) i = this.length - 1; | ||
if (i < 0) i += this.length; | ||
if (i > this.length - 1) i = this.length - 1; | ||
for (i++; i-- > 0;) /* i++ because from-argument is sadly inclusive */ | ||
if (this[i] === find) | ||
return i; | ||
return -1; | ||
}; | ||
} | ||
if (!('forEach' in Array.prototype)) { | ||
Array.prototype.forEach = function(action, that /*opt*/ ) { | ||
for (var i = 0, n = this.length; i < n; i++) | ||
//if (i in this) | ||
action.call(that, this[i], i, this); | ||
}; | ||
} | ||
if (!('map' in Array.prototype)) { | ||
Array.prototype.map = function(mapper, that /*opt*/ ) { | ||
var other = new Array(this.length); | ||
for (var i = 0, n = this.length; i < n; i++) | ||
//if (i in this) | ||
other[i] = mapper.call(that, this[i], i, this); | ||
return other; | ||
}; | ||
} | ||
if (!('filter' in Array.prototype)) { | ||
Array.prototype.filter = function(filter, that /*opt*/ ) { | ||
var other = [], | ||
v; | ||
for (var i = 0, n = this.length; i < n; i++) | ||
if (filter.call(that, v = this[i], i, this)) | ||
other.push(v); | ||
return other; | ||
}; | ||
} | ||
if (!('every' in Array.prototype)) { | ||
Array.prototype.every = function(tester, that /*opt*/ ) { | ||
for (var i = 0, n = this.length; i < n; i++) | ||
if (!tester.call(that, this[i], i, this)) | ||
return false; | ||
return true; | ||
}; | ||
} | ||
if (!('some' in Array.prototype)) { | ||
Array.prototype.some = function(tester, that /*opt*/ ) { | ||
for (var i = 0, n = this.length; i < n; i++) | ||
if (tester.call(that, this[i], i, this)) | ||
return true; | ||
return false; | ||
}; | ||
} | ||
if (!Array.prototype.reduce) { | ||
Array.prototype.reduce = function(fun /*, initial*/ ) { | ||
var len = this.length; | ||
if (typeof fun !== 'function') | ||
throw new TypeError(); | ||
// no value to return if no initial value and an empty array | ||
if (len === 0 && arguments.length == 1) | ||
throw new TypeError(); | ||
// no value to return if no initial value and an empty array | ||
if (len === 0 && arguments.length == 1) | ||
throw new TypeError(); | ||
var i = 0, | ||
rv; | ||
if (arguments.length >= 2) { | ||
rv = arguments[1]; | ||
} else { | ||
//do | ||
//{ | ||
//if (i in this) | ||
//{ | ||
rv = this[i]; | ||
// break; | ||
//} | ||
var i = 0, | ||
rv; | ||
if (arguments.length >= 2) { | ||
rv = arguments[1]; | ||
} else { | ||
//do | ||
//{ | ||
//if (i in this) | ||
//{ | ||
rv = this[i]; | ||
// break; | ||
//} | ||
// if array contains no values, no initial value to return | ||
//if (++i >= len) | ||
//throw new TypeError(); | ||
//} | ||
//while (true); | ||
} | ||
// if array contains no values, no initial value to return | ||
//if (++i >= len) | ||
//throw new TypeError(); | ||
//} | ||
//while (true); | ||
} | ||
for (; i < len; i++) { | ||
//if (i in this) | ||
rv = fun.call(null, rv, this[i], i, this); | ||
} | ||
for (; i < len; i++) { | ||
//if (i in this) | ||
rv = fun.call(null, rv, this[i], i, this); | ||
} | ||
return rv; | ||
}; | ||
} | ||
return rv; | ||
}; | ||
} | ||
})(); | ||
})(); |
@@ -10,7 +10,7 @@ /** | ||
} | ||
define(["require", "../deep"], function (require, deep) { | ||
define([], function() { | ||
var cache = {}; | ||
return deep.cache = { | ||
clear:function (namespace) { | ||
if(namespace) | ||
return { | ||
clear: function(namespace) { | ||
if (namespace) | ||
delete cache[namespace]; | ||
@@ -20,21 +20,23 @@ else | ||
}, | ||
remove:function (namespace, uri) { | ||
if(cache[namespace]) | ||
remove: function(namespace, uri) { | ||
if (cache[namespace]) | ||
delete cache[namespace][uri]; | ||
}, | ||
add:function (response, namespace, uri, life) { | ||
add: function(response, namespace, uri, life) { | ||
// console.log("cache.add = ", response, namespace, uri, life); | ||
var space = cache[namespace] = cache[namespace] || {}; | ||
space[uri] = { response:response, stamp:(life?(Date.now().valueOf()+life):null) }; | ||
space[uri] = { | ||
response: response, | ||
stamp: (life ? (Date.now().valueOf() + life) : null) | ||
}; | ||
return response; | ||
}, | ||
get:function(namespace, uri) { | ||
get: function(namespace, uri) { | ||
var space = cache[namespace]; | ||
if(!space) | ||
if (!space) | ||
return; | ||
var val = space[uri]; | ||
if(!val) | ||
if (!val) | ||
return val; | ||
if(val.stamp && Date.now().valueOf() > val.stamp) | ||
{ | ||
if (val.stamp && Date.now().valueOf() > val.stamp) { | ||
delete space[uri]; | ||
@@ -46,4 +48,2 @@ return; | ||
}; | ||
}); | ||
}); |
/** | ||
* layer-data-composition : inspired by Compose, it offer a set of tools that permit to merge values when layer's are collided. | ||
* @author Gilles Coomans <gilles.coomans@gmail.com> | ||
* | ||
* As Compose merge two functions by wrapping them by appropriate Compose method (after, before, around), | ||
* layer-compose do the same by fireing a paticular merger when values are collided. | ||
* | ||
* If you know photoshop : it's an equivalent of the fusion modes between two layers (or pixel). | ||
* | ||
* | ||
* @module deep | ||
* @submodule deep-collider | ||
* @author Gilles Coomans <gilles.coomans@gmail.com> | ||
*/ | ||
if (typeof define !== 'function') { | ||
var define = require('amdefine')(module); | ||
} | ||
/* | ||
* TODO : implement almost every operations, few are done. Will be made on-need. | ||
* | ||
* | ||
* - add asynch collision (up, bottom) mode | ||
* | ||
* - ifCollision : don't keep collider if no collision | ||
* - dontKeep : do not keep collider (it will only be used to fire something as a test) | ||
*/ | ||
define(["require", "./utils", "./utils/query", "./compiler", "./errors"], function(require, utils, queryUtils, compiler, errors) { | ||
define(["require", "../deep", "deep-compiler/lib/collider"], function(require, deep, collider) { | ||
deep.collider = collider; | ||
/** | ||
* the collider interface | ||
* @namespace deep | ||
* @chainable true | ||
* @class collider | ||
* @static | ||
*/ | ||
var collider = {}; | ||
var Collider = collider.Collider = function(fn) { | ||
this._collision = fn; | ||
this._deep_collider_ = true; | ||
this._deep_compiler_ = true; | ||
}; | ||
Collider.prototype = { | ||
_wrapIn: function(fn) { | ||
var coll = this._collision; | ||
return function(input) { | ||
return fn(coll(input)); | ||
}; | ||
}, | ||
/*_wrapIn: function(fn) { | ||
var coll = this._collision; | ||
return function(input) { | ||
if(input && input.then) | ||
return deep.when(input).done(coll).done(fn); | ||
var r = coll(input); | ||
if(r && r.then) | ||
return deep.when(r).done(fn); | ||
return fn(r); | ||
}; | ||
},*/ | ||
_clone: function() { | ||
//console.log("this on colliders clone ? ", this); | ||
return utils.copy(this, true); | ||
}, | ||
_up: function(obj) { | ||
if (!obj._deep_collider_) | ||
return obj; | ||
this._collision = this._wrapIn(obj._collision); | ||
return this; | ||
}, | ||
_bottom: function(obj) { | ||
if (!obj._deep_collider_) | ||
return this._collision(obj); | ||
this._collision = obj._wrapIn(this._collision); | ||
return this; | ||
} | ||
}; | ||
/** | ||
* Add new collider method | ||
* @param {String} name the method name | ||
* @param {Function} fn the method | ||
*/ | ||
Collider.add = function(name, fn) { | ||
var handler = function() { | ||
var args = Array.prototype.slice.apply(arguments); | ||
var h = function(input) { | ||
args.unshift(input); | ||
return fn.apply({}, args); | ||
}; | ||
if (!this._deep_collider_) | ||
return new Collider(h); | ||
this._collision = this._wrapIn(h); | ||
return this; | ||
}; | ||
collider[name] = Collider.prototype[name] = handler; | ||
return Collider; | ||
}; | ||
/** | ||
* bottom | ||
* | ||
* @example | ||
* var a = { | ||
* test:deep.collider.bottom({}) | ||
* }; | ||
* | ||
*/ | ||
Collider.add("bottom", function() { | ||
var len = arguments.length - 1, base = arguments[0]; | ||
for (; len > 0; --len) | ||
base = compiler.abottom(arguments[len], base); | ||
return base; | ||
}); | ||
/** | ||
* up | ||
* | ||
* @example | ||
* var a = { | ||
* test:deep.collider.up({}) | ||
* }; | ||
* | ||
*/ | ||
Collider.add("up", function() { | ||
var len = arguments.length, base = arguments[0]; | ||
for (var count = 1; count < len; ++count) | ||
base = compiler.aup(arguments[count], base); | ||
return base; | ||
}); | ||
/** | ||
* replace | ||
@@ -140,6 +21,5 @@ * | ||
*/ | ||
Collider.add("replace", function(input, by, query) { | ||
if(query) | ||
{ | ||
utils.replace(input, query, by); | ||
collider.Collider.add("replace", function(input, by, query) { | ||
if (query) { | ||
deep.Querier.replace(input, query, by); | ||
return input; | ||
@@ -149,63 +29,19 @@ } | ||
}); | ||
/** | ||
* remove | ||
* | ||
* @example | ||
* var a = { | ||
* test:deep.collider.remove("./myKey") | ||
* }; | ||
* | ||
*/ | ||
Collider.add("remove", function(input, query) { | ||
collider.Collider.add("remove", function(input, query) { | ||
// console.log("Collider.remove : ", input, query); | ||
if(!query) | ||
return { _deep_remover_:true }; | ||
utils.remove(input, query); | ||
if (!query) | ||
return { | ||
_deep_remover_: true | ||
}; | ||
deep.Querier.remove(input, query); | ||
return input; | ||
}); | ||
/** | ||
* log | ||
* | ||
* @example | ||
* var a = { | ||
* test:deep.collider.log("my title") | ||
* }; | ||
* | ||
*/ | ||
Collider.add("log", function(input, title) { | ||
collider.Collider.add("log", function(input, title) { | ||
deep.log("collider.log : ", title, ":", input); | ||
return input; | ||
}); | ||
/** | ||
* upperCase | ||
* | ||
* @example | ||
* var a = { | ||
* test:deep.collider.up({}) | ||
* }; | ||
* | ||
*/ | ||
Collider.add("changeCase", function(input, strcase) { | ||
switch(strcase) | ||
{ | ||
case "lower" : return input.toLowerCase(); | ||
case "upper" : return input.toUpperCase(); | ||
case "title" : return utils.titleCase(input); | ||
case "camel" : return utils.camelCase(input); | ||
default : return input; | ||
} | ||
}); | ||
/** | ||
* validate | ||
* | ||
* @example | ||
* var a = { | ||
* test:deep.collider.validate( mySchema ) | ||
* }; | ||
* | ||
*/ | ||
Collider.add("validate", function(input, schema) { | ||
collider.Collider.add("validate", function(input, schema) { | ||
var report = deep.validate(input, schema); | ||
@@ -217,115 +53,14 @@ if (!report.valid) | ||
/** | ||
* equal | ||
* | ||
* @example | ||
* var a = { | ||
* test:deep.collider.equal( neededValue ) | ||
* }; | ||
* | ||
*/ | ||
Collider.add("equal", function(input, needed) { | ||
var ok = utils.deepEqual(input, needed); | ||
collider.Collider.add("equal", function(input, needed) { | ||
var ok = deep.utils.deepEqual(input, needed); | ||
if (!ok) | ||
throw errors.PreconditionFail({ valid:false, value:input, needed:needed }); | ||
throw errors.PreconditionFail({ | ||
valid: false, | ||
value: input, | ||
needed: needed | ||
}); | ||
return input; | ||
}); | ||
/** | ||
* array.insertAt | ||
* | ||
* @example | ||
* var a = { | ||
* test:deep.collider.insertAt( what, index ) | ||
* }; | ||
* | ||
*/ | ||
Collider.add("insertAt", function(input, what, index) { | ||
if (!Array.isArray(input)) | ||
throw errors.Internal("colliders.insertAt couldn't be applied : target is not an array."); | ||
var args = [index, 0].concat(what); | ||
input.splice.apply(input, args); | ||
return input; | ||
}); | ||
/** | ||
* array.removeAt | ||
* | ||
* @example | ||
* var a = { | ||
* test:deep.collider.removeAt( index ) | ||
* }; | ||
* | ||
*/ | ||
Collider.add("removeAt", function(input, index, howMuch) { | ||
if (!Array.isArray(input)) | ||
throw errors.Internal("collider.removeAt couldn't be applied : target is not an array."); | ||
if(!howMuch && howMuch !== 0) | ||
howMuch = 1; | ||
input.splice(index, howMuch); | ||
return input; | ||
}); | ||
/** | ||
* array.push | ||
* | ||
* @example | ||
* var a = { | ||
* test:deep.collider.push( value ) | ||
* }; | ||
* | ||
*/ | ||
Collider.add("push", function(input, value) { | ||
if (!Array.isArray(input)) | ||
throw errors.Internal("collider.push couldn't be applied : target is not an array."); | ||
input.push(value); | ||
return input; | ||
}); | ||
/** | ||
* array.unshift | ||
* | ||
* @example | ||
* var a = { | ||
* test:deep.collider.unshift( value ) | ||
* }; | ||
* | ||
*/ | ||
Collider.add("unshift", function(input, value) { | ||
if (!Array.isArray(input)) | ||
throw errors.Internal("collider.push couldn't be applied : target is not an array."); | ||
input.unshift(value); | ||
return input; | ||
}); | ||
/** | ||
* map | ||
* | ||
* @example | ||
* var a = { | ||
* test:deep.collider.map( function(value){ return value.toUpperCase() } ) | ||
* }; | ||
* | ||
*/ | ||
Collider.add("map", function(input, callback) { | ||
if (!Array.isArray(input)) | ||
return callback(input); | ||
return input.map(callback); | ||
}); | ||
/** | ||
* transform | ||
* | ||
* @example | ||
* var a = { | ||
* test:deep.collider.transform( function(input){ return input+2; } ) | ||
* }; | ||
* | ||
*/ | ||
Collider.add("transform", function(input, fn) { | ||
return fn(input); | ||
}); | ||
return collider; | ||
}); |
@@ -20,7 +20,7 @@ /** | ||
this.emit = function(type, datas, context) { | ||
var list = listeners[type], previousContext; | ||
var list = listeners[type], | ||
previousContext; | ||
if (!list) | ||
return; | ||
if(context) | ||
{ | ||
if (context) { | ||
previousContext = promise.Promise.context; | ||
@@ -32,7 +32,6 @@ if (previousContext && previousContext.suspend) | ||
context.resume(); | ||
} | ||
} | ||
for (var i = 0, len = list.length; i < len; ++i) | ||
list[i](new event.Event(type, datas)); | ||
if(context) | ||
{ | ||
if (context) { | ||
if (context.suspend) | ||
@@ -39,0 +38,0 @@ context.suspend(); |
/** | ||
* @author Gilles Coomans <gilles.coomans@gmail.com> | ||
* Promise classe and related tools. | ||
* Inspired from [promised-io](https://github.com/kriszyp/promised-io) from Kris Zyp implementation. | ||
* based on [deep-promise](https://github.com/deepjs/deep-promise). | ||
* Wrap Promise classe in deep.Classes to make it extensible. | ||
*/ | ||
@@ -10,865 +10,8 @@ | ||
} | ||
define(["require", "./utils", "./errors", "./class-constructor"], function(require, utils, errors, classes) { | ||
var promise = {}; | ||
promise.Undefined = { | ||
_deep_undefined_: true | ||
}; | ||
/** | ||
* return a promise that will be fullfilled when arg are ready (resolve or immediat) | ||
* @for deep | ||
* @static | ||
* @method when | ||
* @param {Object} arg an object to waiting for | ||
* @return {deep.Promise} a promise | ||
*/ | ||
promise.when = function(arg) { | ||
//console.log("deep.when : ", arg) | ||
if (!arg || (!arg.promise && !arg.then)) | ||
return new promise.Promise().resolve(arg); | ||
//if (arg._deep_promise_) | ||
// return arg; | ||
if (arg._deep_deferred_) | ||
return arg.promise(); | ||
if (typeof arg.then === 'function') //any promise compliant object | ||
{ | ||
//console.log("doing simple promise (no promise and then is present) on : ", arg); | ||
var p = new promise.Promise(); | ||
arg.then(function(s) { | ||
p.resolve(s); | ||
}, function(e) { | ||
p.reject(e); | ||
}); | ||
return p; | ||
} | ||
if (typeof arg.promise === "function") // jquery deferred case | ||
return arg.promise(); | ||
if (typeof arg.promise === 'object') | ||
return arg.promise; | ||
return new promise.Promise().resolve(arg); | ||
}; | ||
promise.immediate = function(result) { | ||
return new promise.Promise().resolve(result); | ||
}; | ||
/** | ||
* return a promise that will be fullfilled when all args are ready (resolve or immediat) | ||
* @for deep | ||
* @static | ||
* @method all | ||
* @param {Object} arg an array of objects to waiting for | ||
* @return {deep.Promise} a promise | ||
*/ | ||
promise.all = function(arr) { | ||
if (arguments.length > 1) | ||
arr = Array.prototype.slice.call(arguments); | ||
if (arr.length === 0) | ||
return promise.immediate([]); | ||
var def = promise.Deferred(); | ||
var count = arr.length; | ||
var c = 0, | ||
d = -1; | ||
var res = [], | ||
async; | ||
arr.every(function(a) { | ||
if (def.rejected) | ||
return false; | ||
var i = d + 1; | ||
if (!a || !a.then) { | ||
if (a instanceof Error) { | ||
if (!def.rejected && !def.resolved && !def.canceled) | ||
def.reject(a); | ||
return false; | ||
} | ||
res[i] = a; | ||
c++; | ||
if (c == count) | ||
def.resolve(res); | ||
} else { | ||
async = true; | ||
a.then(function(r) { | ||
res[i] = r; | ||
c++; | ||
if (c == count) | ||
def.resolve(res); | ||
}, function(error) { | ||
if (!def.rejected && !def.resolved && !def.canceled) | ||
def.reject(error); | ||
}); | ||
} | ||
d++; | ||
return true | ||
}); | ||
if (!async) | ||
return promise.immediate(res); | ||
return def.promise(); | ||
}; | ||
//_____________________________________________________________________ PROMISED CHAIN MECANIC | ||
var addInChain = function(handle) { | ||
this._state.queue.push(handle); | ||
if (this._initialised && !this._running && !this._executing) | ||
this._next(); | ||
return this; | ||
}; | ||
var asynchChainDone = function(res) { | ||
if (typeof res !== 'undefined') { | ||
if (res instanceof Error) { | ||
this._state.success = null; | ||
this._state.error = res; | ||
} else { | ||
if (res && res._deep_undefined_) | ||
res = undefined; | ||
this._state.success = res; | ||
this._state.error = null; | ||
} | ||
} | ||
this._running = false; // asynch flag | ||
if (!this._executing) // real asynch event | ||
this._next(); | ||
}; | ||
var asynchChainFail = function(e) { | ||
this._running = false; // asynch flag | ||
this._state.success = null; | ||
this._state.error = e; | ||
if (!this._executing) // real asynch event | ||
this._next(); | ||
}; | ||
var nextTry = function(self) { | ||
self._executing = true; // synch flag | ||
while (!self._running) // while not asynch | ||
{ | ||
var next = self._state.queue.shift(); | ||
if (self._state.error) | ||
while (next && next._isDone_) | ||
next = self._state.queue.shift(); | ||
else | ||
while (next && next._isFail_) | ||
next = self._state.queue.shift(); | ||
if (!next) | ||
break; | ||
//________________________________encouter a promise in queue : was a chain stack call. launch chain. | ||
if (next._deep_promise_) { | ||
self._paused = true; | ||
next._context = self._context; | ||
next.resolve(); | ||
break; | ||
} | ||
self._running = true; // asynch flag | ||
self._state.oldQueue = self._state.queue; | ||
self._state.queue = []; | ||
var res = next(self._state.success, self._state.error); | ||
if (res === self) { | ||
if (self._state.oldQueue) { | ||
if (self._state.queue.length) | ||
self._state.queue = self._state.queue.concat(self._state.oldQueue); | ||
else | ||
self._state.queue = self._state.oldQueue; | ||
self._state.oldQueue = null; | ||
} | ||
self._running = false; // asynch flag | ||
continue; | ||
} | ||
if (res && (res.then || res.promise)) { | ||
var p = (res._deep_promise_ || res._deep_chain_) ? res : promise.when(res); | ||
p.done(function(s) { | ||
return asynchChainDone.call(self, s); | ||
}) | ||
.fail(function(e) { | ||
return asynchChainFail.call(self, e); | ||
}); | ||
} else { | ||
self._running = false; | ||
if (typeof res !== 'undefined') { | ||
var isError; | ||
if (res !== null) { | ||
if (res._deep_undefined_) { | ||
res = undefined; | ||
isError = false; | ||
} else | ||
isError = res instanceof Error; | ||
} | ||
self._state.success = (isError) ? null : res; | ||
self._state.error = (isError) ? res : null; | ||
} | ||
} | ||
if (self._state.oldQueue) { | ||
if (self._state.queue.length) | ||
self._state.queue = self._state.queue.concat(self._state.oldQueue); | ||
else | ||
self._state.queue = self._state.oldQueue; | ||
self._state.oldQueue = null; | ||
} | ||
} | ||
}; | ||
var next = function () { | ||
if (!this._initialised || this._paused) | ||
return; | ||
var self = this; | ||
if (self._state.queue.length !== 0) { | ||
try { | ||
var previousContext = promise.Promise.context; | ||
if (previousContext !== self._context) { | ||
if (previousContext && previousContext.suspend) | ||
previousContext.suspend(); | ||
promise.Promise.context = self._context; | ||
if (self._context && self._context.resume) | ||
self._context.resume(); | ||
} | ||
nextTry(self); | ||
} catch (e) { | ||
if (self._context.debug) | ||
utils.dumpError(e); | ||
if (self._context.rethrow) | ||
throw e; | ||
self._state.success = null; | ||
self._state.error = e; | ||
self._running = false; // async flag | ||
} finally { | ||
if (previousContext !== self._context) { | ||
if (self._context && self._context.suspend) | ||
self._context.suspend(); | ||
if (previousContext && previousContext.resume) | ||
previousContext.resume(); | ||
promise.Promise.context = previousContext; | ||
} | ||
} | ||
self._executing = false; | ||
} | ||
}; | ||
//_____________________________________________________________________ DEFERRED | ||
/** | ||
* A deep implementation of Deferred object (see promise on web) | ||
* @class deep.Deferred | ||
* @constructor | ||
*/ | ||
promise.Deferred = function () { | ||
if (!(this instanceof promise.Deferred)) | ||
return new promise.Deferred(); | ||
this._promises = []; | ||
this._deep_deferred_ = true; | ||
return this; | ||
}; | ||
promise.Deferred.prototype = { | ||
_deep_deferred_: true, | ||
_promises: null, | ||
rejected: false, | ||
resolved: false, | ||
canceled: false, | ||
_success: null, | ||
_error: null, | ||
ended: function() { | ||
return this.rejected || this.resolved || this.canceled; | ||
}, | ||
/** | ||
* resolve the Deferred and so the associated promise | ||
* @method resolve | ||
* @param {Object} argument the resolved object injected in promise | ||
* @return {deep.Deferred} this | ||
*/ | ||
resolve: function(argument) { | ||
//console.log("deep.Deferred.resolve : ", argument); | ||
if (this.rejected || this.resolved || this.canceled) | ||
throw new Error("DeepDeferred (resolve) has already been ended ! could not recolve anymore."); | ||
if (argument instanceof Error) | ||
return this.reject(argument); | ||
this._success = argument; | ||
this.resolved = true; | ||
var self = this; | ||
this._promises.forEach(function(promise) { | ||
promise.resolve(argument); | ||
}); | ||
}, | ||
/** | ||
* reject the Deferred and so the associated promise | ||
* @method reject | ||
* @param {Object} argument the rejected object injected in promise | ||
* @return {deep.Deferred} this | ||
*/ | ||
reject: function(argument) { | ||
// console.log("DeepDeferred.reject"); | ||
if (this.rejected || this.resolved || this.canceled) | ||
throw new Error("DeepDeferred has already been ended ! could not reject anymore."); | ||
this._error = argument; | ||
this.rejected = true; | ||
var self = this; | ||
this._promises.forEach(function(promise) { | ||
promise.reject(argument); | ||
}); | ||
}, | ||
/** | ||
* return a promise for this deferred | ||
* @method promise | ||
* @return {deep.Promise} | ||
*/ | ||
promise: function() { | ||
var prom = new Promise(); | ||
//console.log("deep2.Deffered.promise : ", prom, " r,r,c : ", this.rejected, this.resolved, this.canceled) | ||
if (this.resolved) | ||
return prom.resolve(this._success); | ||
if (this.rejected) | ||
return prom.reject(this._error); | ||
this._promises.push(prom); | ||
return prom; | ||
} | ||
}; | ||
var Promise = promise.Promise = classes.Classes(function(state, options) { | ||
this._state = state = state || {}; | ||
this._context = state.context || promise.Promise.context; | ||
this._state.success = state.success || undefined; | ||
this._state.error = state.error || null; | ||
this._state.queue = state.queue || []; | ||
this._state.oldQueue = state.oldQueue || null; | ||
this._state.handlers = state.handlers || []; | ||
this._state.handlers.push(this); | ||
this._identity = promise.Promise; | ||
}, | ||
{ | ||
_locals: undefined, | ||
_deep_promise_: true, | ||
_enqueue: addInChain, | ||
_next: next, | ||
_running: false, | ||
_executing: false, | ||
_initialised: false, | ||
_resolved: false, | ||
_rejected: false, | ||
resolve: function(success) { | ||
if (this._resolved || this._rejected) | ||
throw errors.Internal("promise already resolved or rejected"); | ||
this._resolved = true; | ||
this._paused = false; | ||
this._initialised = true; | ||
if (typeof success !== "undefined") | ||
this._state.success = success; | ||
var instanceOfError = this._state.success instanceof Error; | ||
this._state.error = instanceOfError ? this._state.success : this._state.error; | ||
this._state.success = instanceOfError ? null : this._state.success; | ||
this._next(); | ||
return this; | ||
}, | ||
reject: function(error) { | ||
if (this._resolved || this._rejected) | ||
throw errors.Internal("promise already resolved or rejected"); | ||
this._rejected = true; | ||
this._paused = false; | ||
this._initialised = true; | ||
this._state.error = error; | ||
this._next(); | ||
return this; | ||
}, | ||
/* | ||
_start: function(opt) { | ||
//console.log("_start : ", opt, this._id); | ||
if (opt) | ||
for (var i in opt) | ||
this._state[i] = opt[i]; | ||
this._paused = false; | ||
this._initialised = true; | ||
this._state.error = (this._state.success instanceof Error) ? this._state.success : this._state.error; | ||
this._state.success = (this._state.success instanceof Error) ? null : this._state.success; | ||
this._next(); | ||
//console.log("_start : end ", opt, this._id); | ||
return this; | ||
},*/ | ||
/*_forward: function(clone) { | ||
return { | ||
handlers: (clone ? this._state.handlers.slice() : this._state.handlers), | ||
queue: ((clone && this._state.queue) ? this._state.queue.slice() : []), | ||
oldQueue: ((clone && this._state.oldQueue) ? this._state.oldQueue.slice() : null), | ||
success: this._state.success, | ||
error: this._state.error | ||
}; | ||
},*/ | ||
close: function() { | ||
var self = this; | ||
if (this._state.handlers.length == 1) | ||
return this; | ||
this._state.handlers.pop(); | ||
return this._state.handlers[this._state.handlers.length - 1]; //._start(); | ||
}, | ||
clone: function() { | ||
return new this._identity({ | ||
handlers: this._state.handlers.slice(), | ||
queue: (this._state.queue ? this._state.queue.slice() : []), | ||
oldQueue: (this._state.oldQueue ? this._state.oldQueue.slice() : null), | ||
success: this._state.success, | ||
error: this._state.error | ||
}); | ||
}, | ||
catchError: function(arg) { | ||
var self = this; | ||
var func = function(s, e) { | ||
self.toContext("rethrow", arg ? true : false); | ||
}; | ||
return self._enqueue(func); | ||
}, | ||
pushTo: function(array) { | ||
var self = this; | ||
if (self._initialised) { | ||
var func = function(s, e) { | ||
array.push(self); | ||
}; | ||
self._enqueue(func); | ||
} else | ||
array.push(self); | ||
return this; | ||
}, | ||
done: function(callBack) { | ||
if (arguments.length !== 1) | ||
throw new Error("done has weirds args : ", arguments); | ||
var self = this; | ||
var func = function(s, e) { | ||
//console.log("deep.done : ",s,e) | ||
//self._state.oldQueue = self._state.queue; | ||
//self._state.queue = []; | ||
if(!callBack) | ||
return s; | ||
var a = callBack.call(self, s); | ||
if (a === self) | ||
return; | ||
return a; | ||
}; | ||
func._isDone_ = true; | ||
return self._enqueue(func); | ||
}, | ||
fail: function(callBack) { | ||
if (arguments.length !== 1) | ||
throw new Error("fail has weirds args : ", arguments); | ||
var self = this; | ||
var func = function(s, e) { | ||
//self._state.oldQueue = self._state.queue; | ||
//self._state.queue = []; | ||
if(!callBack) | ||
return e; | ||
var a = callBack.call(self, e); | ||
if (a === self) | ||
return; | ||
return a; | ||
}; | ||
func._isFail_ = true; | ||
return self._enqueue(func); | ||
}, | ||
always: function(callBack) { | ||
if (arguments.length !== 1) | ||
throw new Error("always has weirds args : ", arguments); | ||
var self = this; | ||
var func = function(s, e) { | ||
//self._state.oldQueue = self._state.queue; | ||
//self._state.queue = []; | ||
if(!callBack) | ||
return [s, e]; | ||
var a = callBack.call(self, s, e); | ||
if (a === self) | ||
return; | ||
return a; | ||
}; | ||
return self._enqueue(func); | ||
}, | ||
then: function(successCallBack, errorCallBack) { | ||
var self = this; | ||
var func = null; | ||
if (successCallBack) { | ||
func = function(s, e) { | ||
var a = successCallBack.call(self, s); | ||
if (a === self) | ||
return; | ||
return a; | ||
}; | ||
func._isDone_ = true; | ||
self._enqueue(func); | ||
} | ||
if (errorCallBack) { | ||
func = function(s, e) { | ||
var a = errorCallBack.call(self, e); | ||
if (a === self) | ||
return; | ||
return a; | ||
}; | ||
func._isFail_ = true; | ||
self._enqueue(func); | ||
} | ||
return this; | ||
}, | ||
/** | ||
* will wait xxxx ms before contiuing chain | ||
* | ||
* transparent true | ||
* | ||
* | ||
* @chainable | ||
* @method delay | ||
* @param {number} ms | ||
* @return {deep.NodesChain} this | ||
*/ | ||
delay: function(ms, callback) { | ||
var self = this; | ||
var func = function(s, e) { | ||
var time; | ||
//console.log("deep.delay : ", ms); | ||
var def = promise.Deferred(); | ||
setTimeout(function() { | ||
def.resolve(undefined); | ||
}, ms); | ||
var p = def.promise(); | ||
if (callback) | ||
p.done(function() { | ||
return callback(s); | ||
}); | ||
return p; | ||
}; | ||
func._isDone_ = true; | ||
return self._enqueue(func); | ||
}, | ||
/** | ||
* set key/value in current state | ||
* | ||
* @chainable | ||
* @method context | ||
* @param {String} key | ||
* @param {*} value | ||
* @return {deep.NodesChain} this | ||
*/ | ||
toState: function(key, val) { | ||
var self = this; | ||
var create = function(s, e) { | ||
if (!key) | ||
return errors.Internal(".toState need key/val couple."); | ||
val = (typeof val === 'undefined') ? s : val; | ||
self._state[key] = val; | ||
return val; | ||
}; | ||
create._isDone_ = true; | ||
return self._enqueue(create); | ||
}, | ||
/** | ||
* read key/value in current state | ||
* | ||
* @chainable | ||
* @method state | ||
* @param {String} key | ||
* @param {*} value | ||
* @return {deep.NodesChain} this | ||
*/ | ||
fromState: function(key) { | ||
var self = this; | ||
var func = function(s, e) { | ||
if (!key) | ||
return self._state; | ||
var out = self._state[key]; | ||
return (typeof out === 'undefined') ? deep.Undefined : out; | ||
}; | ||
func._isDone_ = true; | ||
return self._enqueue(func); | ||
}, | ||
/** | ||
* wait promise resolution or rejection before continuing chain | ||
* | ||
* asynch | ||
* transparent false | ||
* | ||
* @method when | ||
* @param {deep.when} prom the promise to waiting for | ||
* @chainable | ||
* @return {deep.NodesChain} | ||
*/ | ||
when: function(prom) { | ||
var self = this; | ||
var func = function(s, e) { | ||
return prom; | ||
}; | ||
func._isDone_ = true; | ||
return self._enqueue(func); | ||
}, | ||
//_____________________________________________________________ BRANCHES | ||
/** | ||
* asynch handler for chain branches creation | ||
* | ||
* if you return the branches function (the branch creator) : the chain will wait until all the branches are done before continuing | ||
* | ||
* Inject function result in chain as success or error. | ||
* | ||
* @example | ||
* deep.nodes().branches( function(branches) | ||
* { | ||
* branches.branch().query(...).load().log() | ||
* branches.branch().query(...).post().log(); | ||
* //... | ||
* return branches; | ||
* }); | ||
* | ||
* // if you want to return a subset of branches promises : | ||
* // you could use prom.all([array_of_promises]) : | ||
* | ||
* var branch = branches.branch().myChain()...; | ||
* //... | ||
* return prom.all([prom.when(branch), ...]); | ||
* | ||
* @method branches | ||
* @async | ||
* @chainable | ||
* @param {Function} func the callback that will receive the brancher (see above) | ||
* @return {chains.Chain} this | ||
*/ | ||
branches: function(func) { | ||
var self = this; | ||
var create = function(s, e) { | ||
var a = func.call(self, brancher(self)); | ||
if (a === self) | ||
return; | ||
return a; | ||
}; | ||
create._isDone_ = true; | ||
return self._enqueue(create); | ||
}, | ||
loop: function(cb, interval, maxIteration, input) { | ||
var func = function(s, e) { | ||
return promise.loop(cb, interval, maxIteration, input || s); | ||
}; | ||
func._isDone_ = true; | ||
return this._enqueue(func); | ||
} | ||
}); | ||
Promise.addInChain = addInChain; | ||
var brancher = function(handler) { | ||
var self = this; | ||
var br = { | ||
branches: [], | ||
branch: function() { | ||
if (this._ended) | ||
throw errors.Internal("Branching failed : brancher has already bean ended. Could not add branches any more."); | ||
var cloned = handler.clone(true); | ||
cloned._initialised = true; | ||
this.branches.push(cloned); | ||
return cloned; | ||
}, | ||
promise: function() { | ||
this._ended = true; | ||
return promise.all(this.branches); | ||
} | ||
}; | ||
return br; | ||
}; | ||
promise.wrapNodeAsynch = promise.wrapNodeAsync = promise.async = function(parent, cmd, args) { | ||
var def = promise.Deferred(); | ||
//console.log("wrapNodeAsynch : ", typeof parent, cmd); | ||
var callback = function() { | ||
var argus = Array.prototype.slice.apply(arguments); | ||
var err = argus.shift(); | ||
if (err) | ||
def.reject(err); | ||
else if (!argus.length) | ||
def.resolve(true); | ||
else if (argus.length == 1) | ||
def.resolve(argus[0]); | ||
else | ||
def.resolve(argus); | ||
}; | ||
args.push(callback); | ||
if (parent) { | ||
if (typeof cmd === 'string') | ||
parent[cmd].apply(parent, args); | ||
else | ||
cmd.apply(parent, args); | ||
} else | ||
cmd.apply({}, args); | ||
return def.promise(); | ||
}; | ||
/** | ||
* execute array of funcs sequencially | ||
* @for deep | ||
* @static | ||
* @method sequence | ||
* @param {String} funcs an array of functions to execute sequentially | ||
* @param {Object} args (optional) some args to pass to first functions | ||
* @return {deep.Promise} a promise | ||
*/ | ||
promise.series = function(funcs, context, args) { | ||
if (!funcs || funcs.length === 0) | ||
return args; | ||
var current = funcs.shift(); | ||
var def = promise.Deferred(); | ||
context = context || {}; | ||
var doIt = function(r) { | ||
promise.when(r).then(function(r) { | ||
if (funcs.length === 0) { | ||
if (typeof r === 'undefined') { | ||
r = args; | ||
if (args.length == 1) | ||
r = args[0]; | ||
} | ||
def.resolve(r); | ||
return r; | ||
} | ||
if (typeof r === 'undefined') | ||
r = args; | ||
else | ||
r = [r]; | ||
current = funcs.shift(); | ||
doIt(current.apply(context, r)); | ||
}, function(error) { | ||
if (!def.rejected && !def.resolved && !def.canceled) | ||
def.reject(error); | ||
}); | ||
}; | ||
doIt(current.apply(context, args)); | ||
return def.promise(); | ||
}; | ||
/** | ||
* iterate over an array of objects (could be array of promises). | ||
* Execute 'done' callback for each entry. (or 'fail' if item is error) | ||
* @param {[type]} collection [description] | ||
* @param {Function} done [description] | ||
* @param {[type]} fail [description] | ||
* @return {[type]} [description] | ||
*/ | ||
promise.iterate = function(collection, done, fail) { | ||
var coll = collection.concat([]); | ||
var res = []; | ||
var doneAndIterate = function(s) { | ||
if (coll.length > 0) | ||
this.done(function(s) { | ||
res.push(s); | ||
}) | ||
.when(coll.shift()) | ||
.done(doneAndIterate); | ||
return done.call(this, s); | ||
}; | ||
var failAndIterate = function(e) { | ||
if (!fail) | ||
return e; | ||
if (coll.length > 0) | ||
this.when(coll.shift()) | ||
.done(doneAndIterate); | ||
var self = this; | ||
return promise.when(fail.call(this, e)) | ||
.done(function(s) { | ||
if (typeof s === 'undefined' || s instanceof Error) | ||
return s || e; | ||
res.push(s); | ||
self.fail(failAndIterate); | ||
}); | ||
}; | ||
var iterator = promise.when(coll.shift()) | ||
.done(doneAndIterate) | ||
.fail(failAndIterate) | ||
.done(function(s) { | ||
res.push(s); | ||
return res; | ||
}); | ||
return iterator; | ||
}; | ||
promise.wired = function(functions, args, context, done, fail) { | ||
//console.log("wired : ", functions, args, context, done, fail); | ||
var ctx = context || {}; | ||
if (args && !args.forEach) | ||
args = [args]; | ||
var coll = functions.concat([]); | ||
var doneAndIterate = function(s) { | ||
//console.log("done and wired : ",s) | ||
if (done) | ||
this.done(function(s) { | ||
return done.call(this, s); | ||
}); | ||
if (coll.length > 0) | ||
this.done(function(s) { | ||
args = s; | ||
if (args && !args.forEach) | ||
args = [args]; | ||
this.when(coll.shift()) | ||
.done(doneAndIterate); | ||
}); | ||
if (s._deep_query_node_) | ||
return s.value.apply(context || (s.ancestor) ? s.ancestor.value : {}, args); | ||
return s.apply(ctx, args); | ||
}; | ||
var failAndIterate = function(e) { | ||
if (!fail) | ||
return e; | ||
if (coll.length > 0) | ||
this.when(coll.shift()) | ||
.done(doneAndIterate); | ||
var self = this; | ||
return promise.when(fail.call(this, e)) | ||
.done(function(s) { | ||
if (typeof s === 'undefined' || s instanceof Error) | ||
return s || e; | ||
args = s; | ||
if (args && !args.forEach) | ||
args = [args]; | ||
self.fail(failAndIterate); | ||
}); | ||
}; | ||
var iterator = promise.when(coll.shift()) | ||
.done(doneAndIterate) | ||
.fail(failAndIterate); | ||
return iterator; | ||
}; | ||
/** | ||
* contextualised loop on a callback | ||
* | ||
* | ||
* @example | ||
* deep.loop(function(s){ console.log("hello success : ", s); return s+1; }, 50, 10, 1).done(function(s){ console.log("end of loop : ", s); }); | ||
* | ||
* @example | ||
* // to finish loop : | ||
* | ||
* deep.loop(function(s){ console.log("hello success : ", s); if(s >10) this.finish(); return s+1; }, 50, null, 1).done(function(s){ console.log("end of loop : ", s); }); | ||
* | ||
* @param {Function} callBack the callback that need to be called several times. receive promise success as single argument. | ||
* @param {Number} interval interval between call | ||
* @param {Number} maxIteration | ||
* @param {*} input First promise success | ||
* @return {Promise} a promise that could handle end of loop. | ||
*/ | ||
promise.loop = function(callBack, interval, maxIteration, input) { | ||
var iteration = 0, | ||
finished = false; | ||
var iterate = function(s) { | ||
if (finished) | ||
return s; | ||
if (maxIteration) { | ||
iteration++; | ||
if (maxIteration < iteration) | ||
return s; | ||
} | ||
this.done(callBack).delay(interval).done(iterate); | ||
return s; | ||
} | ||
var p = new prom.Promise().resolve(input).done(iterate); | ||
p.finish = function() { | ||
finished = true; | ||
}; | ||
return p; | ||
}; | ||
define(["require", "deep-promise/index", "deep-compiler/lib/classes"], function(require, promise, Classes) { | ||
var Promise = Classes(promise.Promise); | ||
for (var i in promise.Promise) // copy statics | ||
Promise[i] = promise.Promise[i]; | ||
promise.Promise = Promise; | ||
return promise; | ||
}); | ||
}); |
@@ -79,3 +79,3 @@ /** | ||
var results = []; | ||
var d = deep.when(this.setup(options)); | ||
var d = deep.contextualise({ protocols:{}, session:null, rethrow:false, debug:true }).done(function(){ return self.setup(options); }); | ||
var closure = {}; | ||
@@ -176,2 +176,44 @@ var applyTest = function(fn) { | ||
function reportToString(){ | ||
var report = this, e = this.finalError; | ||
var output = ""; | ||
output += "\n\n\n___________________________________________________________________"; | ||
output += "\n*******************************************************************"; | ||
output += "\n************************** Bunch time : ***************************"; | ||
if (e) | ||
output += "\nerror while executings tests bunch : "; | ||
output += e; | ||
output += "\n*******************************************************************"; | ||
output += "\n********** tests bunch arrived to end : final report : ************"; | ||
//console.log("\n",report,"\n"); | ||
if(report.errors) | ||
{ | ||
output += "\n\tErrors: "; | ||
report.errors.forEach(function(e) { | ||
output += e.unit + ":" + e.test + " " + String(e.error); | ||
if (e.error && e.error.report) | ||
output += "\nreport : " + report.toString(); | ||
}); | ||
} | ||
else | ||
output += "\n\tNo errors.\n"; | ||
output += "\n\tNumber of units : " + report.numberOfUnits; | ||
output += "\n\tNumber of tests : " + report.numberOfTests; | ||
output += "\n\tsuccess : " + report.success + "/" + report.numberOfTests; | ||
output += "\n\tfailure : " + report.failure + "/" + report.numberOfTests; | ||
output += "\n\tommited : " + report.ommited + "/" + report.numberOfTests; | ||
output += "\n\tommiteds : " + report.ommiteds; | ||
output += "\n\ttime : " + report.time; | ||
output += "\n\ttotalTime : " + report.totalTime; | ||
output += "\n\tcounters : " + JSON.stringify(deep.counter, null, ' '); | ||
//output += JSON.stringify(report, null, ' ')); | ||
output += "\n*******************************************************************"; | ||
output += "\n*******************************************************************"; | ||
output += "\n___________________________________________________________________\n\n"; | ||
return output; | ||
} | ||
Unit.run = deep.test = function(units, options) { | ||
@@ -209,2 +251,3 @@ if (!options && units === false) | ||
ommited: 0, | ||
ommiteds: [], | ||
time: 0 | ||
@@ -244,2 +287,4 @@ }; | ||
report.ommited += s.ommited; | ||
if(s.ommited) | ||
report.ommiteds.push(s.title); | ||
report.numberOfTests += s.numberOfTests; | ||
@@ -258,2 +303,3 @@ report.errors = report.errors.concat(s.errors); | ||
report.totalTime = new Date().getTime() - startTime; | ||
report.counters = deep.counter; | ||
//if(options.verbose !== false) | ||
@@ -288,2 +334,4 @@ //{ | ||
console.log("\tommited : ", report.ommited, "/", report.numberOfTests); | ||
console.log("\tommiteds : ", report.ommiteds); | ||
console.log("\ttime : ", report.time); | ||
@@ -297,3 +345,4 @@ console.log("\ttotalTime : ", report.totalTime); | ||
//} | ||
report.counters = deep.counter; | ||
report.toString = reportToString; | ||
report.finalError = e; | ||
return report; | ||
@@ -300,0 +349,0 @@ }); |
@@ -5,26 +5,26 @@ /** | ||
*/ | ||
if (typeof define !== 'function') { | ||
var define = require('amdefine')(module); | ||
var define = require('amdefine')(module); | ||
} | ||
define(["require", "./errors"], function(require, errors){ | ||
define(["require"], function(require) { | ||
var Validator = null; | ||
var Validator = null; | ||
return { | ||
set:function(Vali){ | ||
Validator = Vali; | ||
}, | ||
validate:function(object, schema){ | ||
if(!Validator) | ||
throw errors.Internal("no real schema validator setted. please set on using (deepjs/lib/validator).set"); | ||
return Validator.validate(object, schema); | ||
}, | ||
partialValidation:function(object, fields, schema){ | ||
if(!Validator) | ||
throw errors.Internal("no real schema validator setted. please set on using (deepjs/lib/validator).set"); | ||
return Validator.partialValidation(object, fields, schema); | ||
return { | ||
set: function(Vali) { | ||
Validator = Vali; | ||
}, | ||
validate: function(object, schema) { | ||
if (!Validator) | ||
throw new Error("no real schema validator setted. please set on using (deepjs/lib/validator).set"); | ||
return Validator.validate(object, schema); | ||
}, | ||
partialValidation: function(object, fields, schema) { | ||
if (!Validator) | ||
throw new Error("no real schema validator setted. please set on using (deepjs/lib/validator).set"); | ||
return Validator.partialValidation(object, fields, schema); | ||
} | ||
} | ||
} | ||
}); |
{ | ||
"name": "deepjs", | ||
"version": "0.14.0", | ||
"author": "Gilles Coomans <gilles.coomans@gmail.com>", | ||
"description": "Atomic tools for better programming", | ||
"homepage": "http://www.deepjs.org", | ||
"keywords": [ | ||
"util", | ||
"promise", | ||
"asynch", | ||
"AOP", | ||
"query", | ||
"composition", | ||
"server", | ||
"client", | ||
"browser", | ||
"restful", | ||
"OCM" | ||
], | ||
"contributors": [ | ||
"Philippe Delabye <phil@chemicalrules.net>" | ||
], | ||
"licenses": [ | ||
{ | ||
"type": "LGPLv3.0", | ||
"url": "http://www.gnu.org/licenses/lgpl-3.0.txt" | ||
"name": "deepjs", | ||
"version": "0.15.0", | ||
"author": "Gilles Coomans <gilles.coomans@gmail.com>", | ||
"description": "Atomic tools for better programming", | ||
"homepage": "http://www.deepjs.org", | ||
"keywords": [ | ||
"util", | ||
"promise", | ||
"asynch", | ||
"AOP", | ||
"query", | ||
"composition", | ||
"server", | ||
"client", | ||
"browser", | ||
"restful", | ||
"OCM" | ||
], | ||
"contributors": [ | ||
"Philippe Delabye <phil@chemicalrules.net>" | ||
], | ||
"licenses": [{ | ||
"type": "LGPLv3.0", | ||
"url": "http://www.gnu.org/licenses/lgpl-3.0.txt" | ||
}], | ||
"directories": { | ||
"lib": "./lib" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/deepjs/deepjs.git" | ||
}, | ||
"dependencies": { | ||
"rql": ">=0.3.1", | ||
"amdefine": "*" | ||
}, | ||
"main": "./deep.js", | ||
"mappings": {}, | ||
"engines": { | ||
"node": ">=0.10.0" | ||
} | ||
], | ||
"directories": { | ||
"lib": "./lib" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/deepjs/deepjs.git" | ||
}, | ||
"dependencies": { | ||
"rql": ">=0.3.1", | ||
"amdefine": "*" | ||
}, | ||
"main": "./deep.js", | ||
"mappings": {}, | ||
"engines": { | ||
"node": ">=0.10.0" | ||
} | ||
} |
@@ -87,3 +87,3 @@ #deepjs | ||
plants : [{uri:"appletree",growSpeed:10}], | ||
watering : deep.compose.after(function () { | ||
watering : deep.compose().after(function () { | ||
console.log("We put some mulch after watering"); | ||
@@ -95,3 +95,3 @@ }) | ||
plants : [{uri:"carrots",growSpeed:6}], | ||
watering : deep.compose.before(function () { | ||
watering : deep.compose().before(function () { | ||
console.log("We protect seedlings before watering"); | ||
@@ -98,0 +98,0 @@ }) |
@@ -8,54 +8,80 @@ /** | ||
define(["require","../deep", "../lib/unit"], function (require, deep, Unit) { | ||
define(["require", "../deep", "../lib/unit"], function(require, deep, Unit) { | ||
//_______________________________________________________________ GENERIC STORE TEST CASES | ||
var unit = { | ||
title:"deepjs/units/chains/values", | ||
stopOnError:false, | ||
tests : { | ||
promise_on_chain:function(){ | ||
title: "deepjs/units/chains/values", | ||
stopOnError: false, | ||
tests: { | ||
promise_on_chain: function() { | ||
return deep.when(deep.nodes("hello").delay(1)) | ||
.equal("hello"); | ||
.equal("hello"); | ||
}, | ||
delayed_run_return:function(){ | ||
delayed_run_return: function() { | ||
return deep.nodes({ | ||
a:true | ||
}) | ||
.run(function(){ | ||
this.b = true; | ||
return deep.nodes(this).delay(1); | ||
}) | ||
.equal({ a:true, b:true }); | ||
a: true | ||
}) | ||
.run(function() { | ||
this.b = true; | ||
return deep.nodes(this).delay(1); | ||
}) | ||
.equal({ | ||
a: true, | ||
b: true | ||
}); | ||
}, | ||
delayed_run_call:function(){ | ||
delayed_run_call: function() { | ||
return deep.nodes({ | ||
c:function(){ | ||
return "c returned"; | ||
} | ||
}) | ||
.run("c") | ||
.equal("c returned"); | ||
c: function() { | ||
return "c returned"; | ||
} | ||
}) | ||
.run("c") | ||
.equal("c returned"); | ||
}, | ||
branch1:function(){ | ||
branch1: function() { | ||
return deep.nodes({ | ||
test:1 | ||
}) | ||
.branches(function(b){ | ||
b.branch().equal({test:1}).delay(2).when("branch 1"); | ||
b.branch().equal({test:1}).delay(1).when("branch 2"); | ||
return b; | ||
}) | ||
.equal(["branch 1","branch 2"]); | ||
test: 1 | ||
}) | ||
.branches(function(b) { | ||
b.branch().equal({ | ||
test: 1 | ||
}).delay(2).when("branch 1"); | ||
b.branch().equal({ | ||
test: 1 | ||
}).delay(1).when("branch 2"); | ||
return b; | ||
}) | ||
.equal(["branch 1", "branch 2"]); | ||
}, | ||
up:function(){ | ||
return deep.nodes({ a:true }) | ||
.up({ b:true }, { c:true }) | ||
.equal({ a:true, b:true, c:true }); | ||
up: function() { | ||
return deep.nodes({ | ||
a: true | ||
}) | ||
.up({ | ||
b: true | ||
}, { | ||
c: true | ||
}) | ||
.equal({ | ||
a: true, | ||
b: true, | ||
c: true | ||
}); | ||
}, | ||
bottom:function(){ | ||
return deep.nodes({ a:true }) | ||
.bottom({ b:true }, { c:true }) | ||
.equal({ b:true, c:true, a:true}); | ||
bottom: function() { | ||
return deep.nodes({ | ||
a: true | ||
}) | ||
.bottom({ | ||
b: true | ||
}, { | ||
c: true | ||
}) | ||
.equal({ | ||
b: true, | ||
c: true, | ||
a: true | ||
}); | ||
} | ||
@@ -66,2 +92,2 @@ } | ||
return unit; | ||
}); | ||
}); |
if (typeof define !== 'function') { | ||
var define = require('amdefine')(module); | ||
var define = require('amdefine')(module); | ||
} | ||
define(["require","../deep"], function (require, deep) { | ||
var unit = { | ||
title:"deepjs/units/classes", | ||
stopOnError:false, | ||
// setup:function(){}, | ||
tests : { | ||
classes_defaultproto:function(){ | ||
var Mc = deep.Classes(function(schema){ | ||
if(schema && this.schema) | ||
deep.up(this.schema, schema); | ||
}, { | ||
schema:{ | ||
bloup:true | ||
} | ||
}); | ||
define(["require", "../deep"], function(require, deep) { | ||
var unit = { | ||
title: "deepjs/units/classes", | ||
stopOnError: false, | ||
// setup:function(){}, | ||
tests: { | ||
classes_defaultproto: function() { | ||
var Mc = deep.Classes(function(schema) { | ||
if (schema && this.schema) | ||
deep.up(this.schema, schema); | ||
}, { | ||
schema: { | ||
bloup: true | ||
} | ||
}); | ||
var a = new Mc({ | ||
fromA:true | ||
}); | ||
var a = new Mc({ | ||
fromA: true | ||
}); | ||
var b = new Mc({ | ||
fromB:true | ||
}); | ||
var b = new Mc({ | ||
fromB: true | ||
}); | ||
return deep.nodes(a.schema) | ||
.equal({ bloup:true, fromA:true }); | ||
} | ||
} | ||
}; | ||
return unit; | ||
}); | ||
return deep.nodes(a.schema) | ||
.equal({ | ||
bloup: true, | ||
fromA: true | ||
}); | ||
} | ||
} | ||
}; | ||
return unit; | ||
}); |
@@ -18,110 +18,157 @@ /** | ||
tests : { | ||
up:function(){ | ||
return deep.nodes({ | ||
steps:[ | ||
{ | ||
id:"client", | ||
label:"hello" | ||
}] | ||
}) | ||
.up({ | ||
steps:[ | ||
{ | ||
id:"address", | ||
label:"heu" | ||
}, | ||
{ | ||
id:"client", | ||
label:"world", | ||
testez:1 | ||
} | ||
] | ||
}) | ||
.equal({ | ||
"steps": [ | ||
{ | ||
"id": "client", | ||
"label": "world", | ||
"testez": 1 | ||
}, | ||
{ | ||
"id": "address", | ||
"label": "heu" | ||
} | ||
] | ||
}); | ||
}, | ||
bottom_object:function(){ | ||
var r = deep.abottom({"a":{"second":true}},{"a":{"hello":"world"}}); | ||
return deep.nodes(r.a).equal({ second:true, hello:"world" }); | ||
}, | ||
bottom_array:function(){ | ||
return deep.nodes({ | ||
steps:[ | ||
{ | ||
id:"client", | ||
label:"hello" | ||
}] | ||
}) | ||
.bottom({ | ||
steps:[ | ||
{ | ||
id:"address", | ||
label:"heu" | ||
}, | ||
{ | ||
id:"client", | ||
label:"world", | ||
testez:1 | ||
} | ||
] | ||
}) | ||
.equal( { | ||
"steps": [ | ||
{ | ||
"id": "address", | ||
"label": "heu" | ||
}, | ||
{ | ||
"id": "client", | ||
"label": "hello", | ||
"testez": 1 | ||
} | ||
] | ||
}); | ||
}, | ||
bottom_array2 : function(){ | ||
return deep.nodes([1,2,3,{id:"e1", title:"hello" }]) | ||
.bottom([4,5,{id:"e1", title:"bottom title" }]) | ||
.equal([4,5,{id:"e1", title:"hello" },1,2,3]); | ||
}, | ||
bottom_ocm:function(){ | ||
var ocm = deep.ocm({ | ||
a:{ | ||
hello:"world" | ||
} | ||
}); | ||
deep.abottom({a:{ second:true }}, ocm); | ||
return deep.nodes(ocm("a")).equal({second:true, hello:"world"}); | ||
}, | ||
aup1:function(){ | ||
var a = { a:true }; | ||
deep.aup({ b:true }, a); | ||
return deep.nodes(a).equal({ a:true, b:true }); | ||
}, | ||
abottom1:function(){ | ||
var a = { a:true }; | ||
deep.abottom({ b:true }, a); | ||
return deep.nodes(a).equal({ b:true, a:true }); | ||
}, | ||
up:function(){ | ||
var tg = { a:true }; | ||
deep.up(tg, { b:true }, { c:true }); | ||
return deep.nodes(tg).equal({ a:true, b:true, c:true }); | ||
}, | ||
bottom:function(){ | ||
var tg = { a:true }; | ||
deep.bottom({ b:true }, { c:true }, tg); | ||
return deep.nodes(tg).equal({ b:true, c:true, a:true }); | ||
} | ||
up: function() { | ||
return deep.nodes({ | ||
steps: [{ | ||
id: "client", | ||
label: "hello" | ||
}] | ||
}) | ||
.up({ | ||
steps: [{ | ||
id: "address", | ||
label: "heu" | ||
}, { | ||
id: "client", | ||
label: "world", | ||
testez: 1 | ||
}] | ||
}) | ||
.equal({ | ||
"steps": [{ | ||
"id": "client", | ||
"label": "world", | ||
"testez": 1 | ||
}, { | ||
"id": "address", | ||
"label": "heu" | ||
}] | ||
}); | ||
}, | ||
bottom_object: function() { | ||
var r = deep.abottom({ | ||
"a": { | ||
"second": true | ||
} | ||
}, { | ||
"a": { | ||
"hello": "world" | ||
} | ||
}); | ||
return deep.nodes(r.a).equal({ | ||
second: true, | ||
hello: "world" | ||
}); | ||
}, | ||
bottom_array: function() { | ||
return deep.nodes({ | ||
steps: [{ | ||
id: "client", | ||
label: "hello" | ||
}] | ||
}) | ||
.bottom({ | ||
steps: [{ | ||
id: "address", | ||
label: "heu" | ||
}, { | ||
id: "client", | ||
label: "world", | ||
testez: 1 | ||
}] | ||
}) | ||
.equal({ | ||
"steps": [{ | ||
"id": "address", | ||
"label": "heu" | ||
}, { | ||
"id": "client", | ||
"label": "hello", | ||
"testez": 1 | ||
}] | ||
}); | ||
}, | ||
bottom_array2: function() { | ||
return deep.nodes([1, 2, 3, { | ||
id: "e1", | ||
title: "hello" | ||
}]) | ||
.bottom([4, 5, { | ||
id: "e1", | ||
title: "bottom title" | ||
}]) | ||
.equal([4, 5, { | ||
id: "e1", | ||
title: "hello" | ||
}, 1, 2, 3]); | ||
}, | ||
bottom_ocm: function() { | ||
var ocm = deep.ocm({ | ||
a: { | ||
hello: "world" | ||
} | ||
}); | ||
deep.abottom({ | ||
a: { | ||
second: true | ||
} | ||
}, ocm); | ||
return deep.nodes(ocm("a")).equal({ | ||
second: true, | ||
hello: "world" | ||
}); | ||
}, | ||
aup1: function() { | ||
var a = { | ||
a: true | ||
}; | ||
deep.aup({ | ||
b: true | ||
}, a); | ||
return deep.nodes(a).equal({ | ||
a: true, | ||
b: true | ||
}); | ||
}, | ||
abottom1: function() { | ||
var a = { | ||
a: true | ||
}; | ||
deep.abottom({ | ||
b: true | ||
}, a); | ||
return deep.nodes(a).equal({ | ||
b: true, | ||
a: true | ||
}); | ||
}, | ||
up: function() { | ||
var tg = { | ||
a: true | ||
}; | ||
deep.up(tg, { | ||
b: true | ||
}, { | ||
c: true | ||
}); | ||
return deep.nodes(tg).equal({ | ||
a: true, | ||
b: true, | ||
c: true | ||
}); | ||
}, | ||
bottom: function() { | ||
var tg = { | ||
a: true | ||
}; | ||
deep.bottom({ | ||
b: true | ||
}, { | ||
c: true | ||
}, tg); | ||
return deep.nodes(tg).equal({ | ||
b: true, | ||
c: true, | ||
a: true | ||
}); | ||
} | ||
} | ||
@@ -128,0 +175,0 @@ }; |
@@ -8,4 +8,4 @@ /** | ||
define(["require","../deep", "../lib/unit"], function (require, deep, Unit) { | ||
define(["require", "../deep", "../lib/unit"], function(require, deep, Unit) { | ||
//_______________________________________________________________ GENERIC STORE TEST CASES | ||
@@ -15,16 +15,16 @@ | ||
var unit = { | ||
title:"deepjs/units/compositions", | ||
stopOnError:false, | ||
setup:function(){ | ||
title: "deepjs/units/compositions", | ||
stopOnError: false, | ||
setup: function() { | ||
return { | ||
a : { | ||
func1:function(){ | ||
a: { | ||
func1: function() { | ||
//console.log("func1"); | ||
this.res.push("func1"); | ||
}, | ||
func2:deep.compose.before(function(){ | ||
func2: deep.compose().before(function() { | ||
//console.log("func2"); | ||
this.res.push("func2"); | ||
}), | ||
func3:deep.compose.after(function(){ | ||
func3: deep.compose().after(function() { | ||
//console.log("func3"); | ||
@@ -34,13 +34,13 @@ this.res.push("func3"); | ||
}, | ||
b : { | ||
res:[], | ||
func1:deep.compose.after(function(){ | ||
b: { | ||
res: [], | ||
func1: deep.compose().after(function() { | ||
// console.log("func1_1"); | ||
this.res.push("func1_1"); | ||
}), | ||
func2:deep.compose.after(function(){ | ||
func2: deep.compose().after(function() { | ||
// console.log("func2_2"); | ||
this.res.push("func2_2"); | ||
}), | ||
func3:deep.compose.after(function(){ | ||
func3: deep.compose().after(function() { | ||
// console.log("func3_3"); | ||
@@ -50,13 +50,13 @@ this.res.push("func3_3"); | ||
}, | ||
c : { | ||
res:[], | ||
func1:deep.compose.after(function(){ | ||
c: { | ||
res: [], | ||
func1: deep.compose().after(function() { | ||
// console.log("func1_1_c"); | ||
this.res.push("func1_1_c"); | ||
}), | ||
func2:deep.compose.after(function(){ | ||
func2: deep.compose().after(function() { | ||
// console.log("func2_2_c"); | ||
this.res.push("func2_2_c"); | ||
}), | ||
func3:deep.compose.after(function(){ | ||
func3: deep.compose().after(function() { | ||
// console.log("func3_3_c"); | ||
@@ -68,23 +68,25 @@ this.res.push("func3_3_c"); | ||
}, | ||
tests : { | ||
a:function(){ | ||
tests: { | ||
a: function() { | ||
return deep.nodes(this.b) | ||
.bottom(this.a) | ||
.query("/(func.*)") | ||
.run() | ||
.nodes(this.b.res) | ||
.equal(["func1","func1_1", "func2","func2_2","func3","func3_3"]); | ||
.bottom(this.a) | ||
.query("/(func.*)") | ||
.run() | ||
.nodes(this.b.res) | ||
.equal(["func1", "func1_1", "func2", "func2_2", "func3", "func3_3"]); | ||
}, | ||
b:function(){ | ||
b: function() { | ||
return deep.nodes(this.c) | ||
.bottom(this.a) | ||
.query("./(func.*)") | ||
.run() | ||
.nodes(this.c.res) | ||
.equal(["func1","func1_1_c", "func2","func2_2_c","func3","func3_3_c"]); | ||
.bottom(this.a) | ||
.query("./(func.*)") | ||
.run() | ||
.nodes(this.c.res) | ||
.equal(["func1", "func1_1_c", "func2", "func2_2_c", "func3", "func3_3_c"]); | ||
}, | ||
after:function(){ | ||
var closure = { test:"" }; | ||
after: function() { | ||
var closure = { | ||
test: "" | ||
}; | ||
var a = { | ||
test:function(){ | ||
test: function() { | ||
closure.test += "hello test"; | ||
@@ -95,3 +97,3 @@ return closure.test; | ||
var b = { | ||
test:deep.compose.after(function(){ | ||
test: deep.compose().after(function() { | ||
closure.test += " : after"; | ||
@@ -103,8 +105,10 @@ return closure.test; | ||
return deep.when(a.test()) | ||
.equal("hello test : after"); | ||
.equal("hello test : after"); | ||
}, | ||
delayed_after:function(){ | ||
var closure = { test:"" }; | ||
delayed_after: function() { | ||
var closure = { | ||
test: "" | ||
}; | ||
var a = { | ||
test:function(){ | ||
test: function() { | ||
closure.test += "hello test"; | ||
@@ -115,3 +119,3 @@ return deep.when(closure.test).delay(2); | ||
var b = { | ||
test:deep.compose.after(function(){ | ||
test: deep.compose().after(function() { | ||
closure.test += " : after"; | ||
@@ -123,7 +127,7 @@ return deep.when(closure.test).delay(1); | ||
return deep.when(a.test()) | ||
.equal( "hello test : after" ); | ||
.equal("hello test : after"); | ||
}, | ||
around:function(){ | ||
around: function() { | ||
var a = { | ||
test:function(){ | ||
test: function() { | ||
return "test"; | ||
@@ -133,5 +137,5 @@ } | ||
var b = { | ||
test:deep.compose.around(function(old){ | ||
return function(){ | ||
return "hello "+ old.apply(this) + " around"; | ||
test: deep.compose().around(function(old) { | ||
return function() { | ||
return "hello " + old.apply(this) + " around"; | ||
}; | ||
@@ -142,8 +146,10 @@ }) | ||
return deep.when(a.test()) | ||
.equal("hello test around"); | ||
.equal("hello test around"); | ||
}, | ||
before:function(){ | ||
var closure = { test:"" }; | ||
before: function() { | ||
var closure = { | ||
test: "" | ||
}; | ||
var a = { | ||
test:function(){ | ||
test: function() { | ||
closure.test += "hello test"; | ||
@@ -153,3 +159,3 @@ } | ||
var b = { | ||
test:deep.compose.before(function(){ | ||
test: deep.compose().before(function() { | ||
closure.test += "before : "; | ||
@@ -161,8 +167,10 @@ }) | ||
return deep.nodes(closure.test) | ||
.equal("before : hello test"); | ||
.equal("before : hello test"); | ||
}, | ||
delayed_before:function(){ | ||
var closure = { test:"" }; | ||
delayed_before: function() { | ||
var closure = { | ||
test: "" | ||
}; | ||
var a = { | ||
test:function(){ | ||
test: function() { | ||
closure.test += "hello test"; | ||
@@ -173,3 +181,3 @@ return deep.nodes(closure.test).delay(1); | ||
var b = { | ||
test:deep.compose.before(function(){ | ||
test: deep.compose().before(function() { | ||
closure.test += "before : "; | ||
@@ -181,37 +189,37 @@ return deep.nodes(closure.test).delay(1); | ||
return deep.when(a.test()) | ||
.equal("before : hello test"); | ||
.equal("before : hello test"); | ||
}, | ||
parallele:function(){ | ||
// parallele: function() { | ||
// var a = { | ||
// test: function() { | ||
// return "hello test"; | ||
// } | ||
// }; | ||
// var b = { | ||
// test: deep.compose.parallele(function() { | ||
// return "hello parallele"; | ||
// }) | ||
// }; | ||
// deep.up(a, b); | ||
// return deep.when(a.test()) | ||
// .equal("hello test"); | ||
// }, | ||
// delayed_parallele: function() { | ||
// var a = { | ||
// test: function() { | ||
// return deep.when("hello test").delay(1); | ||
// } | ||
// }; | ||
// var b = { | ||
// test: deep.compose.parallele(function() { | ||
// return deep.when("hello parallele").delay(2); | ||
// }) | ||
// }; | ||
// deep.up(a, b); | ||
// return deep.when(a.test()) | ||
// .equal("hello test"); | ||
// }, | ||
before_alone: function() { | ||
var a = { | ||
test:function(){ | ||
return "hello test"; | ||
} | ||
}; | ||
var b = { | ||
test:deep.compose.parallele(function(){ | ||
return "hello parallele"; | ||
}) | ||
}; | ||
deep.up(a, b); | ||
return deep.when(a.test()) | ||
.equal(["hello test", "hello parallele"]); | ||
}, | ||
delayed_parallele:function(){ | ||
var a = { | ||
test:function(){ | ||
return deep.when("hello test").delay(1); | ||
} | ||
}; | ||
var b = { | ||
test:deep.compose.parallele(function(){ | ||
return deep.when("hello parallele").delay(2); | ||
}) | ||
}; | ||
deep.up(a, b); | ||
return deep.when(a.test()) | ||
.equal(["hello test", "hello parallele"]); | ||
}, | ||
before_alone:function(){ | ||
var a = { | ||
test:deep.compose.before(function(){ | ||
test: deep.compose().before(function() { | ||
return "hello"; | ||
@@ -222,5 +230,5 @@ }) | ||
}, | ||
before_alone_with_arg:function(){ | ||
before_alone_with_arg: function() { | ||
var a = { | ||
test:deep.compose.before(function(arg){ | ||
test: deep.compose().before(function(arg) { | ||
return "hello"; | ||
@@ -231,11 +239,11 @@ }) | ||
}, | ||
before_replace_arg:function(){ | ||
before_replace_arg: function() { | ||
var b = { | ||
test:function(arg){ | ||
return "hello : "+arg; | ||
test: function(arg) { | ||
return "hello : " + arg; | ||
} | ||
}; | ||
var a = { | ||
test:deep.compose.before(function(arg){ | ||
return "weee"; | ||
test: deep.compose().before(function(arg) { | ||
return "weee"; | ||
}) | ||
@@ -248,11 +256,11 @@ }; | ||
}, | ||
before_dont_replace_arg:function(){ | ||
before_dont_replace_arg: function() { | ||
var b = { | ||
test:function(arg){ | ||
return "hello : "+arg; | ||
test: function(arg) { | ||
return "hello : " + arg; | ||
} | ||
}; | ||
var a = { | ||
test:deep.compose.before(function(arg){ | ||
// return nothing so arg are forwarded | ||
test: deep.compose().before(function(arg) { | ||
// return nothing so arg are forwarded | ||
}) | ||
@@ -265,11 +273,11 @@ }; | ||
}, | ||
after_forward_result : function(){ | ||
after_forward_result: function() { | ||
var b = { | ||
test:function(arg){ | ||
return "hello : "+arg; | ||
test: function(arg) { | ||
return "hello : " + arg; | ||
} | ||
}; | ||
var a = { | ||
test:deep.compose.after(function(arg){ | ||
// return nothing so result are not changed | ||
test: deep.compose().after(function(arg) { | ||
// return nothing so result are not changed | ||
}) | ||
@@ -282,11 +290,11 @@ }; | ||
}, | ||
after_receive_forwarded_arg:function(){ | ||
after_receive_forwarded_arg: function() { | ||
var b = { | ||
test:function(arg){ | ||
return "hello : "+arg; | ||
test: function(arg) { | ||
return "hello : " + arg; | ||
} | ||
}; | ||
var a = { | ||
test:deep.compose.after(function(arg){ | ||
return arg+"!"; | ||
test: deep.compose().after(function(arg) { | ||
return arg + "!"; | ||
}) | ||
@@ -297,54 +305,54 @@ }; | ||
return deep.when(a.test("bloup")) | ||
.equal("hello : bloup!"); | ||
.equal("hello : bloup!"); | ||
}, | ||
argsBefore:function(){ | ||
argsBefore: function() { | ||
var checker = {}; | ||
var a = { | ||
test:function(arg1, arg2){ | ||
test: function(arg1, arg2) { | ||
checker.fromA = [arg1, arg2]; | ||
return deep.Arguments(["A1:"+arg1, "A2:"+arg2]); | ||
return deep.Arguments(["A1:" + arg1, "A2:" + arg2]); | ||
} | ||
}; | ||
var b = { | ||
test:deep.compose.before(function(arg1, arg2){ | ||
test: deep.compose().before(function(arg1, arg2) { | ||
checker.fromB = [arg1, arg2]; | ||
return deep.Arguments(["B1:"+arg1, "B2:"+arg2]); | ||
return deep.Arguments(["B1:" + arg1, "B2:" + arg2]); | ||
}) | ||
}; | ||
deep.up(a, b); | ||
return deep.nodes(a.test("hello","world")) | ||
.equal(["A1:B1:hello", "A2:B2:world"]) | ||
.nodes(checker) | ||
.equal({ | ||
fromB:["hello","world"], | ||
fromA:["B1:hello", "B2:world"] | ||
}); | ||
return deep.nodes(a.test("hello", "world")) | ||
.equal(["A1:B1:hello", "A2:B2:world"]) | ||
.nodes(checker) | ||
.equal({ | ||
fromB: ["hello", "world"], | ||
fromA: ["B1:hello", "B2:world"] | ||
}); | ||
}, | ||
argsAfter:function(){ | ||
argsAfter: function() { | ||
var checker = {}; | ||
var a = { | ||
test:function(arg1, arg2){ | ||
test: function(arg1, arg2) { | ||
checker.fromA = [arg1, arg2]; | ||
return deep.Arguments(["A1:"+arg1, "A2:"+arg2]); | ||
return deep.Arguments(["A1:" + arg1, "A2:" + arg2]); | ||
} | ||
}; | ||
var b = { | ||
test:deep.compose.after(function(arg1, arg2){ | ||
test: deep.compose().after(function(arg1, arg2) { | ||
checker.fromB = [arg1, arg2]; | ||
return deep.Arguments(["B1:"+arg1, "B2:"+arg2]); | ||
return deep.Arguments(["B1:" + arg1, "B2:" + arg2]); | ||
}) | ||
}; | ||
deep.up(a, b); | ||
return deep.nodes(a.test("hello","world")) | ||
.equal(["B1:A1:hello", "B2:A2:world"]) | ||
.nodes(checker) | ||
.equal({ | ||
fromA:["hello","world"], | ||
fromB:["A1:hello", "A2:world"] | ||
}); | ||
return deep.nodes(a.test("hello", "world")) | ||
.equal(["B1:A1:hello", "B2:A2:world"]) | ||
.nodes(checker) | ||
.equal({ | ||
fromA: ["hello", "world"], | ||
fromB: ["A1:hello", "A2:world"] | ||
}); | ||
}, | ||
argsAfterUndefined:function(){ | ||
argsAfterUndefined: function() { | ||
var checker = {}; | ||
var a = { | ||
test:function(arg1, arg2){ | ||
test: function(arg1, arg2) { | ||
checker.fromA = [arg1, arg2]; | ||
@@ -355,34 +363,33 @@ //return ["A1:"+arg1, "A2:"+arg2]; | ||
var b = { | ||
test:deep.compose.after(function(arg1, arg2){ | ||
test: deep.compose().after(function(arg1, arg2) { | ||
checker.fromB = [arg1, arg2]; | ||
return ["B1:"+arg1, "B2:"+arg2]; | ||
return ["B1:" + arg1, "B2:" + arg2]; | ||
}) | ||
}; | ||
deep.up(a, b); | ||
return deep.nodes(a.test("hello","world")) | ||
.equal(["B1:hello", "B2:world"]) | ||
.nodes(checker) | ||
.equal({ | ||
fromA:["hello", "world"], | ||
fromB:["hello", "world"] | ||
}); | ||
return deep.nodes(a.test("hello", "world")) | ||
.equal(["B1:hello", "B2:world"]) | ||
.nodes(checker) | ||
.equal({ | ||
fromA: ["hello", "world"], | ||
fromB: ["hello", "world"] | ||
}); | ||
}, | ||
fineFail:function(){ | ||
fineFail: function() { | ||
var closure = {}; | ||
var test = function(a,b){ | ||
return [a+2,b+3]; | ||
var test = function(a, b) { | ||
return [a + 2, b + 3]; | ||
}; | ||
var test2 = deep.compose.after(function(a,b){ | ||
return new Error("tralala"); | ||
}) | ||
.after(function(a,b){ | ||
closure.shouldntSeeThis = true; | ||
}); | ||
var test2 = deep.compose().after(function(a, b) { | ||
return new Error("tralala"); | ||
}) | ||
.after(function(a, b) { | ||
closure.shouldntSeeThis = true; | ||
}); | ||
var test3 = deep.up(test, test2); | ||
try{ | ||
test3(1,3); | ||
} | ||
catch(e){ | ||
try { | ||
test3(1, 3); | ||
} catch (e) { | ||
console.log("error cacthed : ", e); | ||
@@ -392,56 +399,7 @@ } | ||
}, | ||
branches:function(){ | ||
var a = function(){ | ||
return "hello"; | ||
}; | ||
a = deep.up(a, deep.compose.branches(function(){ | ||
this.after(function(s){ | ||
return s+":after"; | ||
}); | ||
})); | ||
return deep.nodes(a()).equal("hello:after"); | ||
}, | ||
branches2:function(){ | ||
var a = deep.compose.before(function(){ | ||
return "hello"; | ||
}) | ||
.branches(function(){ | ||
this.around(function(old){ | ||
return function(){ | ||
return "before:"+old.apply(this)+":after"; | ||
}; | ||
}); | ||
}); | ||
return deep.nodes(a()).equal("before:hello:after"); | ||
}, | ||
/*dynamicBranches:function(){ | ||
var closure = { test:true }; | ||
var a = deep.compose.before(function(){ | ||
return "hello"; | ||
}) | ||
.branches(function(){ | ||
if(closure.test) | ||
this.around(function(old){ | ||
return function(){ | ||
return "around:"+old.apply(this)+":around"; | ||
}; | ||
}); | ||
else | ||
this.after(function(s){ | ||
return "after:"+s; | ||
}); | ||
}); | ||
return deep.nodes(a()) | ||
.equal("around:hello:around") | ||
.done(function(s){ | ||
closure.test = false; | ||
return a(); | ||
}) | ||
.equal("after:hello"); | ||
},*/ | ||
func_up_compo:function(){ | ||
var compo = deep.compose.after(function(){ | ||
func_up_compo: function() { | ||
var compo = deep.compose().after(function() { | ||
return "lolipopi"; | ||
}); | ||
var func = function(){ | ||
var func = function() { | ||
return "hello"; | ||
@@ -451,24 +409,27 @@ }; | ||
return deep.nodes(r()) | ||
.equal("hello"); | ||
.equal("hello"); | ||
}, | ||
clone_composer : function(){ | ||
clone_composer: function() { | ||
var base = {}; | ||
var closure = []; | ||
var a = { | ||
bloupi : function(){ | ||
closure.push(1); | ||
} | ||
var a = { | ||
bloupi: function() { | ||
closure.push(1); | ||
} | ||
}; | ||
var b = { | ||
bloupi : deep.compose.after(function(){ | ||
closure.push(2); | ||
}) | ||
var b = { | ||
bloupi: deep.compose().after(function() { | ||
closure.push(2); | ||
}) | ||
}; | ||
var c = { | ||
bloupi : deep.compose.around(function(old){ | ||
return function(){ old.call(this); closure.push(3); }; | ||
}) | ||
bloupi: deep.compose().around(function(old) { | ||
return function() { | ||
old.call(this); | ||
closure.push(3); | ||
}; | ||
}) | ||
}; | ||
deep.up(base, b, c ) | ||
deep.up(base, b, c) | ||
b.bloupi(); | ||
@@ -481,2 +442,2 @@ return deep.when(closure).equal([2]); | ||
return unit; | ||
}); | ||
}); |
if (typeof define !== 'function') { | ||
var define = require('amdefine')(module); | ||
var define = require('amdefine')(module); | ||
} | ||
define(["require","../deep"], function (require, deep) { | ||
define(["require", "../deep"], function(require, deep) { | ||
deep.chainTest = function(){ | ||
deep.chainTest = function() { | ||
return new ChainTest(null).resolve(); | ||
}; | ||
deep.chainTest2 = function(){ | ||
deep.chainTest2 = function() { | ||
return new ChainTest2(null).resolve(); | ||
}; | ||
var ChainTest = deep.compose.Classes(deep.Promise, function (state) { | ||
var ChainTest = deep.Classes(deep.Promise, function(state) { | ||
this._identity = ChainTest; | ||
this._name = "ChainTest"; | ||
}, { | ||
testez:function(res){ | ||
testez: function(res) { | ||
var self = this; | ||
var func = function(s,e){ | ||
return deep.delay(1).done(function(){ | ||
var val = 'seen:'+self._name; | ||
var func = function(s, e) { | ||
return deep.delay(1).done(function() { | ||
var val = 'seen:' + self._name; | ||
res.push(val); | ||
@@ -33,11 +33,11 @@ return val; | ||
var ChainTest2 = deep.Classes(deep.Promise, function (state) { | ||
var ChainTest2 = deep.Classes(deep.Promise, function(state) { | ||
this._identity = ChainTest2; | ||
this._name = "ChainTest2"; | ||
}, { | ||
testez:function(res){ | ||
testez: function(res) { | ||
var self = this; | ||
var func = function(s,e){ | ||
return deep.delay(1).done(function(){ | ||
var val = 'seen2:'+self._name; | ||
var func = function(s, e) { | ||
return deep.delay(1).done(function() { | ||
var val = 'seen2:' + self._name; | ||
res.push(val); | ||
@@ -53,39 +53,39 @@ return val; | ||
deep.up(deep.Promise, { | ||
chainTest : function() { | ||
var handler = new ChainTest(this._state); | ||
this._enqueue(handler); | ||
return handler; | ||
chainTest: function() { | ||
var handler = new ChainTest(this._state); | ||
this._enqueue(handler); | ||
return handler; | ||
}, | ||
chainTest2 :function() { | ||
var handler = new ChainTest2(this._state); | ||
this._enqueue(handler); | ||
return handler; | ||
chainTest2: function() { | ||
var handler = new ChainTest2(this._state); | ||
this._enqueue(handler); | ||
return handler; | ||
} | ||
}); | ||
var unit = { | ||
title:"deepjs/units/custom-chain", | ||
stopOnError:false, | ||
setup:function(){}, | ||
clean:function(){ | ||
var unit = { | ||
title: "deepjs/units/custom-chain", | ||
stopOnError: false, | ||
setup: function() {}, | ||
clean: function() { | ||
}, | ||
tests : { | ||
first:function(){ | ||
var res = []; | ||
return deep | ||
.chainTest() | ||
.testez(res) | ||
.chainTest2() | ||
.testez(res) | ||
.close() | ||
.testez(res) | ||
.done(function(){ | ||
return res; | ||
}) | ||
.equal(['seen:ChainTest', 'seen2:ChainTest2', 'seen:ChainTest']) | ||
} | ||
} | ||
}; | ||
return unit; | ||
}); | ||
}, | ||
tests: { | ||
first: function() { | ||
var res = []; | ||
return deep | ||
.chainTest() | ||
.testez(res) | ||
.chainTest2() | ||
.testez(res) | ||
.close() | ||
.testez(res) | ||
.done(function() { | ||
return res; | ||
}) | ||
.equal(['seen:ChainTest', 'seen2:ChainTest2', 'seen:ChainTest']) | ||
} | ||
} | ||
}; | ||
return unit; | ||
}); |
@@ -32,3 +32,3 @@ /** | ||
}, | ||
myFunc: deep.compose.after(function() { | ||
myFunc: deep.compose().after(function() { | ||
//console.log("myFunc of b : ", this); | ||
@@ -53,11 +53,11 @@ this.obj.b = true; | ||
return deep.nodes({ | ||
_backgrounds: [a], | ||
obj: { | ||
second: true | ||
}, | ||
myFunc: deep.compose.after(function() { | ||
//console.log("myFunc of b : ", this); | ||
this.obj.b = true; | ||
_backgrounds: [a], | ||
obj: { | ||
second: true | ||
}, | ||
myFunc: deep.compose().after(function() { | ||
//console.log("myFunc of b : ", this); | ||
this.obj.b = true; | ||
}) | ||
}) | ||
}) | ||
.flatten() | ||
@@ -75,9 +75,9 @@ .run("myFunc") | ||
return deep.nodes({ | ||
sub: { | ||
_backgrounds: [this.b], | ||
obj: { | ||
third: true | ||
sub: { | ||
_backgrounds: [this.b], | ||
obj: { | ||
third: true | ||
} | ||
} | ||
} | ||
}) | ||
}) | ||
.flatten() | ||
@@ -109,14 +109,14 @@ .query("/sub") | ||
return deep.nodes({ | ||
_backgrounds: [bc2, b], | ||
c: { | ||
_backgrounds: [b], | ||
prop: 2 | ||
}, | ||
d: { | ||
_backgrounds: ["this::../c"], | ||
}, | ||
e: { | ||
_backgrounds: ["this::/c"], | ||
} | ||
}) | ||
_backgrounds: [bc2, b], | ||
c: { | ||
_backgrounds: [b], | ||
prop: 2 | ||
}, | ||
d: { | ||
_backgrounds: ["this::../c"], | ||
}, | ||
e: { | ||
_backgrounds: ["this::/c"], | ||
} | ||
}) | ||
.flatten() | ||
@@ -181,10 +181,12 @@ .done(function(s) { | ||
}, | ||
top_transformations:function(){ | ||
top_transformations: function() { | ||
var a = { | ||
_transformations : [ { "dq.up::./hello":"world" }], | ||
lolipop:true | ||
_transformations: [{ | ||
"dq.up::./hello": "world" | ||
}], | ||
lolipop: true | ||
}; | ||
var b = { | ||
_backgrounds:[a], | ||
hello:"bloupi" | ||
var b = { | ||
_backgrounds: [a], | ||
hello: "bloupi" | ||
}; | ||
@@ -254,4 +256,3 @@ deep.flatten(b); | ||
_backgrounds: [ | ||
"this::../obj1", | ||
{ | ||
"this::../obj1", { | ||
_backgrounds: [{ | ||
@@ -261,4 +262,3 @@ bloup3: true | ||
backback3: true | ||
}, | ||
{ | ||
}, { | ||
_foregrounds: [{ | ||
@@ -328,40 +328,80 @@ hello: "changed!!" | ||
}; | ||
return deep.flatten(a).equal(needed); | ||
return deep.flatten(a).equal(needed); | ||
}, | ||
_transformations1:function(){ | ||
_transformations1: function() { | ||
var a = { | ||
_transformations:[{ | ||
"dq.up::./!":{ done:"hello done" } | ||
}] | ||
_transformations: [{ | ||
"dq.up::./!": { | ||
done: "hello done" | ||
} | ||
}] | ||
} | ||
return deep.nodes(a) | ||
.flatten() | ||
.done(function(success){ | ||
return success.done; | ||
}) | ||
.equal("hello done"); | ||
.flatten() | ||
.done(function(success) { | ||
return success.done; | ||
}) | ||
.equal("hello done"); | ||
}, | ||
_transformations2:function(){ | ||
_transformations2: function() { | ||
var a = { | ||
_backgrounds:[{ reu:"bloupi" }], | ||
_foregrounds:[{ sub:{ foo:"bar"} }], | ||
_transformations:[{ | ||
"dq.up::.//?_type=string":"lolipop" | ||
_backgrounds: [{ | ||
reu: "bloupi" | ||
}], | ||
test:{ | ||
_backgrounds:[{ reu2:"bloupi" }], | ||
_foregrounds:[{ sub2:{ foo2:"bar"} }], | ||
_transformations:[{ | ||
"dq.up::./!":{ roo:"weeee" } | ||
_foregrounds: [{ | ||
sub: { | ||
foo: "bar" | ||
} | ||
}], | ||
_transformations: [{ | ||
"dq.up::.//?_type=string": "lolipop" | ||
}], | ||
test: { | ||
_backgrounds: [{ | ||
reu2: "bloupi" | ||
}], | ||
_foregrounds: [{ | ||
sub2: { | ||
foo2: "bar" | ||
} | ||
}], | ||
_transformations: [{ | ||
"dq.up::./!": { | ||
roo: "weeee" | ||
} | ||
}], | ||
} | ||
} | ||
return deep.nodes(a) | ||
.flatten() | ||
.done(function(a){ | ||
return [a.reu, a.sub.foo, a.test.reu2, a.test.sub2.foo2, a.test.roo]; | ||
}) | ||
.equal(["lolipop","lolipop","lolipop","lolipop","weeee"]); | ||
return deep.flatten(a) | ||
.done(function(a) { | ||
return [a.reu, a.sub.foo, a.test.reu2, a.test.sub2.foo2, a.test.roo]; | ||
}) | ||
.equal(["lolipop", "lolipop", "lolipop", "lolipop", "weeee"]); | ||
}, | ||
_transformations3: function() { | ||
var a = { | ||
_backgrounds: [{ | ||
b: { | ||
_transformations: [{ | ||
_deep_sheet_: true, | ||
"dq.bottom::.//?bloupi": { | ||
decorated: true | ||
} | ||
}], | ||
c: { | ||
bloupi: true | ||
} | ||
} | ||
}] | ||
}; | ||
return deep.flatten(a) | ||
.done(function(success) { | ||
return a.b.c.decorated || null; | ||
}) | ||
.equal(true); | ||
} | ||
@@ -368,0 +408,0 @@ } |
211
units/ocm.js
@@ -87,5 +87,5 @@ /** | ||
return deep.modes({ | ||
"myGroup": "mode1" | ||
}) // start a chain with provided modes | ||
.delay(1) | ||
"myGroup": "mode1" | ||
}) // start a chain with provided modes | ||
.delay(1) | ||
.done(function(success) { | ||
@@ -110,16 +110,16 @@ return myManager(); | ||
return deep.modes({ | ||
group1: "mode1" | ||
}) | ||
group1: "mode1" | ||
}) | ||
.done(function(success) { | ||
return deep.modes({ | ||
group2: "mode2" | ||
}) | ||
.delay(1) | ||
.done(function(success) { | ||
return deep.Promise.context.modes; | ||
}) | ||
.equal({ | ||
group1: "mode1", | ||
group2: "mode2" | ||
}); | ||
group2: "mode2" | ||
}) | ||
.delay(1) | ||
.done(function(success) { | ||
return deep.Promise.context.modes; | ||
}) | ||
.equal({ | ||
group1: "mode1", | ||
group2: "mode2" | ||
}); | ||
}) | ||
@@ -152,6 +152,6 @@ .delay(1) | ||
return obj.flatten().done(function(obj) { | ||
obj("mode1").myShared.push(6); | ||
obj("mode1").myShared2.c = 3; | ||
return [obj("mode1"), obj("mode2")]; | ||
}) | ||
obj("mode1").myShared.push(6); | ||
obj("mode1").myShared2.c = 3; | ||
return [obj("mode1"), obj("mode2")]; | ||
}) | ||
.equal([{ | ||
@@ -188,3 +188,3 @@ myShared: [1, 2, 3, 4, 5, 6], | ||
}, | ||
multiGroup: function() { | ||
@@ -203,3 +203,3 @@ var o = deep.ocm({ | ||
"public": { | ||
get: deep.compose.after(function(s) { | ||
get: deep.compose().after(function(s) { | ||
return s + ":public"; | ||
@@ -209,3 +209,3 @@ }) | ||
admin: { | ||
get: deep.compose.after(function(s) { | ||
get: deep.compose().after(function(s) { | ||
return s + ":admin"; | ||
@@ -219,5 +219,5 @@ }) | ||
return deep.modes({ | ||
env: "dev", | ||
roles: "public" | ||
}) | ||
env: "dev", | ||
roles: "public" | ||
}) | ||
.done(function() { | ||
@@ -241,3 +241,3 @@ return o().get("hello"); | ||
"public": { | ||
get: deep.compose.after(function(s) { | ||
get: deep.compose().after(function(s) { | ||
return s + ":public"; | ||
@@ -247,3 +247,3 @@ }) | ||
admin: { | ||
get: deep.compose.after(function(s) { | ||
get: deep.compose().after(function(s) { | ||
return s + ":admin"; | ||
@@ -257,9 +257,9 @@ }) | ||
return deep.modes({ | ||
env: "prod", | ||
roles:"admin" | ||
}) | ||
.done(function() { | ||
return o().get("hello"); | ||
}) | ||
.equal("prod:hello:admin"); | ||
env: "prod", | ||
roles: "admin" | ||
}) | ||
.done(function() { | ||
return o().get("hello"); | ||
}) | ||
.equal("prod:hello:admin"); | ||
}, | ||
@@ -273,12 +273,14 @@ ocm_transformations: function() { | ||
}, | ||
prod: deep.Sheet({ | ||
"dq.up::./get": deep.compose.after(function(s) { | ||
prod: { | ||
_deep_sheet_: true, | ||
"dq.up::./get": deep.compose().after(function(s) { | ||
return s + ":prod"; | ||
}) | ||
}), | ||
dev: deep.Sheet({ | ||
"dq.up::./get": deep.compose.before(function(s) { | ||
}, | ||
dev: { | ||
_deep_sheet_: true, | ||
"dq.up::./get": deep.compose().before(function(s) { | ||
return "dev:" + s; | ||
}) | ||
}) | ||
} | ||
}, { | ||
@@ -288,17 +290,17 @@ sensibleTo: ["roles", "env"] | ||
return deep.modes({ | ||
env: "dev", | ||
roles: "public" | ||
}) | ||
.done(function() { | ||
return o().get("hello"); | ||
}) | ||
.equal("public:dev:hello") | ||
.modes({ | ||
env: "prod", | ||
roles: "public" | ||
}) | ||
.done(function() { | ||
return o().get("hello"); | ||
}) | ||
.equal("public:hello:prod"); | ||
env: "dev", | ||
roles: "public" | ||
}) | ||
.done(function() { | ||
return o().get("hello"); | ||
}) | ||
.equal("public:dev:hello") | ||
.modes({ | ||
env: "prod", | ||
roles: "public" | ||
}) | ||
.done(function() { | ||
return o().get("hello"); | ||
}) | ||
.equal("public:hello:prod"); | ||
}, | ||
@@ -359,51 +361,80 @@ ocm_afterCompilation: function() { | ||
familly: "Doe" | ||
}]); | ||
} | ||
]); | ||
}, | ||
ocm_strict:function(){ | ||
ocm_strict: function() { | ||
var myManager = deep.ocm({ | ||
dev:{ dev:true }, | ||
prod:{ prod:true }, | ||
"public":{ "public":true }, | ||
admin:{ admin:true } | ||
}, { strict:true }); | ||
dev: { | ||
dev: true | ||
}, | ||
prod: { | ||
prod: true | ||
}, | ||
"public": { | ||
"public": true | ||
}, | ||
admin: { | ||
admin: true | ||
} | ||
}, { | ||
strict: true | ||
}); | ||
return deep.nodes(myManager("prod", "bloup")) | ||
.equal(undefined) | ||
.equal(undefined) | ||
}, | ||
multiModesFalse:function(){ | ||
multiModesFalse: function() { | ||
var myManager = deep.ocm({ | ||
"public":{ "public":true }, | ||
"user":{ "user":true } | ||
}, { multiModes:false }); | ||
"public": { | ||
"public": true | ||
}, | ||
"user": { | ||
"user": true | ||
} | ||
}, { | ||
multiModes: false | ||
}); | ||
return deep.nodes(myManager("public", "user")) | ||
.equal(null); | ||
.equal(null); | ||
}, | ||
auto_flatten:function(){ | ||
auto_flatten: function() { | ||
var store = deep.ocm({ | ||
"user":{ | ||
test:true | ||
}, | ||
"public":{_backgrounds:["this::../user"]} | ||
"user": { | ||
test: true | ||
}, | ||
"public": { | ||
_backgrounds: ["this::../user"] | ||
} | ||
}); | ||
store.modes("public") | ||
return deep.when(deep.protocol(store)).equal({ test:true }); | ||
return deep.when(deep.protocol(store)).equal({ | ||
test: true | ||
}); | ||
}, | ||
flattener_wont_stop_flatten:function(){ | ||
flattener_wont_stop_flatten: function() { | ||
var test = { | ||
pro:{ | ||
o:deep.ocm({ | ||
_backgrounds : [ { test:{ yop:true } }], | ||
bloupi:{ | ||
lolipop:"hello" | ||
} | ||
}, { modes:["bloupi"] }) | ||
}, | ||
second:{ | ||
_backgrounds:[ { shouldBeThere:true } ] | ||
} | ||
pro: { | ||
o: deep.ocm({ | ||
_backgrounds: [{ | ||
test: { | ||
yop: true | ||
} | ||
}], | ||
bloupi: { | ||
lolipop: "hello" | ||
} | ||
}, { | ||
modes: ["bloupi"] | ||
}) | ||
}, | ||
second: { | ||
_backgrounds: [{ | ||
shouldBeThere: true | ||
}] | ||
} | ||
}; | ||
return deep.flatten(test) | ||
.done(function (s) { | ||
return test.second.shouldBeThere; | ||
}) | ||
.equal(true); | ||
.done(function(s) { | ||
return test.second.shouldBeThere; | ||
}) | ||
.equal(true); | ||
} | ||
@@ -410,0 +441,0 @@ } |
@@ -5,28 +5,28 @@ /** | ||
if (typeof define !== 'function') { | ||
var define = require('amdefine')(module); | ||
var define = require('amdefine')(module); | ||
} | ||
define(["require","../deep"], function (require, deep) { | ||
//_______________________________________________________________ GENERIC STORE TEST CASES | ||
define(["require", "../deep"], function(require, deep) { | ||
//_______________________________________________________________ GENERIC STORE TEST CASES | ||
var unit = { | ||
title:"deepjs/units/sheets", | ||
stopOnError:false, | ||
setup:function(){}, | ||
tests : { | ||
base:function(){ | ||
var unit = { | ||
title: "deepjs/units/sheets", | ||
stopOnError: false, | ||
setup: function() {}, | ||
tests: { | ||
base: function() { | ||
var sheet = { | ||
_deep_sheet_:true, | ||
"dq.up::./!":{ | ||
hello:"world", | ||
array:["from up"] | ||
_deep_sheet_: true, | ||
"dq.up::./!": { | ||
hello: "world", | ||
array: ["from up"] | ||
}, | ||
"dq.bottom::./!":{ | ||
array:["from bottom"] | ||
"dq.bottom::./!": { | ||
array: ["from bottom"] | ||
}, | ||
"dq.up::./a":{ | ||
test:123, | ||
other:true | ||
"dq.up::./a": { | ||
test: 123, | ||
other: true | ||
} | ||
@@ -36,92 +36,64 @@ }; | ||
var obj = { | ||
array:["base entry"], | ||
a:{ | ||
test:1 | ||
array: ["base entry"], | ||
a: { | ||
test: 1 | ||
} | ||
}; | ||
deep.sheet(obj, sheet); | ||
return deep.nodes(obj).equal({"array":["from bottom","base entry","from up"],"a":{"test":123,"other":true},"hello":"world"}); | ||
return deep.nodes(obj).equal({ | ||
"array": ["from bottom", "base entry", "from up"], | ||
"a": { | ||
"test": 123, | ||
"other": true | ||
}, | ||
"hello": "world" | ||
}); | ||
}, | ||
map:function(){ | ||
map: function() { | ||
var sheet = { | ||
_deep_sheet_:true, | ||
"dq.map::./*":function(input){ | ||
return "e"+input.value; | ||
_deep_sheet_: true, | ||
"dq.map::./*": function(input) { | ||
return "e" + input.value; | ||
} | ||
}; | ||
return deep.nodes([1,2,3,4,5]) | ||
.sheet(sheet) | ||
.equal(["e1", "e2", "e3", "e4", "e5"]); | ||
return deep.nodes([1, 2, 3, 4, 5]) | ||
.sheet(sheet) | ||
.equal(["e1", "e2", "e3", "e4", "e5"]); | ||
}, | ||
sheets_as__backgrounds:function(){ | ||
sheets_as__backgrounds: function() { | ||
// no effect | ||
return deep.nodes({ | ||
test:false, | ||
_backgrounds:[{ | ||
_deep_sheet_:true, | ||
"dq.bottom::./!":{ | ||
hello:"world" | ||
} | ||
}] | ||
}) | ||
.flatten() | ||
.equal({ | ||
hello:"world", | ||
test:false | ||
}); | ||
test: false, | ||
_backgrounds: [{ | ||
_deep_sheet_: true, | ||
"dq.bottom::./!": { | ||
hello: "world" | ||
} | ||
}] | ||
}) | ||
.flatten() | ||
.equal({ | ||
hello: "world", | ||
test: false | ||
}); | ||
}, | ||
sheets_as_backgrounds2:function(){ | ||
sheets_as_backgrounds3: function() { | ||
return deep.nodes({ | ||
_deep_sheet_:true, | ||
"dq.up::./!":"testez", | ||
"dq.bottom::./!":{ test:true }, | ||
_backgrounds:[{ | ||
_deep_sheet_:true, | ||
"dq.bottom::./!":{ | ||
hello:"world" | ||
} | ||
}] | ||
}) | ||
.flatten() | ||
.equal({ | ||
_deep_sheet_:true, | ||
"dq.bottom::./!":{ hello:"world" , test:true }, | ||
"dq.up::./!":"testez", | ||
}); | ||
test: false, | ||
_backgrounds: [{ | ||
base: "yes" | ||
}, { | ||
_deep_sheet_: true, | ||
"dq.bottom::./!": { | ||
hello: "world" | ||
} | ||
}] | ||
}) | ||
.flatten() | ||
.equal({ | ||
hello: "world", | ||
base: "yes", | ||
test: false | ||
}); | ||
}, | ||
sheets_as_backgrounds3:function(){ | ||
return deep.nodes({ | ||
test:false, | ||
_backgrounds:[{ | ||
base:"yes" | ||
}, { | ||
_deep_sheet_:true, | ||
"dq.bottom::./!":{ | ||
hello:"world" | ||
} | ||
}] | ||
}) | ||
.flatten() | ||
.equal({ | ||
hello:"world", | ||
base:"yes", | ||
test:false | ||
}); | ||
}, | ||
sheets_as_backgrounds4:function(){ | ||
return deep.nodes({ | ||
_deep_sheet_:true, | ||
"dq.up::./!":{ fromUp:true }, | ||
"dq.bottom::./!":{ fromBottom:true }, | ||
_backgrounds:[{ | ||
_deep_sheet_:true, | ||
"dq.up::./!":{ fromUp2:true }, | ||
}] | ||
}) | ||
.flatten() | ||
.equal({ | ||
_deep_sheet_:true, | ||
"dq.up::./!":{ fromUp2:true , fromUp:true }, | ||
"dq.bottom::./!":{ fromBottom:true } | ||
}); | ||
}, | ||
/* | ||
@@ -152,32 +124,40 @@ DEPRECATED TO USE backgrounds in sheets application | ||
sheet_up_sheet:function(){ | ||
sheet_up_sheet: function() { | ||
var a = deep.aup({ | ||
_deep_sheet_:true, | ||
"dq.bottom::.//!":{ bloup:true } | ||
},{ | ||
_deep_sheet_:true, | ||
"dq.bottom::.//!":{ hello:"world" } | ||
_deep_sheet_: true, | ||
"dq.bottom::.//!": { | ||
bloup: true | ||
} | ||
}, { | ||
_deep_sheet_: true, | ||
"dq.bottom::.//!": { | ||
hello: "world" | ||
} | ||
}); | ||
return deep.nodes(a).equal({ | ||
_deep_sheet_:true, | ||
"dq.bottom::.//!":{ | ||
hello:"world", | ||
bloup:true | ||
_deep_sheet_: true, | ||
"dq.bottom::.//!": { | ||
hello: "world", | ||
bloup: true | ||
} | ||
}); | ||
}, | ||
sheet_bottom_sheet:function(){ | ||
sheet_bottom_sheet: function() { | ||
var a = deep.abottom({ | ||
_deep_sheet_:true, | ||
"dq.bottom::.//!":{ bloup:true } | ||
},{ | ||
_deep_sheet_:true, | ||
"dq.bottom::.//!":{ hello:"world" } | ||
_deep_sheet_: true, | ||
"dq.bottom::.//!": { | ||
bloup: true | ||
} | ||
}, { | ||
_deep_sheet_: true, | ||
"dq.bottom::.//!": { | ||
hello: "world" | ||
} | ||
}); | ||
return deep.nodes(a).equal({ | ||
_deep_sheet_:true, | ||
"dq.bottom::.//!":{ | ||
bloup:true, | ||
hello:"world" | ||
_deep_sheet_: true, | ||
"dq.bottom::.//!": { | ||
bloup: true, | ||
hello: "world" | ||
} | ||
@@ -188,3 +168,3 @@ }); | ||
var C = deep.compose.Classes(function(){ | ||
var C = deep.Classes(function(){ | ||
@@ -219,181 +199,225 @@ }, { | ||
},*/ | ||
sheets_foregrounds:function(){ | ||
sheets_foregrounds: function() { | ||
var a = { | ||
_foregrounds:[{ | ||
_deep_sheet_:true, | ||
"dq.bottom::.//!":{ hello:"tulip" } | ||
_foregrounds: [{ | ||
_deep_sheet_: true, | ||
"dq.bottom::.//!": { | ||
hello: "tulip" | ||
} | ||
}], | ||
bloup:true | ||
bloup: true | ||
}; | ||
return deep.nodes(a).flatten() | ||
.equal({ | ||
hello:"tulip", | ||
bloup:true | ||
}); | ||
.equal({ | ||
hello: "tulip", | ||
bloup: true | ||
}); | ||
}, | ||
sheeter_up:function(){ | ||
sheeter_up: function() { | ||
return deep.nodes({ | ||
test:{ hello:"world" } | ||
}) | ||
.sheet({ | ||
_deep_sheet_:true, | ||
"dq::./test":deep.compose.nodes.up({ hello:"deepjs" }) | ||
}) | ||
.equal({ | ||
test:{ hello:"deepjs" } | ||
}); | ||
test: { | ||
hello: "world" | ||
} | ||
}) | ||
.sheet({ | ||
_deep_sheet_: true, | ||
"dq::./test": deep.compose.nodes.up({ | ||
hello: "deepjs" | ||
}) | ||
}) | ||
.equal({ | ||
test: { | ||
hello: "deepjs" | ||
} | ||
}); | ||
}, | ||
sheeter_bottom:function(){ | ||
sheeter_bottom: function() { | ||
return deep.nodes({ | ||
test:{ hello:"world" } | ||
}) | ||
.sheet({ | ||
_deep_sheet_:true, | ||
"dq::./test":deep.compose.nodes.bottom({ bloup:"deepjs" }) | ||
}) | ||
.equal({ | ||
test:{ bloup:"deepjs", hello:"world" } | ||
}); | ||
test: { | ||
hello: "world" | ||
} | ||
}) | ||
.sheet({ | ||
_deep_sheet_: true, | ||
"dq::./test": deep.compose.nodes.bottom({ | ||
bloup: "deepjs" | ||
}) | ||
}) | ||
.equal({ | ||
test: { | ||
bloup: "deepjs", | ||
hello: "world" | ||
} | ||
}); | ||
}, | ||
sheeter_sheet:function(){ | ||
sheeter_sheet: function() { | ||
return deep.nodes({ | ||
test:{ hello:"world" } | ||
}) | ||
.sheet({ | ||
_deep_sheet_:true, | ||
"dq::./test":deep.compose.nodes.sheet({ "dq.up::./hello":"deepjs" }) | ||
}) | ||
.equal({ | ||
test:{ hello:"deepjs" } | ||
}); | ||
test: { | ||
hello: "world" | ||
} | ||
}) | ||
.sheet({ | ||
_deep_sheet_: true, | ||
"dq::./test": deep.compose.nodes.sheet({ | ||
"dq.up::./hello": "deepjs" | ||
}) | ||
}) | ||
.equal({ | ||
test: { | ||
hello: "deepjs" | ||
} | ||
}); | ||
}, | ||
sheeter_chain:function(){ | ||
sheeter_chain: function() { | ||
return deep.nodes({ | ||
test:{ hello:"world" } | ||
}) | ||
.sheet({ | ||
_deep_sheet_:true, | ||
"dq::./test":deep.compose.nodes.bottom({ bloup:"deepjs" }).up({ lolipop:true }) | ||
}) | ||
.equal({ | ||
test:{ bloup:"deepjs", hello:"world", lolipop:true } | ||
}); | ||
test: { | ||
hello: "world" | ||
} | ||
}) | ||
.sheet({ | ||
_deep_sheet_: true, | ||
"dq::./test": deep.compose.nodes.bottom({ | ||
bloup: "deepjs" | ||
}).up({ | ||
lolipop: true | ||
}) | ||
}) | ||
.equal({ | ||
test: { | ||
bloup: "deepjs", | ||
hello: "world", | ||
lolipop: true | ||
} | ||
}); | ||
}, | ||
sheeter_map:function(){ | ||
sheeter_map: function() { | ||
return deep.nodes({ | ||
test:{ hello:"world" } | ||
}) | ||
.sheet({ | ||
_deep_sheet_:true, | ||
"dq::./test":deep.compose.nodes.map(function(node){ | ||
// console.log("node : ", node) | ||
node.value.bloup = true; | ||
return node.value; | ||
test: { | ||
hello: "world" | ||
} | ||
}) | ||
}) | ||
.equal({ | ||
test:{ hello:"world", bloup:true } | ||
}); | ||
.sheet({ | ||
_deep_sheet_: true, | ||
"dq::./test": deep.compose.nodes.map(function(node) { | ||
// console.log("node : ", node) | ||
node.value.bloup = true; | ||
return node.value; | ||
}) | ||
}) | ||
.equal({ | ||
test: { | ||
hello: "world", | ||
bloup: true | ||
} | ||
}); | ||
}, | ||
sheeter_flatten:function(){ | ||
sheeter_flatten: function() { | ||
return deep.nodes({ | ||
_backgrounds:[{ bloup:true }], | ||
test:{ hello:"world" } | ||
}) | ||
.sheet({ | ||
_deep_sheet_:true, | ||
"dq::./!":deep.compose.nodes.flatten() | ||
}) | ||
.equal({ | ||
bloup:true, | ||
test:{ hello:"world" } | ||
}); | ||
_backgrounds: [{ | ||
bloup: true | ||
}], | ||
test: { | ||
hello: "world" | ||
} | ||
}) | ||
.sheet({ | ||
_deep_sheet_: true, | ||
"dq::./!": deep.compose.nodes.flatten() | ||
}) | ||
.equal({ | ||
bloup: true, | ||
test: { | ||
hello: "world" | ||
} | ||
}); | ||
}, | ||
sheeter_interpret:function(){ | ||
sheeter_interpret: function() { | ||
return deep.nodes({ | ||
test:"hello { name }" | ||
}) | ||
.sheet({ | ||
_deep_sheet_:true, | ||
"dq::./test":deep.compose.nodes.interpret({ name:"John" }) | ||
}) | ||
.equal({ | ||
test:"hello John" | ||
}); | ||
test: "hello { name }" | ||
}) | ||
.sheet({ | ||
_deep_sheet_: true, | ||
"dq::./test": deep.compose.nodes.interpret({ | ||
name: "John" | ||
}) | ||
}) | ||
.equal({ | ||
test: "hello John" | ||
}); | ||
}, | ||
sheeter_after:function(){ | ||
sheeter_after: function() { | ||
return deep.nodes({ | ||
test:"hello" | ||
}) | ||
.sheet({ | ||
_deep_sheet_:true, | ||
"dq::./!":deep.compose.nodes.each(function(entry, options){ | ||
entry.value.bloup = true; | ||
test: "hello" | ||
}) | ||
}) | ||
.equal({ | ||
test:"hello", | ||
bloup:true | ||
}); | ||
.sheet({ | ||
_deep_sheet_: true, | ||
"dq::./!": deep.compose.nodes.each(function(entry, options) { | ||
entry.value.bloup = true; | ||
}) | ||
}) | ||
.equal({ | ||
test: "hello", | ||
bloup: true | ||
}); | ||
}, | ||
sheeter_after_before:function(){ | ||
sheeter_after_before: function() { | ||
return deep.nodes({ | ||
test:"hello" | ||
}) | ||
.sheet({ | ||
_deep_sheet_:true, | ||
"dq::./!":deep.compose.nodes.after(function(entry, options){ | ||
entry.value.bloup = true; | ||
}).before(function(entry, options){ | ||
entry.value.lolipop = true; | ||
test: "hello" | ||
}) | ||
}) | ||
.equal({ | ||
test:"hello", | ||
lolipop:true, | ||
bloup:true | ||
}); | ||
.sheet({ | ||
_deep_sheet_: true, | ||
"dq::./!": deep.compose.nodes.after(function(entry, options) { | ||
entry.value.bloup = true; | ||
}).before(function(entry, options) { | ||
entry.value.lolipop = true; | ||
}) | ||
}) | ||
.equal({ | ||
test: "hello", | ||
lolipop: true, | ||
bloup: true | ||
}); | ||
}, | ||
sheeter_after_before_around:function(){ | ||
sheeter_after_before_around: function() { | ||
return deep.nodes({ | ||
test:"hello" | ||
}) | ||
.sheet({ | ||
_deep_sheet_:true, | ||
"dq::./!":deep.compose.nodes.after(function(entry, options){ | ||
entry.value.bloup = true; | ||
}).before(function(entry, options){ | ||
entry.value.lolipop = true; | ||
test: "hello" | ||
}) | ||
.around(function(old){ | ||
return function(entry, options){ | ||
entry.value.blap = true; | ||
old.call(this, entry, options); | ||
entry.value.ploutch = true; | ||
} | ||
.sheet({ | ||
_deep_sheet_: true, | ||
"dq::./!": deep.compose.nodes.after(function(entry, options) { | ||
entry.value.bloup = true; | ||
}).before(function(entry, options) { | ||
entry.value.lolipop = true; | ||
}) | ||
.around(function(old) { | ||
return function(entry, options) { | ||
entry.value.blap = true; | ||
old.call(this, entry, options); | ||
entry.value.ploutch = true; | ||
} | ||
}) | ||
}) | ||
}) | ||
.equal({ | ||
test:"hello", | ||
blap:true, | ||
lolipop:true, | ||
bloup:true, | ||
ploutch:true | ||
}); | ||
.equal({ | ||
test: "hello", | ||
blap: true, | ||
lolipop: true, | ||
bloup: true, | ||
ploutch: true | ||
}); | ||
}, | ||
sheeter_merge:function(){ | ||
sheeter_merge: function() { | ||
var sheet = deep.bottom({ | ||
_deep_sheet_:true, | ||
"dq::./!":deep.compose.nodes.after(function(entry, options){ | ||
_deep_sheet_: true, | ||
"dq::./!": deep.compose.nodes.after(function(entry, options) { | ||
entry.value.bloup = true; | ||
}) | ||
},{ | ||
_deep_sheet_:true, | ||
"dq::./!":deep.compose.nodes.before(function(entry, options){ | ||
}, { | ||
_deep_sheet_: true, | ||
"dq::./!": deep.compose.nodes.before(function(entry, options) { | ||
entry.value.lolipop = true; | ||
}) | ||
},{ | ||
_deep_sheet_:true, | ||
"dq::./!":deep.compose.nodes.around(function(old){ | ||
return function(entry, options){ | ||
}, { | ||
_deep_sheet_: true, | ||
"dq::./!": deep.compose.nodes.around(function(old) { | ||
return function(entry, options) { | ||
entry.value.blap = true; | ||
@@ -406,19 +430,17 @@ old.call(this, entry, options); | ||
return deep.nodes({ | ||
test:"hello" | ||
}) | ||
.sheet(sheet) | ||
.equal({ | ||
test:"hello", | ||
blap:true, | ||
lolipop:true, | ||
bloup:true, | ||
ploutch:true | ||
}); | ||
test: "hello" | ||
}) | ||
.sheet(sheet) | ||
.equal({ | ||
test: "hello", | ||
blap: true, | ||
lolipop: true, | ||
bloup: true, | ||
ploutch: true | ||
}); | ||
} | ||
} | ||
}; | ||
} | ||
}; | ||
return unit; | ||
}); | ||
return unit; | ||
}); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
AI-detected potential security risk
Supply chain riskAI has determined that this package may contain potential security issues or vulnerabilities.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
734926
15922
117
3
16