aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/collections/CollectionView.tsx
diff options
context:
space:
mode:
authorsrichman333 <sarah_n_richman@brown.edu>2023-11-06 18:36:58 -0500
committersrichman333 <sarah_n_richman@brown.edu>2023-11-06 18:36:58 -0500
commit1b412d402c77a2aae82cf86b1f6a23f8a4f82caf (patch)
tree7ebd22eeade12099d1d891d9f9b264f02956ad4a /src/client/views/collections/CollectionView.tsx
parent7163062edec37cef9dd9ae6c123d987e83837463 (diff)
parenta4e3b645317c4589cf49f8007f6e6b57cf2c12d3 (diff)
Merge branch 'master' into dataViz-annotations
Diffstat (limited to 'src/client/views/collections/CollectionView.tsx')
-rw-r--r--src/client/views/collections/CollectionView.tsx22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/client/views/collections/CollectionView.tsx b/src/client/views/collections/CollectionView.tsx
index ce19b3f9b..c2062e8ab 100644
--- a/src/client/views/collections/CollectionView.tsx
+++ b/src/client/views/collections/CollectionView.tsx
@@ -1,4 +1,4 @@
-import { computed, observable, runInAction } from 'mobx';
+import { IReactionDisposer, observable, reaction, runInAction } from 'mobx';
import { observer } from 'mobx-react';
import * as React from 'react';
import { Doc, DocListCast, Opt } from '../../../fields/Doc';
@@ -41,7 +41,6 @@ interface CollectionViewProps_ extends FieldViewProps {
isAnnotationOverlayScrollable?: boolean; // whether the annotation overlay can be vertically scrolled (just for tree views, currently)
layoutEngine?: () => string;
setPreviewCursor?: (func: (x: number, y: number, drag: boolean, hide: boolean, doc: Opt<Doc>) => void) => void;
- setBrushViewer?: (func?: (view: { width: number; height: number; panX: number; panY: number }, transTime: number) => void) => void;
ignoreUnrendered?: boolean;
// property overrides for child documents
@@ -79,6 +78,8 @@ export class CollectionView extends ViewBoxAnnotatableComponent<ViewBoxAnnotatab
public static SetSafeMode(safeMode: boolean) {
this._safeMode = safeMode;
}
+ private reactionDisposer: IReactionDisposer | undefined;
+ @observable _isContentActive: boolean | undefined;
protected _multiTouchDisposer?: InteractionUtils.MultiTouchEventDisposer;
@@ -87,6 +88,21 @@ export class CollectionView extends ViewBoxAnnotatableComponent<ViewBoxAnnotatab
runInAction(() => (this._annotationKeySuffix = returnEmptyString));
}
+ componentDidMount() {
+ // we use a reaction/observable instead of a computed value to reduce invalidations.
+ // There are many variables that aggregate into this boolean output - a change in any of them
+ // will cause downstream invalidations even if the computed value doesn't change. By making
+ // this a reaction, downstream invalidations only occur when the reaction value actually changes.
+ this.reactionDisposer = reaction(
+ () => (this.isAnyChildContentActive() ? true : this.props.isContentActive()),
+ active => (this._isContentActive = active),
+ { fireImmediately: true }
+ );
+ }
+ componentWillUnmount() {
+ this.reactionDisposer?.();
+ }
+
get collectionViewType(): CollectionViewType | undefined {
const viewField = StrCast(this.layoutDoc._type_collection);
if (CollectionView._safeMode) {
@@ -221,7 +237,7 @@ export class CollectionView extends ViewBoxAnnotatableComponent<ViewBoxAnnotatab
childHideResizeHandles = () => this.props.childHideResizeHandles?.() ?? BoolCast(this.Document.childHideResizeHandles);
childHideDecorationTitle = () => this.props.childHideDecorationTitle?.() ?? BoolCast(this.Document.childHideDecorationTitle);
childLayoutTemplate = () => this.props.childLayoutTemplate?.() || Cast(this.rootDoc.childLayoutTemplate, Doc, null);
- isContentActive = (outsideReaction?: boolean) => (this.isAnyChildContentActive() ? true : this.props.isContentActive());
+ isContentActive = (outsideReaction?: boolean) => this._isContentActive;
render() {
TraceMobx();