aboutsummaryrefslogtreecommitdiff
path: root/src/client/util/SelectionManager.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/util/SelectionManager.ts')
-rw-r--r--src/client/util/SelectionManager.ts7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/client/util/SelectionManager.ts b/src/client/util/SelectionManager.ts
index 4612f10f4..6c386d684 100644
--- a/src/client/util/SelectionManager.ts
+++ b/src/client/util/SelectionManager.ts
@@ -55,10 +55,13 @@ export namespace SelectionManager {
manager.SelectDoc(docView, ctrlPressed);
}
+ // computed functions, such as used in IsSelected generate errors if they're called outside of a
+ // reaction context. Specifying the context with 'outsideReaction' allows an efficiency feature
+ // to avoid unnecessary mobx invalidations when running inside a reaction.
export function IsSelected(doc: DocumentView, outsideReaction?: boolean): boolean {
return outsideReaction ?
- manager.SelectedDocuments.get(doc) ? true : false :
- computedFn(function isSelected(doc: DocumentView) {
+ manager.SelectedDocuments.get(doc) ? true : false : // get() accesses a hashtable -- setting anything in the hashtable generates a mobx invalidation for every get()
+ computedFn(function isSelected(doc: DocumentView) { // wraapping get() in a computedFn only generates mobx() invalidations when the return value of the function for the specific get parameters has changed
return manager.SelectedDocuments.get(doc) ? true : false;
})(doc);
}