-
Notifications
You must be signed in to change notification settings - Fork 3
/
registration.js
29 lines (24 loc) · 1.02 KB
/
registration.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
function apply(entries, asyncObjects, relations) {
asyncObjects.getAll().forEach(asyncObj => {
let parentObject = findAsyncObjectWhereRegistered(asyncObjects, asyncObj);
if (parentObject)
relations.add(parentObject.id, asyncObj.id, 'registration');
});
}
function findAsyncObjectWhereRegistered(asyncObjects, asyncObj) {
let triggers = asyncObjects.getByAsyncId(asyncObj.entry.trigger);
//For this specific case, current should be used.
if (asyncObj.entry.trigger !== asyncObj.entry.current && asyncObj.entry.type === 'TickObject') {
triggers = asyncObjects.getByAsyncId(asyncObj.entry.current);
}
if (triggers.length === 0)
return null;
//select the closest
for (let i = 0; i < triggers.length - 1; i++) {
if (asyncObj.entry.logindex > triggers[i].beforeindex
&& asyncObj.entry.logindex < triggers[i + 1].beforeindex)
return triggers[i];
}
return triggers[triggers.length - 1];
}
module.exports = { apply }