@carbonorm/carbonreact 4.0.2 → 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.
@@ -26,8 +26,10 @@ declare abstract class CarbonReact<P = {}, S extends {
26
26
  } & P, S> {
27
27
  private static persistentStateMap;
28
28
  context: Context<S>;
29
- protected static instance: CarbonReact;
30
29
  protected target: typeof CarbonReact;
30
+ protected static _instance: CarbonReact;
31
+ static get instance(): CarbonReact;
32
+ static set instance(instance: CarbonReact);
31
33
  protected updateRestfulObjectArrays: <ObjectType extends {
32
34
  [key: string]: any;
33
35
  } = {}>(rest: Omit<iUpdateRestfulObjectArrays<ObjectType, S, P>, "instance">) => void;
package/dist/index.cjs.js CHANGED
@@ -4361,11 +4361,17 @@ function isJsonString(str) {
4361
4361
  }
4362
4362
  class CarbonReact extends react.Component {
4363
4363
  static persistentStateMap = new Map();
4364
+ // Context is for functional components to access the state of this class efficiently
4364
4365
  context = react.createContext(this.state);
4365
- // Private static member
4366
- // we actually implement this in the constructor todo - test this
4367
- static instance;
4368
4366
  target;
4367
+ static _instance;
4368
+ static get instance() {
4369
+ // Here `this` refers to the calling class in static context
4370
+ return this._instance;
4371
+ }
4372
+ static set instance(instance) {
4373
+ this._instance = instance;
4374
+ }
4369
4375
  updateRestfulObjectArrays = (rest) => updateRestfulObjectArrays({
4370
4376
  instance: this,
4371
4377
  ...rest
@@ -4385,7 +4391,7 @@ class CarbonReact extends react.Component {
4385
4391
  // this is the magic that allows each class that's extends this to have a static instance - a singleton pattern
4386
4392
  // new.target is a meta-property introduced in ES6 that references the constructor that was directly invoked with the new keyword.
4387
4393
  Object.assign(new.target, {
4388
- instance: this
4394
+ _instance: this
4389
4395
  });
4390
4396
  if (this.props.instanceId && CarbonReact.persistentStateMap.has(this.props.instanceId)) {
4391
4397
  this.state = CarbonReact.persistentStateMap.get(this.props.instanceId);