@carbonorm/carbonreact 3.6.0 → 3.6.2
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 +22 -52
- package/dist/index.cjs.js +26 -19
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +27 -20
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/CarbonReact.tsx +38 -28
package/dist/CarbonReact.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Component, Context, ReactElement, ReactNode } from 'react';
|
|
2
2
|
import 'react-toastify/dist/ReactToastify.min.css';
|
|
3
3
|
import { iRestfulObjectArrayTypes } from "variables/C6";
|
|
4
|
+
import { iCarbonWebSocketProps } from "./components/WebSocket/CarbonWebSocket";
|
|
4
5
|
export interface iCarbonReactState {
|
|
5
6
|
alertsWaiting: any[];
|
|
6
7
|
websocketEvents: MessageEvent[];
|
|
@@ -11,58 +12,27 @@ export interface iCarbonReactState {
|
|
|
11
12
|
export declare const initialRequiredCarbonORMState: iCarbonReactState;
|
|
12
13
|
export declare const initialCarbonReactState: iCarbonReactState & iRestfulObjectArrayTypes;
|
|
13
14
|
export declare function isJsonString(str: string): boolean;
|
|
14
|
-
declare
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
children?: ReactNode | ReactNode[];
|
|
22
|
-
shouldStatePersist?: boolean | undefined;
|
|
23
|
-
} & P>) => (S & iCarbonReactState) | Pick<S & iCarbonReactState, K> | null) | Pick<S & iCarbonReactState, K> | null, callback?: (() => void) | undefined): void;
|
|
24
|
-
forceUpdate(callback?: (() => void) | undefined): void;
|
|
25
|
-
readonly props: Readonly<{
|
|
26
|
-
children?: ReactNode | ReactNode[];
|
|
27
|
-
shouldStatePersist?: boolean | undefined;
|
|
28
|
-
} & P>;
|
|
29
|
-
state: Readonly<S & iCarbonReactState>;
|
|
30
|
-
refs: {
|
|
31
|
-
[key: string]: import("react").ReactInstance;
|
|
32
|
-
};
|
|
33
|
-
componentDidMount?(): void;
|
|
34
|
-
componentWillUnmount?(): void;
|
|
35
|
-
componentDidCatch?(error: Error, errorInfo: import("react").ErrorInfo): void;
|
|
36
|
-
getSnapshotBeforeUpdate?(prevProps: Readonly<{
|
|
37
|
-
children?: ReactNode | ReactNode[];
|
|
38
|
-
shouldStatePersist?: boolean | undefined;
|
|
39
|
-
} & P>, prevState: Readonly<S & iCarbonReactState>): any;
|
|
40
|
-
componentWillMount?(): void;
|
|
41
|
-
UNSAFE_componentWillMount?(): void;
|
|
42
|
-
componentWillReceiveProps?(nextProps: Readonly<{
|
|
43
|
-
children?: ReactNode | ReactNode[];
|
|
44
|
-
shouldStatePersist?: boolean | undefined;
|
|
45
|
-
} & P>, nextContext: any): void;
|
|
46
|
-
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<{
|
|
47
|
-
children?: ReactNode | ReactNode[];
|
|
48
|
-
shouldStatePersist?: boolean | undefined;
|
|
49
|
-
} & P>, nextContext: any): void;
|
|
50
|
-
componentWillUpdate?(nextProps: Readonly<{
|
|
51
|
-
children?: ReactNode | ReactNode[];
|
|
52
|
-
shouldStatePersist?: boolean | undefined;
|
|
53
|
-
} & P>, nextState: Readonly<S & iCarbonReactState>, nextContext: any): void;
|
|
54
|
-
UNSAFE_componentWillUpdate?(nextProps: Readonly<{
|
|
55
|
-
children?: ReactNode | ReactNode[];
|
|
56
|
-
shouldStatePersist?: boolean | undefined;
|
|
57
|
-
} & P>, nextState: Readonly<S & iCarbonReactState>, nextContext: any): void;
|
|
58
|
-
};
|
|
59
|
-
instance: Component<{
|
|
15
|
+
declare abstract class CarbonReact<P = {}, S = {}> extends Component<{
|
|
16
|
+
children?: ReactNode | ReactNode[];
|
|
17
|
+
instanceId?: string;
|
|
18
|
+
websocket?: iCarbonWebSocketProps | boolean;
|
|
19
|
+
} & P, S & iCarbonReactState> {
|
|
20
|
+
context: Context<S & iCarbonReactState>;
|
|
21
|
+
protected static instance: CarbonReact & Component<{
|
|
60
22
|
children?: ReactNode | ReactNode[];
|
|
61
23
|
} & any, any & iCarbonReactState>;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
24
|
+
protected static getState(): Readonly<iCarbonReactState> & Readonly<any>;
|
|
25
|
+
protected static useContext(): () => iCarbonReactState;
|
|
26
|
+
protected: any;
|
|
27
|
+
static lastLocation: string;
|
|
28
|
+
static whyDidYouRender: boolean;
|
|
29
|
+
protected constructor(props: {
|
|
30
|
+
children?: ReactNode | ReactNode[];
|
|
31
|
+
shouldStatePersist?: boolean | undefined;
|
|
32
|
+
websocket?: boolean | iCarbonWebSocketProps | undefined;
|
|
33
|
+
} & P);
|
|
34
|
+
shouldComponentUpdate(nextProps: Readonly<any>, nextState: Readonly<iCarbonReactState>, _nextContext: any): boolean;
|
|
35
|
+
componentDidUpdate(_prevProps: Readonly<any>, _prevState: Readonly<iCarbonReactState>, _snapshot?: any): void;
|
|
36
|
+
render(): ReactElement;
|
|
37
|
+
}
|
|
68
38
|
export default CarbonReact;
|
package/dist/index.cjs.js
CHANGED
|
@@ -4257,10 +4257,18 @@ function isJsonString(str) {
|
|
|
4257
4257
|
return true;
|
|
4258
4258
|
}
|
|
4259
4259
|
// Create a context
|
|
4260
|
-
const
|
|
4261
|
-
|
|
4260
|
+
const persistentStateMap = new Map();
|
|
4261
|
+
class CarbonReact extends react.Component {
|
|
4262
4262
|
context = react.createContext(this.state);
|
|
4263
|
-
|
|
4263
|
+
// Private static member
|
|
4264
|
+
static instance;
|
|
4265
|
+
static getState() {
|
|
4266
|
+
return CarbonReact.instance.state;
|
|
4267
|
+
}
|
|
4268
|
+
static useContext() {
|
|
4269
|
+
return () => react.useContext(CarbonReact.instance.context);
|
|
4270
|
+
}
|
|
4271
|
+
protected;
|
|
4264
4272
|
static lastLocation = window.location.pathname;
|
|
4265
4273
|
// @link https://github.com/welldone-software/why-did-you-render
|
|
4266
4274
|
// noinspection JSUnusedGlobalSymbols
|
|
@@ -4268,16 +4276,20 @@ const CarbonReact = class extends react.Component {
|
|
|
4268
4276
|
constructor(props) {
|
|
4269
4277
|
super(props);
|
|
4270
4278
|
console.log('CarbonORM TSX CONSTRUCTOR');
|
|
4271
|
-
|
|
4272
|
-
this
|
|
4279
|
+
Object.assign(this, {
|
|
4280
|
+
instance: this
|
|
4281
|
+
});
|
|
4282
|
+
if (this.props.instanceId && persistentStateMap.has(this.props.instanceId)) {
|
|
4283
|
+
this.state = persistentStateMap.get(this.props.instanceId);
|
|
4273
4284
|
}
|
|
4274
4285
|
else {
|
|
4286
|
+
// This should only ever be done here, when the full state is being trashed.
|
|
4287
|
+
// todo - does this suck in context of multiple instances?
|
|
4288
|
+
carbonnode.clearCache({
|
|
4289
|
+
ignoreWarning: true
|
|
4290
|
+
});
|
|
4275
4291
|
this.state = initialCarbonReactState;
|
|
4276
4292
|
}
|
|
4277
|
-
// This should only ever be done here, when the full state is being trashed.
|
|
4278
|
-
carbonnode.clearCache({
|
|
4279
|
-
ignoreWarning: true
|
|
4280
|
-
});
|
|
4281
4293
|
/** We can think of our app as having one state; this state.
|
|
4282
4294
|
* Long-term, I'd like us to store this state to local storage and only load updates on reload...
|
|
4283
4295
|
* Class based components are far easier to manage state in local storage and pass state down to children.
|
|
@@ -4285,15 +4297,9 @@ const CarbonReact = class extends react.Component {
|
|
|
4285
4297
|
* components' tend to be shorter syntactically and bonus points if it's stateless.
|
|
4286
4298
|
**/
|
|
4287
4299
|
}
|
|
4288
|
-
static getState() {
|
|
4289
|
-
return CarbonReact.instance.state;
|
|
4290
|
-
}
|
|
4291
4300
|
shouldComponentUpdate(nextProps, nextState, _nextContext) {
|
|
4292
|
-
if (this.props.
|
|
4293
|
-
|
|
4294
|
-
}
|
|
4295
|
-
else {
|
|
4296
|
-
CarbonReact.persistentState = nextState;
|
|
4301
|
+
if (this.props.instanceId) {
|
|
4302
|
+
persistentStateMap.set(this.props.instanceId, nextState);
|
|
4297
4303
|
}
|
|
4298
4304
|
changed(this.constructor.name + ' (C6Api)', 'props', this.props, nextProps);
|
|
4299
4305
|
changed(this.constructor.name + ' (C6Api)', 'state', this.state, nextState);
|
|
@@ -4318,9 +4324,10 @@ const CarbonReact = class extends react.Component {
|
|
|
4318
4324
|
return jsxRuntime_2(jsxRuntime_3, { children: [nest, jsxRuntime_1(BackendThrowable, {})] });
|
|
4319
4325
|
}
|
|
4320
4326
|
const Context = this.context.Provider;
|
|
4321
|
-
return jsxRuntime_2(jsxRuntime_3, { children: [jsxRuntime_1(GlobalHistory, {}),
|
|
4327
|
+
return jsxRuntime_2(jsxRuntime_3, { children: [jsxRuntime_1(GlobalHistory, {}), this.props.websocket &&
|
|
4328
|
+
jsxRuntime_1(CarbonWebSocket, { ...(true === this.props.websocket ? {} : this.props.websocket) }), jsxRuntime_1(Context, { value: this.state, children: this.props.children }), jsxRuntime_1(reactToastify.ToastContainer, {})] });
|
|
4322
4329
|
}
|
|
4323
|
-
}
|
|
4330
|
+
}
|
|
4324
4331
|
|
|
4325
4332
|
var getStatefulObjectWithWhere = ({ request }) => {
|
|
4326
4333
|
console.log('request', request);
|