@carbonorm/carbonreact 4.0.14 → 4.0.15
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 +7 -4
- package/dist/index.cjs.js +37 -24
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +37 -24
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/CarbonReact.tsx +47 -31
package/dist/index.esm.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import react, { useRef, useState, useEffect, Component, createContext, lazy } from 'react';
|
|
2
|
-
import { toastOptions, clearCache, timeout, axiosInstance, isVerbose, checkAllRequestsComplete } from '@carbonorm/carbonnode';
|
|
3
2
|
import { useNavigate } from 'react-router-dom';
|
|
4
3
|
import { toast, ToastContainer } from 'react-toastify';
|
|
5
4
|
import OutsideClickHandler from 'react-outside-click-handler';
|
|
5
|
+
import { toastOptions, timeout, axiosInstance, isVerbose, checkAllRequestsComplete } from '@carbonorm/carbonnode';
|
|
6
6
|
import classNames from 'classnames';
|
|
7
7
|
import { faClose } from '@fortawesome/free-solid-svg-icons';
|
|
8
8
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
@@ -4370,12 +4370,22 @@ function isJsonString(str) {
|
|
|
4370
4370
|
return true;
|
|
4371
4371
|
}
|
|
4372
4372
|
class CarbonReact extends Component {
|
|
4373
|
-
static
|
|
4373
|
+
static allInstances = new Map();
|
|
4374
4374
|
static activeInstances = new Map();
|
|
4375
4375
|
context = createContext(this.state);
|
|
4376
4376
|
target;
|
|
4377
4377
|
static _instance;
|
|
4378
|
-
static getInstance() {
|
|
4378
|
+
static getInstance(instanceId) {
|
|
4379
|
+
const identifier = this.generateIdentifier(instanceId);
|
|
4380
|
+
if (undefined !== instanceId) {
|
|
4381
|
+
if (CarbonReact.activeInstances.has(identifier)) {
|
|
4382
|
+
return CarbonReact.activeInstances.get(identifier);
|
|
4383
|
+
}
|
|
4384
|
+
throw new Error(`No instance has been instantiated yet for class (${this.name}) with instanceId (${instanceId})`);
|
|
4385
|
+
}
|
|
4386
|
+
if (!this._instance) {
|
|
4387
|
+
throw new Error(`No instance has been instantiated yet for class (${this.name})`);
|
|
4388
|
+
}
|
|
4379
4389
|
return this._instance;
|
|
4380
4390
|
}
|
|
4381
4391
|
static get instance() {
|
|
@@ -4396,32 +4406,39 @@ class CarbonReact extends Component {
|
|
|
4396
4406
|
static whyDidYouRender = true;
|
|
4397
4407
|
constructor(props) {
|
|
4398
4408
|
super(props);
|
|
4399
|
-
const
|
|
4400
|
-
const identifier = props.instanceId || target.name;
|
|
4409
|
+
const identifier = this.generateIdentifier();
|
|
4401
4410
|
if (CarbonReact.activeInstances.has(identifier)) {
|
|
4402
|
-
throw new Error(
|
|
4411
|
+
throw new Error(`${identifier} instance already exists in the DOM! Each instance should have a unique instanceId.`);
|
|
4403
4412
|
}
|
|
4413
|
+
// Register the new instance
|
|
4404
4414
|
CarbonReact.activeInstances.set(identifier, this);
|
|
4405
|
-
|
|
4406
|
-
|
|
4407
|
-
|
|
4408
|
-
_instance: this
|
|
4409
|
-
});
|
|
4410
|
-
if (CarbonReact.persistentStateMap.has(identifier)) {
|
|
4411
|
-
this.state = CarbonReact.persistentStateMap.get(identifier);
|
|
4415
|
+
if (props.persistentState && CarbonReact.allInstances.has(identifier)) {
|
|
4416
|
+
// Reuse the state from the existing instance
|
|
4417
|
+
this.state = CarbonReact.allInstances.get(identifier).state;
|
|
4412
4418
|
}
|
|
4413
4419
|
else {
|
|
4414
|
-
clearCache({
|
|
4415
|
-
ignoreWarning: true
|
|
4416
|
-
});
|
|
4417
4420
|
this.state = initialCarbonReactState;
|
|
4421
|
+
CarbonReact.allInstances.set(identifier, this);
|
|
4418
4422
|
}
|
|
4419
|
-
|
|
4420
|
-
|
|
4423
|
+
this.target = new.target;
|
|
4424
|
+
console.log('CarbonORM TSX CONSTRUCTOR');
|
|
4425
|
+
Object.assign(this.target, {
|
|
4426
|
+
_instance: this
|
|
4427
|
+
});
|
|
4428
|
+
}
|
|
4429
|
+
static generateIdentifier(instanceId) {
|
|
4430
|
+
const className = this.name;
|
|
4431
|
+
return instanceId ? `${className}-${instanceId}` : className;
|
|
4432
|
+
}
|
|
4433
|
+
generateIdentifier() {
|
|
4434
|
+
const className = this.constructor.name;
|
|
4435
|
+
return this.props.instanceId ? `${className}-${this.props.instanceId}` : className;
|
|
4436
|
+
}
|
|
4437
|
+
componentWillUnmount() {
|
|
4438
|
+
const identifier = this.generateIdentifier();
|
|
4439
|
+
CarbonReact.activeInstances.delete(identifier);
|
|
4421
4440
|
}
|
|
4422
4441
|
shouldComponentUpdate(nextProps, nextState, _nextContext) {
|
|
4423
|
-
const identifier = this.props.instanceId || this.constructor.name;
|
|
4424
|
-
CarbonReact.persistentStateMap.set(identifier, nextState);
|
|
4425
4442
|
changed(this.constructor.name + ' (C6Api)', 'props', this.props, nextProps);
|
|
4426
4443
|
changed(this.constructor.name + ' (C6Api)', 'state', this.state, nextState);
|
|
4427
4444
|
return true;
|
|
@@ -4448,10 +4465,6 @@ class CarbonReact extends Component {
|
|
|
4448
4465
|
return jsxRuntime_2(jsxRuntime_3, { children: [jsxRuntime_1(GlobalHistory, {}), this.props.websocket &&
|
|
4449
4466
|
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, {})] });
|
|
4450
4467
|
}
|
|
4451
|
-
componentWillUnmount() {
|
|
4452
|
-
const identifier = this.props.instanceId || this.constructor.name;
|
|
4453
|
-
CarbonReact.activeInstances.delete(identifier);
|
|
4454
|
-
}
|
|
4455
4468
|
}
|
|
4456
4469
|
|
|
4457
4470
|
var getStatefulObjectWithWhere = ({ request }) => {
|