forked from noolsjs/nools
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathagendaGroup.js
57 lines (51 loc) · 1.33 KB
/
agendaGroup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var nools = require("../");
function Message(name) {
this.name = name;
}
var flow = nools.flow("agenda-group example", function () {
this.rule("Hello World", {agendaGroup: "ag1"}, [Message, "m", "m.name == 'hello'"], function (facts) {
this.assert(new Message("goodbye"));
});
this.rule("Hello World2", {agendaGroup: "ag2"}, [Message, "m", "m.name == 'hello'"], function (facts) {
this.assert(new Message("goodbye"));
});
});
var fired = [], fired2 = [], allFired = [], allfired2 = [];
flow
.getSession(new Message("hello"))
.focus("ag1")
.on("fire", function (ruleName) {
fired.push(ruleName);
})
.match(function () {
console.log(fired);
});
flow
.getSession(new Message("hello"))
.focus("ag2")
.on("fire", function (ruleName) {
fired2.push(ruleName);
})
.match(function () {
console.log(fired2);
});
flow
.getSession(new Message("hello"))
.focus("ag2")
.focus("ag1")
.on("fire", function (ruleName) {
allFired.push(ruleName);
})
.match(function () {
console.log(allFired);
});
flow
.getSession(new Message("hello"))
.focus("ag1")
.focus("ag2")
.on("fire", function (ruleName) {
allfired2.push(ruleName);
})
.match(function () {
console.log(allfired2);
});