@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/index.esm.js
CHANGED
|
@@ -4359,11 +4359,17 @@ function isJsonString(str) {
|
|
|
4359
4359
|
}
|
|
4360
4360
|
class CarbonReact extends Component {
|
|
4361
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,7 +4389,7 @@ 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
|
-
|
|
4392
|
+
_instance: this
|
|
4387
4393
|
});
|
|
4388
4394
|
if (this.props.instanceId && CarbonReact.persistentStateMap.has(this.props.instanceId)) {
|
|
4389
4395
|
this.state = CarbonReact.persistentStateMap.get(this.props.instanceId);
|