From 9ebd5a40668e5dd23e83277f5ad1a5c219146811 Mon Sep 17 00:00:00 2001 From: Lee Wexler Date: Tue, 31 Dec 2024 14:19:37 -0500 Subject: [PATCH] Tighten/simplify implementation of HoistModel.componentProps (#3883) - Fix difficult bug with re-render loops. - Avoid mobx object/proxy object creation for models that don't use this property - Avoid extra prop processing for linked models that don't use this property --- core/model/HoistModel.ts | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/core/model/HoistModel.ts b/core/model/HoistModel.ts index 538730216..bd076e23b 100644 --- a/core/model/HoistModel.ts +++ b/core/model/HoistModel.ts @@ -4,9 +4,9 @@ * * Copyright © 2025 Extremely Heavy Industries Inc. */ -import {action, makeObservable, observable} from '@xh/hoist/mobx'; +import {action, computed, comparer, makeObservable, observable} from '@xh/hoist/mobx'; import {warnIf} from '@xh/hoist/utils/js'; -import {forOwn, has, isFunction} from 'lodash'; +import {isFunction} from 'lodash'; import {DefaultHoistProps, HoistBase, LoadSpecConfig, managed, PlainObject} from '../'; import {instanceManager} from '../impl/InstanceManager'; import {Loadable, LoadSpec, LoadSupport} from '../load'; @@ -67,8 +67,7 @@ export abstract class HoistModel extends HoistBase implements Loadable { } // Internal State - @observable - _componentProps = {}; + @observable.ref _componentProps = null; _modelLookup = null; _created = Date.now(); @@ -136,6 +135,7 @@ export abstract class HoistModel extends HoistBase implements Loadable { * Observability is based on a shallow computation for each prop (i.e. a reference * change in any particular prop will trigger observers to be notified). */ + @computed({equals: comparer.shallow}) get componentProps(): DefaultHoistProps { return this._componentProps; } @@ -187,13 +187,7 @@ export abstract class HoistModel extends HoistBase implements Loadable { /** @internal */ @action setComponentProps(newProps) { - const props = this._componentProps; - Object.assign(props, newProps); - forOwn(props, (v, k) => { - if (!has(newProps, k)) { - delete props[k]; - } - }); + this._componentProps = newProps; } /** @internal */