@carbonorm/carbonreact 4.0.11 → 4.0.13
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/CarbonReact.d.ts
CHANGED
|
@@ -17,13 +17,13 @@ export interface iCarbonReactState {
|
|
|
17
17
|
export declare const initialRequiredCarbonORMState: iCarbonReactState;
|
|
18
18
|
export declare const initialCarbonReactState: iCarbonReactState & iRestfulObjectArrayTypes;
|
|
19
19
|
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
23
|
websocket?: Omit<iCarbonWebSocketProps<P, S>, "instance"> | false;
|
|
24
|
-
}
|
|
25
|
-
declare abstract class CarbonReact<P = {}, S extends iCarbonReactState = iCarbonReactState> extends Component<iCarbonReactProps<P, S> & P, S> {
|
|
24
|
+
} & P, S> {
|
|
26
25
|
private static persistentStateMap;
|
|
26
|
+
private static activeInstances;
|
|
27
27
|
context: Context<S & iCarbonReactState>;
|
|
28
28
|
protected target: typeof CarbonReact;
|
|
29
29
|
protected static _instance: ThisType<CarbonReact<any, any>>;
|
|
@@ -38,9 +38,15 @@ declare abstract class CarbonReact<P = {}, S extends iCarbonReactState = iCarbon
|
|
|
38
38
|
} = {}>(rest: Omit<iDeleteRestfulObjectArrays<ObjectType, S, P>, "instance">) => void;
|
|
39
39
|
static lastLocation: string;
|
|
40
40
|
static whyDidYouRender: boolean;
|
|
41
|
-
protected constructor(props:
|
|
41
|
+
protected constructor(props: {
|
|
42
|
+
children?: ReactNode | ReactNode[];
|
|
43
|
+
shouldStatePersist?: boolean | undefined;
|
|
44
|
+
websocket?: boolean | iCarbonWebSocketProps<P, S> | undefined;
|
|
45
|
+
instanceId?: string;
|
|
46
|
+
} & P);
|
|
42
47
|
shouldComponentUpdate(nextProps: Readonly<P>, nextState: Readonly<S>, _nextContext: any): boolean;
|
|
43
48
|
componentDidUpdate(_prevProps: Readonly<P>, _prevState: Readonly<S>, _snapshot?: any): void;
|
|
44
49
|
render(): ReactElement;
|
|
50
|
+
componentWillUnmount(): void;
|
|
45
51
|
}
|
|
46
52
|
export default CarbonReact;
|
package/dist/index.cjs.js
CHANGED
|
@@ -4361,10 +4361,9 @@ function isJsonString(str) {
|
|
|
4361
4361
|
}
|
|
4362
4362
|
class CarbonReact extends react.Component {
|
|
4363
4363
|
static persistentStateMap = new Map();
|
|
4364
|
-
|
|
4364
|
+
static activeInstances = new Map();
|
|
4365
4365
|
context = react.createContext(this.state);
|
|
4366
4366
|
target;
|
|
4367
|
-
// @link https://stackoverflow.com/questions/55029032/what-is-typescripts-thistype-used-for
|
|
4368
4367
|
static _instance;
|
|
4369
4368
|
static getInstance() {
|
|
4370
4369
|
return this._instance;
|
|
@@ -4375,7 +4374,6 @@ class CarbonReact extends react.Component {
|
|
|
4375
4374
|
static set instance(instance) {
|
|
4376
4375
|
this._instance = instance;
|
|
4377
4376
|
}
|
|
4378
|
-
// these are public but the class is abstract
|
|
4379
4377
|
updateRestfulObjectArrays = (rest) => updateRestfulObjectArrays({
|
|
4380
4378
|
instance: this,
|
|
4381
4379
|
...rest
|
|
@@ -4385,46 +4383,35 @@ class CarbonReact extends react.Component {
|
|
|
4385
4383
|
...rest
|
|
4386
4384
|
});
|
|
4387
4385
|
static lastLocation = window.location.pathname;
|
|
4388
|
-
// @link https://github.com/welldone-software/why-did-you-render
|
|
4389
|
-
// noinspection JSUnusedGlobalSymbols
|
|
4390
4386
|
static whyDidYouRender = true;
|
|
4391
4387
|
constructor(props) {
|
|
4392
4388
|
super(props);
|
|
4393
|
-
|
|
4394
|
-
|
|
4395
|
-
|
|
4396
|
-
throw new Error(
|
|
4389
|
+
const target = new.target;
|
|
4390
|
+
const identifier = props.instanceId || target.name;
|
|
4391
|
+
if (CarbonReact.activeInstances.has(identifier)) {
|
|
4392
|
+
throw new Error(`Instance with ID ${identifier} already exists! CarbonReact extended classes can only be referenced once in DOM with the same identifier.`);
|
|
4397
4393
|
}
|
|
4398
|
-
|
|
4399
|
-
this.target =
|
|
4394
|
+
CarbonReact.activeInstances.set(identifier, this);
|
|
4395
|
+
this.target = target;
|
|
4400
4396
|
console.log('CarbonORM TSX CONSTRUCTOR');
|
|
4401
|
-
|
|
4402
|
-
// new.target is a meta-property introduced in ES6 that references the constructor that was directly invoked with the new keyword.
|
|
4403
|
-
Object.assign(new.target, {
|
|
4397
|
+
Object.assign(target, {
|
|
4404
4398
|
_instance: this
|
|
4405
4399
|
});
|
|
4406
|
-
if (
|
|
4407
|
-
this.state = CarbonReact.persistentStateMap.get(
|
|
4400
|
+
if (CarbonReact.persistentStateMap.has(identifier)) {
|
|
4401
|
+
this.state = CarbonReact.persistentStateMap.get(identifier);
|
|
4408
4402
|
}
|
|
4409
4403
|
else {
|
|
4410
|
-
// This should only ever be done here, when the full state is being trashed.
|
|
4411
|
-
// todo - does this suck in context of multiple instances?
|
|
4412
4404
|
carbonnode.clearCache({
|
|
4413
4405
|
ignoreWarning: true
|
|
4414
4406
|
});
|
|
4415
4407
|
this.state = initialCarbonReactState;
|
|
4416
4408
|
}
|
|
4417
|
-
|
|
4418
|
-
|
|
4419
|
-
* Class based components are far easier to manage state in local storage and pass state down to children.
|
|
4420
|
-
* Children, if not faced with a local storage or other complexity should be a functional component. Functional
|
|
4421
|
-
* components' tend to be shorter syntactically and bonus points if it's stateless.
|
|
4422
|
-
**/
|
|
4409
|
+
// Save the initial state to the persistent state map with the identifier
|
|
4410
|
+
CarbonReact.persistentStateMap.set(identifier, this.state);
|
|
4423
4411
|
}
|
|
4424
4412
|
shouldComponentUpdate(nextProps, nextState, _nextContext) {
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
}
|
|
4413
|
+
const identifier = this.props.instanceId || this.constructor.name;
|
|
4414
|
+
CarbonReact.persistentStateMap.set(identifier, nextState);
|
|
4428
4415
|
changed(this.constructor.name + ' (C6Api)', 'props', this.props, nextProps);
|
|
4429
4416
|
changed(this.constructor.name + ' (C6Api)', 'state', this.state, nextState);
|
|
4430
4417
|
return true;
|
|
@@ -4451,6 +4438,10 @@ class CarbonReact extends react.Component {
|
|
|
4451
4438
|
return jsxRuntime_2(jsxRuntime_3, { children: [jsxRuntime_1(GlobalHistory, {}), this.props.websocket &&
|
|
4452
4439
|
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, {})] });
|
|
4453
4440
|
}
|
|
4441
|
+
componentWillUnmount() {
|
|
4442
|
+
const identifier = this.props.instanceId || this.constructor.name;
|
|
4443
|
+
CarbonReact.activeInstances.delete(identifier);
|
|
4444
|
+
}
|
|
4454
4445
|
}
|
|
4455
4446
|
|
|
4456
4447
|
var getStatefulObjectWithWhere = ({ request }) => {
|