Comparing version 2.0.0-beta3 to 2.0.0-beta4
{ | ||
"name": "clues", | ||
"version": "2.0.0-beta3", | ||
"version": "2.0.0-beta4", | ||
"main": "clues.js", | ||
@@ -5,0 +5,0 @@ "scripts": [ |
@@ -38,2 +38,3 @@ // clues.js (c) 2009-2014 Ziggy.jonsson.nyc@gmail.com @license MIT | ||
var self = this, ref; | ||
local = local || {}; | ||
@@ -48,4 +49,4 @@ if (typeof fn !== "function") { | ||
if (self.logic[ref] === undefined) { | ||
if (local && local[ref] !== undefined) return self.Promise.fulfilled(local[ref]); | ||
else if (self[ref] !== undefined) return self.Promise.fulfilled(self[ref]); | ||
if (local[ref] !== undefined) return self.Promise.fulfilled(local[ref]); | ||
else if (self[ref] !== undefined && typeof self[ref] !== 'function') return self.Promise.fulfilled(self[ref]); | ||
else if (ref === 'local') return self.Promise.fulfilled(local); | ||
@@ -91,4 +92,4 @@ else return self.Promise.rejected({ref: ref, caller: caller, message: ref+' not defined', name: 'Undefined'}); | ||
clues.prototype.solver = function(d,e) { | ||
return this.solve.bind(this,d,e); | ||
clues.prototype.solver = function(d,e,f) { | ||
return this.solve.bind(this,d,e,f); | ||
}; | ||
@@ -95,0 +96,0 @@ |
{ | ||
"name": "clues", | ||
"version": "2.0.0-beta3", | ||
"version": "2.0.0-beta4", | ||
"description": "Lightweight logic tree solver using promises.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -44,4 +44,6 @@ ##Breaking changes in version 2.0: | ||
Properties of the clues object can be injected into the function arguments when referenced by name. Those include: `self`, `Promise`, `solve`, `solver`, `fork`, `local` and are all linked to the specific `clues`-object being used. This properties are also available through the `this` context supplied to the logic function. | ||
Properties of the clues object (except functions) can be injected into the function arguments when referenced by name. Those include: `self`, `facts`, `logic`. Additionaly the `local` keyword can be injected to get any local variables submitted, or the local variable can be injected by name (if defined in the local object). Function of the clues object can be accessed through top level `this` or the injected `self` which retains the right reference inside nested function. For example, `self.solve`, `self.solver` and `self.fork` provide functionality linked to the respective clues object that called the function. Finally the Promise adaptor can be referenced through `self.Promise`. | ||
This properties are also available through the `this` context supplied to the logic function. | ||
##### Local Variables | ||
@@ -135,4 +137,6 @@ The second argument (optional) allows local variables that will be used, and have priority, against facts and logic. The is to provide the flexibility to have functions respond to request specific variables, such as a response stream or to override any previously determined facts. Please note however, that locals should really be used at end-points in logic, to ensure that locals do not contaminate derived facts. | ||
## Hints and tips | ||
* Check the test folder for examples | ||
* Check the test folder for usage examples | ||
* Helper modules are provided in the util directory. Use `app.use(require('clues/util/express-clues'))(api)` to provide access to clues through an express route. | ||
* By defining logic object as the `Window` object, all global functions and variables are made available. | ||
@@ -139,0 +143,0 @@ |
@@ -8,22 +8,22 @@ var clues = require("../clues"), | ||
var logic = { | ||
M1 : function(Promise) { | ||
return Promise | ||
M1 : function() { | ||
return this.Promise | ||
.delay(10,130) | ||
.cancellable() | ||
.catch(Promise.CancellationError,function() { | ||
.catch(this.Promise.CancellationError,function() { | ||
cancel.M1 = true; | ||
}); | ||
}, | ||
M2 : function(Promise) { | ||
return Promise | ||
M2 : function() { | ||
return this.Promise | ||
.delay(50,170) | ||
.cancellable() | ||
.catch(Promise.CancellationError,function() { | ||
.catch(this.Promise.CancellationError,function() { | ||
cancel.M2 = true; | ||
}); | ||
}, | ||
M3 : function(Promise) { | ||
return Promise | ||
M3 : function() { | ||
return this.Promise | ||
.delay(10,10) | ||
.catch(Promise.CancellationError,function() { | ||
.catch(this.Promise.CancellationError,function() { | ||
cancel.M3 = true; | ||
@@ -30,0 +30,0 @@ }); |
@@ -7,6 +7,6 @@ var clues = require("../clues"), | ||
var logic = { | ||
M1 : function(Promise) { return Promise.delay(10,100); }, | ||
M2 : function(Promise) { return Promise.delay(300,20); }, | ||
M1 : function() { return this.Promise.delay(10,100); }, | ||
M2 : function() { return this.Promise.delay(300,20); }, | ||
M3 : function(M1,M2) { return M1+M2; }, | ||
M4 : function(Promise) { return Promise.delay(70,150); }, | ||
M4 : function() { return this.Promise.delay(70,150); }, | ||
MTOP : function(M3,M4) { return M3+M4; } | ||
@@ -13,0 +13,0 @@ }; |
@@ -21,8 +21,2 @@ var clues = require("../clues"), | ||
it('should inject solve',function() { | ||
return c.solve(function(a,solve) { | ||
assert.deepEqual(solve,c.solve); | ||
}); | ||
}); | ||
it('should inject local',function() { | ||
@@ -29,0 +23,0 @@ var local = {a: 1, b: 2}; |
@@ -6,3 +6,3 @@ var clues = require("../clues"), | ||
var c = clues({ | ||
response : function(Promise) { return Promise.delay(42,500);}, | ||
response : function() { return this.Promise.delay(42,500);}, | ||
other : function() { return 5; } | ||
@@ -9,0 +9,0 @@ }); |
@@ -7,3 +7,3 @@ var clues = require("../clues"), | ||
var logic = { | ||
A : function(Promise) { return Promise.delay(42,500);}, | ||
A : function() { return this.Promise.delay(42,500);}, | ||
B : 10, | ||
@@ -10,0 +10,0 @@ C : function(A,B) { return A + B; } |
@@ -8,3 +8,3 @@ var clues = require("../clues"), | ||
var logic = { | ||
data : function(Promise) { return Promise.delay(5,1000); }, | ||
data : function() { return this.Promise.delay(5,1000); }, | ||
passthrough : function(_optional) { return _optional; }, | ||
@@ -11,0 +11,0 @@ internalize : function(data,_optional) { return data + (_optional || 2); }, |
@@ -21,5 +21,6 @@ var clues = require("../clues"), | ||
if('should work when injected',function() { | ||
return c.solve(function(B,solver) { | ||
return solver('A'); | ||
it('should work with injected self',function() { | ||
return c.solve(function(B,self) { | ||
return this.Promise.rejected(true) | ||
.then(null,self.solver('A')); | ||
}) | ||
@@ -26,0 +27,0 @@ .then(function(d) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31009
17
507
147