This repository has been archived by the owner on Jun 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
runat-1128988: Add event batching to commands-changed
We don't want to light up the remote interface 10x for every module, so this adds holdFire/resumeFire to addItemsByModule and friends. Signed-off-by: Joe Walker <[email protected]>
- Loading branch information
Showing
1 changed file
with
25 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,7 +149,14 @@ exports.createSystem = function(options) { | |
}, | ||
|
||
addItemsByModule: function(names, options) { | ||
var promises = []; | ||
|
||
options = options || {}; | ||
if (!options.delayedLoad) { | ||
// We could be about to add many commands, just report the change once | ||
this.commands.onCommandsChange.holdFire(); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
joewalker
Author
Owner
|
||
} | ||
|
||
if (typeof names === 'string') { | ||
names = [ names ]; | ||
} | ||
|
@@ -165,20 +172,34 @@ exports.createSystem = function(options) { | |
pendingChanges = true; | ||
} | ||
else { | ||
loadModule(name).catch(console.error); | ||
promises.push(loadModule(name).catch(console.error)); | ||
} | ||
}); | ||
|
||
if (options.delayedLoad) { | ||
return Promise.resolve(); | ||
} | ||
else { | ||
return Promise.all(promises).then(function() { | ||
this.commands.onCommandsChange.resumeFire(); | ||
}.bind(this)); | ||
} | ||
}, | ||
|
||
removeItemsByModule: function(name) { | ||
this.commands.onCommandsChange.holdFire(); | ||
|
||
delete loadableModules[name]; | ||
unloadModule(name); | ||
|
||
this.commands.onCommandsChange.resumeFire(); | ||
}, | ||
|
||
load: function() { | ||
if (!pendingChanges) { | ||
return Promise.resolve(); | ||
} | ||
this.commands.onCommandsChange.holdFire(); | ||
|
||
// clone loadedModules, so we can remove what is left at the end | ||
var modules = Object.keys(loadedModules).map(function(name) { | ||
|
@@ -193,7 +214,9 @@ exports.createSystem = function(options) { | |
Object.keys(modules).forEach(unloadModule); | ||
pendingChanges = false; | ||
|
||
return Promise.all(promises); | ||
return Promise.all(promises).then(function() { | ||
this.commands.onCommandsChange.resumeFire(); | ||
}.bind(this)); | ||
}, | ||
|
||
toString: function() { | ||
|
Just curious, where does the command actually get added? Searching for commands.add doesn't turn up much: https://github.com/joewalker/gcli/search?utf8=%E2%9C%93&q=%22commands.add%22&type=Code