@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.
- package/dist/CarbonReact.d.ts +3 -1
- package/dist/index.cjs.js +10 -4
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +10 -4
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/CarbonReact.tsx +14 -5
package/dist/CarbonReact.d.ts
CHANGED
|
@@ -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
|
-
|
|
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);
|