UNPKG

658 BJavaScriptView Raw
1var RuleEngine = require('../index');
2/* Sample Rule to block a transaction if its below 500 */
3var rule = {
4 "condition": function(R) {
5 R.when(this.someval < 10);
6 },
7 "consequence": function(R) {
8 console.log(++this.someval, " : incrementing again till 10");
9 R.restart();
10 }
11};
12/* Creating Rule Engine instance and registering rule */
13var R = new RuleEngine();
14R.register(rule);
15/* some val is 0 here, rules will recursively run till it becomes 10.
16This just a mock to demo the restart feature. */
17var fact = {
18 "someval": 0
19};
20R.execute(fact, function(data) {
21 console.log("Finished with value", data.someval);
22});
\No newline at end of file