@carbonorm/carbonreact 4.0.11 → 4.0.12
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 +10 -4
- package/dist/index.cjs.js +18 -27
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +18 -27
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/CarbonReact.tsx +41 -68
package/dist/index.esm.js
CHANGED
|
@@ -4359,10 +4359,9 @@ function isJsonString(str) {
|
|
|
4359
4359
|
}
|
|
4360
4360
|
class CarbonReact extends Component {
|
|
4361
4361
|
static persistentStateMap = new Map();
|
|
4362
|
-
|
|
4362
|
+
static activeInstances = new Map();
|
|
4363
4363
|
context = createContext(this.state);
|
|
4364
4364
|
target;
|
|
4365
|
-
// @link https://stackoverflow.com/questions/55029032/what-is-typescripts-thistype-used-for
|
|
4366
4365
|
static _instance;
|
|
4367
4366
|
static getInstance() {
|
|
4368
4367
|
return this._instance;
|
|
@@ -4373,7 +4372,6 @@ class CarbonReact extends Component {
|
|
|
4373
4372
|
static set instance(instance) {
|
|
4374
4373
|
this._instance = instance;
|
|
4375
4374
|
}
|
|
4376
|
-
// these are public but the class is abstract
|
|
4377
4375
|
updateRestfulObjectArrays = (rest) => updateRestfulObjectArrays({
|
|
4378
4376
|
instance: this,
|
|
4379
4377
|
...rest
|
|
@@ -4383,46 +4381,35 @@ class CarbonReact extends Component {
|
|
|
4383
4381
|
...rest
|
|
4384
4382
|
});
|
|
4385
4383
|
static lastLocation = window.location.pathname;
|
|
4386
|
-
// @link https://github.com/welldone-software/why-did-you-render
|
|
4387
|
-
// noinspection JSUnusedGlobalSymbols
|
|
4388
4384
|
static whyDidYouRender = true;
|
|
4389
4385
|
constructor(props) {
|
|
4390
4386
|
super(props);
|
|
4391
|
-
|
|
4392
|
-
|
|
4393
|
-
|
|
4394
|
-
throw new Error(
|
|
4387
|
+
const target = new.target;
|
|
4388
|
+
const identifier = props.instanceId || target.name;
|
|
4389
|
+
if (CarbonReact.activeInstances.has(identifier)) {
|
|
4390
|
+
throw new Error(`Instance with ID ${identifier} already exists! CarbonReact extended classes can only be referenced once in DOM with the same identifier.`);
|
|
4395
4391
|
}
|
|
4396
|
-
|
|
4397
|
-
this.target =
|
|
4392
|
+
CarbonReact.activeInstances.set(identifier, this);
|
|
4393
|
+
this.target = target;
|
|
4398
4394
|
console.log('CarbonORM TSX CONSTRUCTOR');
|
|
4399
|
-
|
|
4400
|
-
// new.target is a meta-property introduced in ES6 that references the constructor that was directly invoked with the new keyword.
|
|
4401
|
-
Object.assign(new.target, {
|
|
4395
|
+
Object.assign(target, {
|
|
4402
4396
|
_instance: this
|
|
4403
4397
|
});
|
|
4404
|
-
if (
|
|
4405
|
-
this.state = CarbonReact.persistentStateMap.get(
|
|
4398
|
+
if (CarbonReact.persistentStateMap.has(identifier)) {
|
|
4399
|
+
this.state = CarbonReact.persistentStateMap.get(identifier);
|
|
4406
4400
|
}
|
|
4407
4401
|
else {
|
|
4408
|
-
// This should only ever be done here, when the full state is being trashed.
|
|
4409
|
-
// todo - does this suck in context of multiple instances?
|
|
4410
4402
|
clearCache({
|
|
4411
4403
|
ignoreWarning: true
|
|
4412
4404
|
});
|
|
4413
4405
|
this.state = initialCarbonReactState;
|
|
4414
4406
|
}
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
* Class based components are far easier to manage state in local storage and pass state down to children.
|
|
4418
|
-
* Children, if not faced with a local storage or other complexity should be a functional component. Functional
|
|
4419
|
-
* components' tend to be shorter syntactically and bonus points if it's stateless.
|
|
4420
|
-
**/
|
|
4407
|
+
// Save the initial state to the persistent state map with the identifier
|
|
4408
|
+
CarbonReact.persistentStateMap.set(identifier, this.state);
|
|
4421
4409
|
}
|
|
4422
4410
|
shouldComponentUpdate(nextProps, nextState, _nextContext) {
|
|
4423
|
-
|
|
4424
|
-
|
|
4425
|
-
}
|
|
4411
|
+
const identifier = this.props.instanceId || this.constructor.name;
|
|
4412
|
+
CarbonReact.persistentStateMap.set(identifier, nextState);
|
|
4426
4413
|
changed(this.constructor.name + ' (C6Api)', 'props', this.props, nextProps);
|
|
4427
4414
|
changed(this.constructor.name + ' (C6Api)', 'state', this.state, nextState);
|
|
4428
4415
|
return true;
|
|
@@ -4449,6 +4436,10 @@ class CarbonReact extends Component {
|
|
|
4449
4436
|
return jsxRuntime_2(jsxRuntime_3, { children: [jsxRuntime_1(GlobalHistory, {}), this.props.websocket &&
|
|
4450
4437
|
jsxRuntime_1(CarbonWebSocket, { ...(false !== this.props.websocket ? this.props.websocket : {}), instance: this }), jsxRuntime_1(Context, { value: this.state, children: this.props.children }), jsxRuntime_1(ToastContainer, {})] });
|
|
4451
4438
|
}
|
|
4439
|
+
componentWillUnmount() {
|
|
4440
|
+
const identifier = this.props.instanceId || this.constructor.name;
|
|
4441
|
+
CarbonReact.activeInstances.delete(identifier);
|
|
4442
|
+
}
|
|
4452
4443
|
}
|
|
4453
4444
|
|
|
4454
4445
|
var getStatefulObjectWithWhere = ({ request }) => {
|