@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/CarbonReact.d.ts
CHANGED
|
@@ -20,14 +20,14 @@ export declare function isJsonString(str: string): boolean;
|
|
|
20
20
|
declare abstract class CarbonReact<P = {}, S extends iCarbonReactState = iCarbonReactState> extends Component<{
|
|
21
21
|
children?: ReactNode | ReactNode[];
|
|
22
22
|
instanceId?: string;
|
|
23
|
+
persistentState?: boolean;
|
|
23
24
|
websocket?: Omit<iCarbonWebSocketProps<P, S>, "instance"> | false;
|
|
24
25
|
} & P, S> {
|
|
25
|
-
private static
|
|
26
|
-
private static activeInstances;
|
|
26
|
+
private static allInstances;
|
|
27
27
|
context: Context<S & iCarbonReactState>;
|
|
28
28
|
protected target: typeof CarbonReact;
|
|
29
29
|
protected static _instance: ThisType<CarbonReact<any, any>>;
|
|
30
|
-
static getInstance<T extends CarbonReact<any, any>>(): T;
|
|
30
|
+
static getInstance<T extends CarbonReact<any, any>>(instanceId?: string): T;
|
|
31
31
|
static get instance(): CarbonReact<any, any>;
|
|
32
32
|
static set instance(instance: CarbonReact<any, any>);
|
|
33
33
|
updateRestfulObjectArrays: <ObjectType extends {
|
|
@@ -40,13 +40,14 @@ declare abstract class CarbonReact<P = {}, S extends iCarbonReactState = iCarbon
|
|
|
40
40
|
static whyDidYouRender: boolean;
|
|
41
41
|
protected constructor(props: {
|
|
42
42
|
children?: ReactNode | ReactNode[];
|
|
43
|
-
shouldStatePersist?: boolean | undefined;
|
|
44
43
|
websocket?: boolean | iCarbonWebSocketProps<P, S> | undefined;
|
|
45
44
|
instanceId?: string;
|
|
45
|
+
persistentState?: boolean;
|
|
46
46
|
} & P);
|
|
47
|
+
private static generateIdentifier;
|
|
48
|
+
private generateIdentifier;
|
|
47
49
|
shouldComponentUpdate(nextProps: Readonly<P>, nextState: Readonly<S>, _nextContext: any): boolean;
|
|
48
50
|
componentDidUpdate(_prevProps: Readonly<P>, _prevState: Readonly<S>, _snapshot?: any): void;
|
|
49
51
|
render(): ReactElement;
|
|
50
|
-
componentWillUnmount(): void;
|
|
51
52
|
}
|
|
52
53
|
export default CarbonReact;
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var react = require('react');
|
|
4
|
-
var carbonnode = require('@carbonorm/carbonnode');
|
|
5
4
|
var reactRouterDom = require('react-router-dom');
|
|
6
5
|
var reactToastify = require('react-toastify');
|
|
7
6
|
var OutsideClickHandler = require('react-outside-click-handler');
|
|
7
|
+
var carbonnode = require('@carbonorm/carbonnode');
|
|
8
8
|
var classNames = require('classnames');
|
|
9
9
|
var freeSolidSvgIcons = require('@fortawesome/free-solid-svg-icons');
|
|
10
10
|
var reactFontawesome = require('@fortawesome/react-fontawesome');
|
|
@@ -4372,12 +4372,21 @@ function isJsonString(str) {
|
|
|
4372
4372
|
return true;
|
|
4373
4373
|
}
|
|
4374
4374
|
class CarbonReact extends react.Component {
|
|
4375
|
-
static
|
|
4376
|
-
static activeInstances = new Map();
|
|
4375
|
+
static allInstances = new Map();
|
|
4377
4376
|
context = react.createContext(this.state);
|
|
4378
4377
|
target;
|
|
4379
4378
|
static _instance;
|
|
4380
|
-
static getInstance() {
|
|
4379
|
+
static getInstance(instanceId) {
|
|
4380
|
+
const identifier = this.generateIdentifier(instanceId);
|
|
4381
|
+
if (undefined !== instanceId) {
|
|
4382
|
+
if (CarbonReact.allInstances.has(identifier)) {
|
|
4383
|
+
return CarbonReact.allInstances.get(identifier);
|
|
4384
|
+
}
|
|
4385
|
+
throw new Error(`No instance has been instantiated yet for class (${this.name}) with instanceId (${instanceId})`);
|
|
4386
|
+
}
|
|
4387
|
+
if (!this._instance) {
|
|
4388
|
+
throw new Error(`No instance has been instantiated yet for class (${this.name})`);
|
|
4389
|
+
}
|
|
4381
4390
|
return this._instance;
|
|
4382
4391
|
}
|
|
4383
4392
|
static get instance() {
|
|
@@ -4398,32 +4407,30 @@ class CarbonReact extends react.Component {
|
|
|
4398
4407
|
static whyDidYouRender = true;
|
|
4399
4408
|
constructor(props) {
|
|
4400
4409
|
super(props);
|
|
4401
|
-
const
|
|
4402
|
-
|
|
4403
|
-
|
|
4404
|
-
|
|
4405
|
-
}
|
|
4406
|
-
CarbonReact.activeInstances.set(identifier, this);
|
|
4407
|
-
this.target = target;
|
|
4408
|
-
console.log('CarbonORM TSX CONSTRUCTOR');
|
|
4409
|
-
Object.assign(target, {
|
|
4410
|
-
_instance: this
|
|
4411
|
-
});
|
|
4412
|
-
if (CarbonReact.persistentStateMap.has(identifier)) {
|
|
4413
|
-
this.state = CarbonReact.persistentStateMap.get(identifier);
|
|
4410
|
+
const identifier = this.generateIdentifier();
|
|
4411
|
+
if (props.persistentState && CarbonReact.allInstances.has(identifier)) {
|
|
4412
|
+
// Reuse the state from the existing instance
|
|
4413
|
+
this.state = CarbonReact.allInstances.get(identifier).state;
|
|
4414
4414
|
}
|
|
4415
4415
|
else {
|
|
4416
|
-
carbonnode.clearCache({
|
|
4417
|
-
ignoreWarning: true
|
|
4418
|
-
});
|
|
4419
4416
|
this.state = initialCarbonReactState;
|
|
4417
|
+
CarbonReact.allInstances.set(identifier, this);
|
|
4420
4418
|
}
|
|
4421
|
-
|
|
4422
|
-
|
|
4419
|
+
this.target = new.target;
|
|
4420
|
+
console.log('CarbonORM TSX CONSTRUCTOR');
|
|
4421
|
+
Object.assign(this.target, {
|
|
4422
|
+
_instance: this
|
|
4423
|
+
});
|
|
4424
|
+
}
|
|
4425
|
+
static generateIdentifier(instanceId) {
|
|
4426
|
+
const className = this.name;
|
|
4427
|
+
return instanceId ? `${className}-${instanceId}` : className;
|
|
4428
|
+
}
|
|
4429
|
+
generateIdentifier() {
|
|
4430
|
+
const className = this.constructor.name;
|
|
4431
|
+
return this.props.instanceId ? `${className}-${this.props.instanceId}` : className;
|
|
4423
4432
|
}
|
|
4424
4433
|
shouldComponentUpdate(nextProps, nextState, _nextContext) {
|
|
4425
|
-
const identifier = this.props.instanceId || this.constructor.name;
|
|
4426
|
-
CarbonReact.persistentStateMap.set(identifier, nextState);
|
|
4427
4434
|
changed(this.constructor.name + ' (C6Api)', 'props', this.props, nextProps);
|
|
4428
4435
|
changed(this.constructor.name + ' (C6Api)', 'state', this.state, nextState);
|
|
4429
4436
|
return true;
|
|
@@ -4450,10 +4457,6 @@ class CarbonReact extends react.Component {
|
|
|
4450
4457
|
return jsxRuntime_2(jsxRuntime_3, { children: [jsxRuntime_1(GlobalHistory, {}), this.props.websocket &&
|
|
4451
4458
|
jsxRuntime_1(CarbonWebSocket, { ...(false !== this.props.websocket ? this.props.websocket : {}), instance: this }), jsxRuntime_1(Context, { value: this.state, children: this.props.children }), jsxRuntime_1(reactToastify.ToastContainer, {})] });
|
|
4452
4459
|
}
|
|
4453
|
-
componentWillUnmount() {
|
|
4454
|
-
const identifier = this.props.instanceId || this.constructor.name;
|
|
4455
|
-
CarbonReact.activeInstances.delete(identifier);
|
|
4456
|
-
}
|
|
4457
4460
|
}
|
|
4458
4461
|
|
|
4459
4462
|
var getStatefulObjectWithWhere = ({ request }) => {
|