-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathexample.js
More file actions
99 lines (82 loc) · 2.08 KB
/
example.js
File metadata and controls
99 lines (82 loc) · 2.08 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
var evtCmd = require('../')();
evtCmd.defineCommand({
id: 'id', // optional
name: 'name', // optional
context: 'context.name', // optional
aggregate: 'aggregate.name', // optional
aggregateId: 'aggregate.id' // optional
});
evtCmd.defineEvent({
correlationId: 'correlationId', // optional
id: 'id', // optional
name: 'name', // optional
context: 'context.name', // optional
aggregate: 'aggregate.name', // optional
aggregateId: 'aggregate.id' // optional
});
evtCmd.idGenerator(function(callback) {
setTimeout(function() {
var id = require('uuid').v4().toString();
callback(null, id);
}, 50);
});
evtCmd.idGenerator(function() {
var id = require('uuid').v4().toString();
return id;
});
evtCmd.on('command', function(cmd) {
if (cmd.name === 'multi') {
evtCmd.emit('event', {name: 'event1', correlationId: cmd.id});
evtCmd.emit('event', {name: 'event2', correlationId: cmd.id});
return;
}
cmd.correlationId = cmd.id;
delete cmd.id;
evtCmd.emit('event', cmd);
});
(new evtCmd.Command({
// id: '12345',
name: 'bla'
})).emit(function(evt) {
console.log(evt);
});
(new evtCmd.Command({
name: 'multi'
})).emit({
event1: function(evt) {
console.log(evt);
},
event2: function(evt) {
console.log(evt);
}
});
setTimeout(function() {
console.log('-------------------');
evtCmd.send('command')
.for('aggregate')
.instance('instanceId')
.in('context')
.with({
revision: '12',
payload: 'data'
})
.go(function(evt) {
console.log('speakable', evt);
});
evtCmd.send('multi')
.for('aggregate')
.instance('instanceId')
.in('context')
.with({
revision: '43',
payload: 'data2'
})
.go({
event1: function(evt) {
console.log('speakable', evt);
},
event2: function(evt) {
console.log('speakable', evt);
}
});
}, 500);