-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.js
24 lines (22 loc) · 998 Bytes
/
settings.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
export class Settings {
static functions = new Map();
/**
* listen to specific document update change
* @param {*} binder - { coll: string, name (uniqueFieldOfDocument): string }
* @param {*} callback - function that receives the following params: (fullDocument, updatedFields)
*/
static on(binder, callback) {
Settings.functions.set(`${JSON.stringify(binder)}`, callback);
}
static execute({ operationType, fullDocument, updateDescription, ns }) {
const key = JSON.stringify({ coll: ns.coll, name: fullDocument.name });
console.log('executed, settingsFunctionLength:', Settings.functions.entries())
// can add special actions according to operationType
if (operationType === 'update') {
const callback = Settings.functions.get(key);
if (callback) callback(fullDocument, updateDescription.updatedFields);
} else if (operationType === 'insert') {
return;
}
}
}