@carbonorm/carbonreact 4.0.9 → 4.0.11
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 -9
- package/dist/index.cjs.js +8 -0
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +8 -0
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/CarbonReact.tsx +24 -12
- package/src/components/Alert/Alert.tsx +4 -6
package/dist/CarbonReact.d.ts
CHANGED
|
@@ -17,11 +17,12 @@ 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
|
+
export interface iCarbonReactProps<P = {}, S extends iCarbonReactState = iCarbonReactState> {
|
|
21
21
|
children?: ReactNode | ReactNode[];
|
|
22
22
|
instanceId?: string;
|
|
23
23
|
websocket?: Omit<iCarbonWebSocketProps<P, S>, "instance"> | false;
|
|
24
|
-
}
|
|
24
|
+
}
|
|
25
|
+
declare abstract class CarbonReact<P = {}, S extends iCarbonReactState = iCarbonReactState> extends Component<iCarbonReactProps<P, S> & P, S> {
|
|
25
26
|
private static persistentStateMap;
|
|
26
27
|
context: Context<S & iCarbonReactState>;
|
|
27
28
|
protected target: typeof CarbonReact;
|
|
@@ -29,19 +30,15 @@ declare abstract class CarbonReact<P = {}, S extends iCarbonReactState = iCarbon
|
|
|
29
30
|
static getInstance<T extends CarbonReact<any, any>>(): T;
|
|
30
31
|
static get instance(): CarbonReact<any, any>;
|
|
31
32
|
static set instance(instance: CarbonReact<any, any>);
|
|
32
|
-
|
|
33
|
+
updateRestfulObjectArrays: <ObjectType extends {
|
|
33
34
|
[key: string]: any;
|
|
34
35
|
} = {}>(rest: Omit<iUpdateRestfulObjectArrays<ObjectType, S, P>, "instance">) => void;
|
|
35
|
-
|
|
36
|
+
deleteRestfulObjectArrays: <ObjectType extends {
|
|
36
37
|
[key: string]: any;
|
|
37
38
|
} = {}>(rest: Omit<iDeleteRestfulObjectArrays<ObjectType, S, P>, "instance">) => void;
|
|
38
39
|
static lastLocation: string;
|
|
39
40
|
static whyDidYouRender: boolean;
|
|
40
|
-
protected constructor(props:
|
|
41
|
-
children?: ReactNode | ReactNode[];
|
|
42
|
-
shouldStatePersist?: boolean | undefined;
|
|
43
|
-
websocket?: boolean | iCarbonWebSocketProps<P, S> | undefined;
|
|
44
|
-
} & P);
|
|
41
|
+
protected constructor(props: any);
|
|
45
42
|
shouldComponentUpdate(nextProps: Readonly<P>, nextState: Readonly<S>, _nextContext: any): boolean;
|
|
46
43
|
componentDidUpdate(_prevProps: Readonly<P>, _prevState: Readonly<S>, _snapshot?: any): void;
|
|
47
44
|
render(): ReactElement;
|
package/dist/index.cjs.js
CHANGED
|
@@ -4364,6 +4364,7 @@ class CarbonReact extends react.Component {
|
|
|
4364
4364
|
// Context is for functional components to access the state of this class efficiently
|
|
4365
4365
|
context = react.createContext(this.state);
|
|
4366
4366
|
target;
|
|
4367
|
+
// @link https://stackoverflow.com/questions/55029032/what-is-typescripts-thistype-used-for
|
|
4367
4368
|
static _instance;
|
|
4368
4369
|
static getInstance() {
|
|
4369
4370
|
return this._instance;
|
|
@@ -4374,6 +4375,7 @@ class CarbonReact extends react.Component {
|
|
|
4374
4375
|
static set instance(instance) {
|
|
4375
4376
|
this._instance = instance;
|
|
4376
4377
|
}
|
|
4378
|
+
// these are public but the class is abstract
|
|
4377
4379
|
updateRestfulObjectArrays = (rest) => updateRestfulObjectArrays({
|
|
4378
4380
|
instance: this,
|
|
4379
4381
|
...rest
|
|
@@ -4388,6 +4390,12 @@ class CarbonReact extends react.Component {
|
|
|
4388
4390
|
static whyDidYouRender = true;
|
|
4389
4391
|
constructor(props) {
|
|
4390
4392
|
super(props);
|
|
4393
|
+
if (!props.instanceId && new.target._instance) {
|
|
4394
|
+
// todo - instanceId being unique should solve this, but.... how
|
|
4395
|
+
// This is a singleton pattern, we can only have one instance of this class
|
|
4396
|
+
throw new Error(`${new.target.name} instance already exists! CarbonReact extended classes can only be referenced once in DOM`);
|
|
4397
|
+
}
|
|
4398
|
+
new.target.instance = (this);
|
|
4391
4399
|
this.target = new.target;
|
|
4392
4400
|
console.log('CarbonORM TSX CONSTRUCTOR');
|
|
4393
4401
|
// this is the magic that allows each class that's extends this to have a static instance - a singleton pattern
|