Skip to content

Commit

Permalink
put rule params in Array so rules are always binary functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan Paluch authored and Bryan Paluch committed Apr 3, 2013
1 parent 3525bd2 commit 7f1bbb0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
9 changes: 6 additions & 3 deletions examples/async.js
Expand Up @@ -3,11 +3,14 @@ var FnCatalog = require('../index').FnCatalog;

var catalog = new FnCatalog();

var switchRelay = function(word){console.log('Switching on Relay because the temp is ' + word);
return word};
var switchRelay = function(word){console.log('Switching on Relay because the temp is ' + word[0]);
return word[0]};
catalog.addFn(switchRelay, 'switchRelay', this);

var getOtherSensorByUserId = function(userid, timeout,cb){
var getOtherSensorByUserId = function(argArray,cb){
var userid = argArray[0];
var timeout = argArray[1];

console.log("Get other relay value running for user:", userid, "with timeout: ", timeout);
setTimeout(function(){
if(userid === '1234')
Expand Down
6 changes: 3 additions & 3 deletions libs/JsonRules.js
Expand Up @@ -138,11 +138,11 @@ JsonRules.prototype.getWrappedCatalogFn = function(catalog, values){
return null;
});
return (function(cb){
appliedArgs.push(cb);
return fn.apply(this,appliedArgs)});
console.log(appliedArgs);
return fn.apply(this,[appliedArgs, cb])});
}
else
return (function(cb){return fn.apply(this, [cb])});
return (function(cb){return fn.apply(this, [null, cb])});
}else{
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "jsonrules",
"version": "0.0.5",
"version": "0.0.6",
"description": "A rule engine with pure json based syntax and function catalog",
"main": "index.js",
"scripts": {
Expand Down
4 changes: 3 additions & 1 deletion tests/2.jsonRules.js
Expand Up @@ -80,7 +80,9 @@ var badFormatIfs =
test: '=='
};

var getOtherSensorByUserId = function(userid, timeout,cb){
var getOtherSensorByUserId = function(argArray,cb){
var userid = argArray[0];
var timeout = argArray[1];
setTimeout(function(){
if(userid === '1234')
cb(null, 1);
Expand Down

0 comments on commit 7f1bbb0

Please sign in to comment.