@carbonorm/carbonreact 4.0.14 → 4.0.16
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 +6 -5
- package/dist/index.cjs.js +31 -28
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +31 -28
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/CarbonReact.tsx +39 -35
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,21 @@ function isJsonString(str) {
|
|
|
4370
4370
|
return true;
|
|
4371
4371
|
}
|
|
4372
4372
|
class CarbonReact extends Component {
|
|
4373
|
-
static
|
|
4374
|
-
static activeInstances = new Map();
|
|
4373
|
+
static allInstances = new Map();
|
|
4375
4374
|
context = createContext(this.state);
|
|
4376
4375
|
target;
|
|
4377
4376
|
static _instance;
|
|
4378
|
-
static getInstance() {
|
|
4377
|
+
static getInstance(instanceId) {
|
|
4378
|
+
const identifier = this.generateIdentifier(instanceId);
|
|
4379
|
+
if (undefined !== instanceId) {
|
|
4380
|
+
if (CarbonReact.allInstances.has(identifier)) {
|
|
4381
|
+
return CarbonReact.allInstances.get(identifier);
|
|
4382
|
+
}
|
|
4383
|
+
throw new Error(`No instance has been instantiated yet for class (${this.name}) with instanceId (${instanceId})`);
|
|
4384
|
+
}
|
|
4385
|
+
if (!this._instance) {
|
|
4386
|
+
throw new Error(`No instance has been instantiated yet for class (${this.name})`);
|
|
4387
|
+
}
|
|
4379
4388
|
return this._instance;
|
|
4380
4389
|
}
|
|
4381
4390
|
static get instance() {
|
|
@@ -4396,32 +4405,30 @@ class CarbonReact extends Component {
|
|
|
4396
4405
|
static whyDidYouRender = true;
|
|
4397
4406
|
constructor(props) {
|
|
4398
4407
|
super(props);
|
|
4399
|
-
const
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4403
|
-
}
|
|
4404
|
-
CarbonReact.activeInstances.set(identifier, this);
|
|
4405
|
-
this.target = target;
|
|
4406
|
-
console.log('CarbonORM TSX CONSTRUCTOR');
|
|
4407
|
-
Object.assign(target, {
|
|
4408
|
-
_instance: this
|
|
4409
|
-
});
|
|
4410
|
-
if (CarbonReact.persistentStateMap.has(identifier)) {
|
|
4411
|
-
this.state = CarbonReact.persistentStateMap.get(identifier);
|
|
4408
|
+
const identifier = this.generateIdentifier();
|
|
4409
|
+
if (props.persistentState && CarbonReact.allInstances.has(identifier)) {
|
|
4410
|
+
// Reuse the state from the existing instance
|
|
4411
|
+
this.state = CarbonReact.allInstances.get(identifier).state;
|
|
4412
4412
|
}
|
|
4413
4413
|
else {
|
|
4414
|
-
clearCache({
|
|
4415
|
-
ignoreWarning: true
|
|
4416
|
-
});
|
|
4417
4414
|
this.state = initialCarbonReactState;
|
|
4415
|
+
CarbonReact.allInstances.set(identifier, this);
|
|
4418
4416
|
}
|
|
4419
|
-
|
|
4420
|
-
|
|
4417
|
+
this.target = new.target;
|
|
4418
|
+
console.log('CarbonORM TSX CONSTRUCTOR');
|
|
4419
|
+
Object.assign(this.target, {
|
|
4420
|
+
_instance: this
|
|
4421
|
+
});
|
|
4422
|
+
}
|
|
4423
|
+
static generateIdentifier(instanceId) {
|
|
4424
|
+
const className = this.name;
|
|
4425
|
+
return instanceId ? `${className}-${instanceId}` : className;
|
|
4426
|
+
}
|
|
4427
|
+
generateIdentifier() {
|
|
4428
|
+
const className = this.constructor.name;
|
|
4429
|
+
return this.props.instanceId ? `${className}-${this.props.instanceId}` : className;
|
|
4421
4430
|
}
|
|
4422
4431
|
shouldComponentUpdate(nextProps, nextState, _nextContext) {
|
|
4423
|
-
const identifier = this.props.instanceId || this.constructor.name;
|
|
4424
|
-
CarbonReact.persistentStateMap.set(identifier, nextState);
|
|
4425
4432
|
changed(this.constructor.name + ' (C6Api)', 'props', this.props, nextProps);
|
|
4426
4433
|
changed(this.constructor.name + ' (C6Api)', 'state', this.state, nextState);
|
|
4427
4434
|
return true;
|
|
@@ -4448,10 +4455,6 @@ class CarbonReact extends Component {
|
|
|
4448
4455
|
return jsxRuntime_2(jsxRuntime_3, { children: [jsxRuntime_1(GlobalHistory, {}), this.props.websocket &&
|
|
4449
4456
|
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
4457
|
}
|
|
4451
|
-
componentWillUnmount() {
|
|
4452
|
-
const identifier = this.props.instanceId || this.constructor.name;
|
|
4453
|
-
CarbonReact.activeInstances.delete(identifier);
|
|
4454
|
-
}
|
|
4455
4458
|
}
|
|
4456
4459
|
|
|
4457
4460
|
var getStatefulObjectWithWhere = ({ request }) => {
|