@carbonorm/carbonreact 3.6.1 → 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.
@@ -12,65 +12,27 @@ export interface iCarbonReactState {
12
12
  export declare const initialRequiredCarbonORMState: iCarbonReactState;
13
13
  export declare const initialCarbonReactState: iCarbonReactState & iRestfulObjectArrayTypes;
14
14
  export declare function isJsonString(str: string): boolean;
15
- declare const CarbonReact: {
16
- new <P = {}, S = {}>(props: any): {
17
- context: Context<S & iCarbonReactState>;
18
- shouldComponentUpdate(nextProps: Readonly<any>, nextState: Readonly<iCarbonReactState>, _nextContext: any): boolean;
19
- componentDidUpdate(_prevProps: Readonly<any>, _prevState: Readonly<iCarbonReactState>, _snapshot?: any): void;
20
- render(): ReactElement;
21
- setState<K extends keyof iCarbonReactState | keyof S>(state: (S & iCarbonReactState) | ((prevState: Readonly<S & iCarbonReactState>, props: Readonly<{
22
- children?: ReactNode | ReactNode[];
23
- shouldStatePersist?: boolean | undefined;
24
- websocket?: boolean | iCarbonWebSocketProps | undefined;
25
- } & P>) => (S & iCarbonReactState) | Pick<S & iCarbonReactState, K> | null) | Pick<S & iCarbonReactState, K> | null, callback?: (() => void) | undefined): void;
26
- forceUpdate(callback?: (() => void) | undefined): void;
27
- readonly props: Readonly<{
28
- children?: ReactNode | ReactNode[];
29
- shouldStatePersist?: boolean | undefined;
30
- websocket?: boolean | iCarbonWebSocketProps | undefined;
31
- } & P>;
32
- state: Readonly<S & iCarbonReactState>;
33
- refs: {
34
- [key: string]: import("react").ReactInstance;
35
- };
36
- componentDidMount?(): void;
37
- componentWillUnmount?(): void;
38
- componentDidCatch?(error: Error, errorInfo: import("react").ErrorInfo): void;
39
- getSnapshotBeforeUpdate?(prevProps: Readonly<{
40
- children?: ReactNode | ReactNode[];
41
- shouldStatePersist?: boolean | undefined;
42
- websocket?: boolean | iCarbonWebSocketProps | undefined;
43
- } & P>, prevState: Readonly<S & iCarbonReactState>): any;
44
- componentWillMount?(): void;
45
- UNSAFE_componentWillMount?(): void;
46
- componentWillReceiveProps?(nextProps: Readonly<{
47
- children?: ReactNode | ReactNode[];
48
- shouldStatePersist?: boolean | undefined;
49
- websocket?: boolean | iCarbonWebSocketProps | undefined;
50
- } & P>, nextContext: any): void;
51
- UNSAFE_componentWillReceiveProps?(nextProps: Readonly<{
52
- children?: ReactNode | ReactNode[];
53
- shouldStatePersist?: boolean | undefined;
54
- websocket?: boolean | iCarbonWebSocketProps | undefined;
55
- } & P>, nextContext: any): void;
56
- componentWillUpdate?(nextProps: Readonly<{
57
- children?: ReactNode | ReactNode[];
58
- shouldStatePersist?: boolean | undefined;
59
- websocket?: boolean | iCarbonWebSocketProps | undefined;
60
- } & P>, nextState: Readonly<S & iCarbonReactState>, nextContext: any): void;
61
- UNSAFE_componentWillUpdate?(nextProps: Readonly<{
62
- children?: ReactNode | ReactNode[];
63
- shouldStatePersist?: boolean | undefined;
64
- websocket?: boolean | iCarbonWebSocketProps | undefined;
65
- } & P>, nextState: Readonly<S & iCarbonReactState>, nextContext: any): void;
66
- };
67
- 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<{
68
22
  children?: ReactNode | ReactNode[];
69
23
  } & any, any & iCarbonReactState>;
70
- persistentState?: iCarbonReactState | undefined;
71
- lastLocation: string;
72
- whyDidYouRender: boolean;
73
- getState<S_1>(): S_1;
74
- contextType?: Context<any> | undefined;
75
- };
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
+ }
76
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 CarbonReact = class extends react.Component {
4261
- static instance;
4260
+ const persistentStateMap = new Map();
4261
+ class CarbonReact extends react.Component {
4262
4262
  context = react.createContext(this.state);
4263
- static persistentState = undefined;
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
- if (CarbonReact.persistentState !== undefined && this.props.shouldStatePersist !== false) {
4272
- this.state = CarbonReact.persistentState;
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.shouldStatePersist === false) {
4293
- CarbonReact.persistentState = undefined;
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);
@@ -4321,7 +4327,7 @@ const CarbonReact = class extends react.Component {
4321
4327
  return jsxRuntime_2(jsxRuntime_3, { children: [jsxRuntime_1(GlobalHistory, {}), this.props.websocket &&
4322
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, {})] });
4323
4329
  }
4324
- };
4330
+ }
4325
4331
 
4326
4332
  var getStatefulObjectWithWhere = ({ request }) => {
4327
4333
  console.log('request', request);