@carbonorm/carbonreact 4.0.1 → 4.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -4357,13 +4357,19 @@ function isJsonString(str) {
4357
4357
  }
4358
4358
  return true;
4359
4359
  }
4360
- const persistentStateMap = new Map();
4361
4360
  class CarbonReact extends Component {
4361
+ static persistentStateMap = new Map();
4362
+ // Context is for functional components to access the state of this class efficiently
4362
4363
  context = createContext(this.state);
4363
- // Private static member
4364
- // we actually implement this in the constructor todo - test this
4365
- static instance;
4366
4364
  target;
4365
+ static _instance;
4366
+ static get instance() {
4367
+ // Here `this` refers to the calling class in static context
4368
+ return this._instance;
4369
+ }
4370
+ static set instance(instance) {
4371
+ this._instance = instance;
4372
+ }
4367
4373
  updateRestfulObjectArrays = (rest) => updateRestfulObjectArrays({
4368
4374
  instance: this,
4369
4375
  ...rest
@@ -4383,10 +4389,10 @@ class CarbonReact extends Component {
4383
4389
  // this is the magic that allows each class that's extends this to have a static instance - a singleton pattern
4384
4390
  // new.target is a meta-property introduced in ES6 that references the constructor that was directly invoked with the new keyword.
4385
4391
  Object.assign(new.target, {
4386
- instance: this
4392
+ _instance: this
4387
4393
  });
4388
- if (this.props.instanceId && persistentStateMap.has(this.props.instanceId)) {
4389
- this.state = persistentStateMap.get(this.props.instanceId);
4394
+ if (this.props.instanceId && CarbonReact.persistentStateMap.has(this.props.instanceId)) {
4395
+ this.state = CarbonReact.persistentStateMap.get(this.props.instanceId);
4390
4396
  }
4391
4397
  else {
4392
4398
  // This should only ever be done here, when the full state is being trashed.
@@ -4405,7 +4411,7 @@ class CarbonReact extends Component {
4405
4411
  }
4406
4412
  shouldComponentUpdate(nextProps, nextState, _nextContext) {
4407
4413
  if (this.props.instanceId) {
4408
- persistentStateMap.set(this.props.instanceId, nextState);
4414
+ CarbonReact.persistentStateMap.set(this.props.instanceId, nextState);
4409
4415
  }
4410
4416
  changed(this.constructor.name + ' (C6Api)', 'props', this.props, nextProps);
4411
4417
  changed(this.constructor.name + ' (C6Api)', 'state', this.state, nextState);