@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/package.json
CHANGED
package/src/CarbonReact.tsx
CHANGED
|
@@ -56,14 +56,23 @@ abstract class CarbonReact<P = {}, S extends { [key: string]: any; } = typeof in
|
|
|
56
56
|
|
|
57
57
|
private static persistentStateMap = new Map<string, { [key: string]: any; }>();
|
|
58
58
|
|
|
59
|
+
// Context is for functional components to access the state of this class efficiently
|
|
59
60
|
context: Context<S> = createContext(this.state);
|
|
60
61
|
|
|
61
|
-
// Private static member
|
|
62
|
-
// we actually implement this in the constructor todo - test this
|
|
63
|
-
protected static instance: CarbonReact;
|
|
64
|
-
|
|
65
62
|
protected target: typeof CarbonReact;
|
|
66
63
|
|
|
64
|
+
protected static _instance: CarbonReact;
|
|
65
|
+
|
|
66
|
+
static get instance() {
|
|
67
|
+
// Here `this` refers to the calling class in static context
|
|
68
|
+
return this._instance;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static set instance(instance: CarbonReact) {
|
|
72
|
+
this._instance = instance;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
|
|
67
76
|
protected updateRestfulObjectArrays = <ObjectType extends { [key: string]: any; } = {}>
|
|
68
77
|
(rest: Omit<iUpdateRestfulObjectArrays<ObjectType, S, P>, "instance">) => updateRestfulObjectArrays<ObjectType, S, P>({
|
|
69
78
|
instance: this,
|
|
@@ -98,7 +107,7 @@ abstract class CarbonReact<P = {}, S extends { [key: string]: any; } = typeof in
|
|
|
98
107
|
// this is the magic that allows each class that's extends this to have a static instance - a singleton pattern
|
|
99
108
|
// new.target is a meta-property introduced in ES6 that references the constructor that was directly invoked with the new keyword.
|
|
100
109
|
Object.assign(new.target, {
|
|
101
|
-
|
|
110
|
+
_instance: this
|
|
102
111
|
})
|
|
103
112
|
|
|
104
113
|
if (this.props.instanceId && CarbonReact.persistentStateMap.has(this.props.instanceId)) {
|