1 | var RuleEngine = require('../index');
|
2 | /* Sample Rule to block a transaction if its below 500 */
|
3 | var 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 */
|
13 | var R = new RuleEngine();
|
14 | R.register(rule);
|
15 | /* some val is 0 here, rules will recursively run till it becomes 10.
|
16 | This just a mock to demo the restart feature. */
|
17 | var fact = {
|
18 | "someval": 0
|
19 | };
|
20 | R.execute(fact, function(data) {
|
21 | console.log("Finished with value", data.someval);
|
22 | }); |
\ | No newline at end of file |