@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/package.json
CHANGED
package/src/CarbonReact.tsx
CHANGED
|
@@ -49,11 +49,13 @@ export function isJsonString(str: string) {
|
|
|
49
49
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
export interface iCarbonReactProps<P = {}, S extends iCarbonReactState = iCarbonReactState> {
|
|
53
53
|
children?: ReactNode | ReactNode[],
|
|
54
54
|
instanceId?: string,
|
|
55
|
-
websocket?: Omit<iCarbonWebSocketProps<P,S>, "instance"> | false
|
|
56
|
-
}
|
|
55
|
+
websocket?: Omit<iCarbonWebSocketProps<P, S>, "instance"> | false
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
abstract class CarbonReact<P = {}, S extends iCarbonReactState = iCarbonReactState> extends Component<iCarbonReactProps<P, S> & P, S> {
|
|
57
59
|
|
|
58
60
|
private static persistentStateMap = new Map<string, { [key: string]: any; }>();
|
|
59
61
|
|
|
@@ -62,25 +64,29 @@ abstract class CarbonReact<P = {}, S extends iCarbonReactState = iCarbonReactSta
|
|
|
62
64
|
|
|
63
65
|
protected target: typeof CarbonReact;
|
|
64
66
|
|
|
67
|
+
// @link https://stackoverflow.com/questions/55029032/what-is-typescripts-thistype-used-for
|
|
65
68
|
protected static _instance: ThisType<CarbonReact<any, any>>;
|
|
66
69
|
|
|
67
70
|
static getInstance<T extends CarbonReact<any, any>>(): T {
|
|
68
71
|
return this._instance as T;
|
|
69
72
|
}
|
|
73
|
+
|
|
70
74
|
static get instance() {
|
|
71
75
|
return this.getInstance();
|
|
72
76
|
}
|
|
77
|
+
|
|
73
78
|
static set instance(instance: CarbonReact<any, any>) {
|
|
74
79
|
this._instance = instance;
|
|
75
80
|
}
|
|
76
81
|
|
|
77
|
-
|
|
82
|
+
// these are public but the class is abstract
|
|
83
|
+
public updateRestfulObjectArrays = <ObjectType extends { [key: string]: any; } = {}>
|
|
78
84
|
(rest: Omit<iUpdateRestfulObjectArrays<ObjectType, S, P>, "instance">) => updateRestfulObjectArrays<ObjectType, S, P>({
|
|
79
85
|
instance: this,
|
|
80
86
|
...rest
|
|
81
87
|
});
|
|
82
88
|
|
|
83
|
-
|
|
89
|
+
public deleteRestfulObjectArrays = <ObjectType extends { [key: string]: any } = {}>
|
|
84
90
|
(rest: Omit<iDeleteRestfulObjectArrays<ObjectType, S, P>, "instance">) => deleteRestfulObjectArrays<ObjectType, S, P>({
|
|
85
91
|
instance: this,
|
|
86
92
|
...rest
|
|
@@ -93,14 +99,20 @@ abstract class CarbonReact<P = {}, S extends iCarbonReactState = iCarbonReactSta
|
|
|
93
99
|
static whyDidYouRender = true;
|
|
94
100
|
|
|
95
101
|
|
|
96
|
-
protected constructor(props
|
|
97
|
-
children?: ReactNode | ReactNode[];
|
|
98
|
-
shouldStatePersist?: boolean | undefined;
|
|
99
|
-
websocket?: boolean | iCarbonWebSocketProps<P,S> | undefined;
|
|
100
|
-
} & P) {
|
|
102
|
+
protected constructor(props) {
|
|
101
103
|
|
|
102
104
|
super(props);
|
|
103
105
|
|
|
106
|
+
if (!props.instanceId && (new.target as typeof CarbonReact)._instance) {
|
|
107
|
+
|
|
108
|
+
// todo - instanceId being unique should solve this, but.... how
|
|
109
|
+
// This is a singleton pattern, we can only have one instance of this class
|
|
110
|
+
throw new Error(`${new.target.name} instance already exists! CarbonReact extended classes can only be referenced once in DOM`);
|
|
111
|
+
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
(new.target as typeof CarbonReact).instance = (this);
|
|
115
|
+
|
|
104
116
|
this.target = new.target;
|
|
105
117
|
|
|
106
118
|
console.log('CarbonORM TSX CONSTRUCTOR');
|
|
@@ -189,8 +201,8 @@ abstract class CarbonReact<P = {}, S extends iCarbonReactState = iCarbonReactSta
|
|
|
189
201
|
return <>
|
|
190
202
|
<GlobalHistory/>
|
|
191
203
|
{this.props.websocket &&
|
|
192
|
-
<CarbonWebSocket<P,S> {...(false !== this.props.websocket ? this.props.websocket : {})}
|
|
193
|
-
|
|
204
|
+
<CarbonWebSocket<P, S> {...(false !== this.props.websocket ? this.props.websocket : {})}
|
|
205
|
+
instance={this}/>}
|
|
194
206
|
<Context value={this.state}>
|
|
195
207
|
{this.props.children}
|
|
196
208
|
</Context>
|
|
@@ -18,10 +18,10 @@ export interface iAlertButtonOptions {
|
|
|
18
18
|
color: "default" | "primary" | "secondary" | "inherit" | "danger" | "info" | "success" | "warning" | undefined,
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export interface iAlert<P,S extends iCarbonReactState> {
|
|
21
|
+
export interface iAlert<P, S extends iCarbonReactState> {
|
|
22
22
|
title: string,
|
|
23
23
|
text: string,
|
|
24
|
-
instance: CarbonReact<P,S>,
|
|
24
|
+
instance: CarbonReact<P, S>,
|
|
25
25
|
component?: ReactNode,
|
|
26
26
|
icon?: "warning" | "error" | "success" | "info" | "question" | null,
|
|
27
27
|
buttons?: (iAlertButtonOptions)[] | undefined, //['No thanks!', 'Yes, Delete it'],
|
|
@@ -41,13 +41,11 @@ export function addAlert<P, S extends iCarbonReactState>(props: iAlert<P, S>) {
|
|
|
41
41
|
}));
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
export default function Alert<P,S extends iCarbonReactState>({
|
|
45
|
-
instance
|
|
46
|
-
}: { instance: CarbonReact<P,S> }) {
|
|
44
|
+
export default function Alert<P, S extends iCarbonReactState>({instance}: { instance: CarbonReact<P, S> }) {
|
|
47
45
|
|
|
48
46
|
const {alertsWaiting, backendThrowable} = instance.state
|
|
49
47
|
|
|
50
|
-
let alert: iAlert<P,S> | undefined = undefined;
|
|
48
|
+
let alert: iAlert<P, S> | undefined = undefined;
|
|
51
49
|
|
|
52
50
|
const alertWaiting = alertsWaiting.length + backendThrowable.length
|
|
53
51
|
|