mirror of
https://github.com/TriliumNext/Notes.git
synced 2026-01-29 08:38:30 -06:00
basic executor / command mechanism
This commit is contained in:
@@ -27,20 +27,7 @@ export default class Component {
|
||||
|
||||
const start = Date.now();
|
||||
|
||||
if (typeof fun === 'function') {
|
||||
let release;
|
||||
|
||||
try {
|
||||
release = await this.mutex.acquire();
|
||||
|
||||
await fun.call(this, data);
|
||||
}
|
||||
finally {
|
||||
if (release) {
|
||||
release();
|
||||
}
|
||||
}
|
||||
}
|
||||
await this.callMethod(fun, data);
|
||||
|
||||
const end = Date.now();
|
||||
|
||||
@@ -65,7 +52,33 @@ export default class Component {
|
||||
await Promise.all(promises);
|
||||
}
|
||||
|
||||
triggerCommand(name, data) {
|
||||
async triggerCommand(name, data) {
|
||||
const fun = this[name + 'Command'];
|
||||
|
||||
const called = await this.callMethod(fun, data);
|
||||
|
||||
if (!called) {
|
||||
await this.parent.triggerCommand(name, data);
|
||||
}
|
||||
}
|
||||
|
||||
async callMethod(fun, data) {
|
||||
if (typeof fun !== 'function') {
|
||||
return false;
|
||||
}
|
||||
|
||||
let release;
|
||||
|
||||
try {
|
||||
release = await this.mutex.acquire();
|
||||
|
||||
await fun.call(this, data);
|
||||
|
||||
return true;
|
||||
} finally {
|
||||
if (release) {
|
||||
release();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -616,4 +616,10 @@ export default class NoteTreeWidget extends TabAwareWidget {
|
||||
treeCacheReloadedListener() {
|
||||
this.reloadTreeFromCache();
|
||||
}
|
||||
|
||||
async moveNotesToCommand() {
|
||||
const selectedOrActiveBranchIds = this.getSelectedOrActiveNodes().map(node => node.data.branchId);
|
||||
|
||||
this.triggerCommand('moveBranchIdsTo', {branchIds: selectedOrActiveBranchIds});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user