Skip to content

Commit

Permalink
Tighten/simplify implementation of HoistModel.componentProps (#3883)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
lbwexler authored Dec 31, 2024
1 parent dfe56fd commit 9ebd5a4
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions core/model/HoistModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit 9ebd5a4

Please sign in to comment.