@pihanga2/core 0.3.1 → 0.3.3

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/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
- import ReactDOM from "react-dom/client"
2
- import { Dispatch } from "react"
1
+ import ReactDOM from "react-dom/client";
2
+ import {Dispatch} from "react";
3
3
 
4
4
  import {
5
5
  PiCardDef,
@@ -14,15 +14,21 @@ import {
14
14
  PiMapProps,
15
15
  WindowProps,
16
16
  GenericCardParameterT,
17
- } from "./types"
18
- import { createCardDeclaration, registerCard, registerCardComponent, registerMetacard, updateOrRegisterCard } from "./register_cards"
19
- import { createReducer } from "./reducer"
20
- import { ON_INIT_ACTION, currentRoute, init as routerInit } from "./router"
17
+ } from "./types";
18
+ import {
19
+ createCardDeclaration,
20
+ registerCard,
21
+ registerCardComponent,
22
+ registerMetacard,
23
+ updateOrRegisterCard,
24
+ } from "./register_cards";
25
+ import {createReducer} from "./reducer";
26
+ import {ON_INIT_ACTION, currentRoute, init as routerInit} from "./router";
21
27
 
22
- import { configureStore } from "@reduxjs/toolkit"
28
+ import {configureStore} from "@reduxjs/toolkit";
23
29
 
24
30
  //import monitorReducerEnhancer from "./monitor_enhancer"
25
- import { getLogger } from "./logger"
31
+ import {getLogger} from "./logger";
26
32
  import {
27
33
  PiRegisterDeleteProps,
28
34
  PiRegisterGetProps,
@@ -32,9 +38,9 @@ import {
32
38
  registerPATCH,
33
39
  registerPOST,
34
40
  registerPUT,
35
- } from "./rest"
36
- import { RootComponent } from "./root"
37
- const logger = getLogger("root")
41
+ } from "./rest";
42
+ import {RootComponent} from "./root";
43
+ const logger = getLogger("root");
38
44
 
39
45
  export type {
40
46
  PiMapProps,
@@ -50,27 +56,38 @@ export type {
50
56
  PiReducer,
51
57
  PiRegisterMetaCard,
52
58
  WindowProps,
53
- } from "./types"
54
- export { registerActions, actionTypesToEvents, createOnAction } from "./redux"
55
- export { Card, usePiReducer } from "./card"
56
- export { memo, createCardDeclaration, isCardRef } from "./register_cards"
57
- export { getLogger } from "./logger"
58
- export type { PiCardProps, PiCardRef } from "./types"
59
- export type { ErrorAction as RestErrorAction } from "./rest"
60
- export { RestContentType } from "./rest"
61
-
62
- export { showPage, onInit, onShowPage, createShowPageAction, onNavigateToPage } from "./router"
63
- export type { ShowPageEvent, NavigateToPageEvent } from "./router"
59
+ } from "./types";
60
+ export {registerActions, actionTypesToEvents, createOnAction} from "./redux";
61
+ export {Card, usePiReducer, cls_f} from "./card";
62
+ export {memo, createCardDeclaration, isCardRef} from "./register_cards";
63
+ export {getLogger} from "./logger";
64
+ export type {PiCardProps, PiCardRef} from "./types";
65
+ export type {ErrorAction as RestErrorAction} from "./rest";
66
+ export {RestContentType} from "./rest";
67
+
68
+ export {
69
+ showPage,
70
+ onInit,
71
+ onShowPage,
72
+ createShowPageAction,
73
+ onNavigateToPage,
74
+ } from "./router";
75
+ export type {ShowPageEvent, NavigateToPageEvent} from "./router";
64
76
 
65
77
  export interface PiRegister {
66
78
  //window(parameters: PiCardDef): PiCardRef
67
79
 
68
- window<S extends ReduxState>(parameters: PiMapProps<WindowProps, S, {}>): PiCardRef
80
+ window<S extends ReduxState>(
81
+ parameters: PiMapProps<WindowProps, S, {}>
82
+ ): PiCardRef;
69
83
 
70
- card(name: string, parameters: PiCardDef): PiCardRef
71
- updateCard(name: string, parameters: { [key: string]: GenericCardParameterT }): PiCardRef
84
+ card(name: string, parameters: PiCardDef): PiCardRef;
85
+ updateCard(
86
+ name: string,
87
+ parameters: {[key: string]: GenericCardParameterT}
88
+ ): PiCardRef;
72
89
 
73
- cardComponent(declaration: PiRegisterComponent): void
90
+ cardComponent(declaration: PiRegisterComponent): void;
74
91
 
75
92
  /**
76
93
  * Register a meta card which expands a single card definition of type `name`
@@ -82,41 +99,41 @@ export interface PiRegister {
82
99
  * @param {string} type
83
100
  * @param {function} mapper
84
101
  */
85
- metaCard<C>(declaration: PiRegisterMetaCard): void
102
+ metaCard<C>(declaration: PiRegisterMetaCard): void;
86
103
 
87
104
  GET<S extends ReduxState, A extends ReduxAction, R, C = any>(
88
- props: PiRegisterGetProps<S, A, R, C>,
89
- ): void
105
+ props: PiRegisterGetProps<S, A, R, C>
106
+ ): void;
90
107
  PUT<S extends ReduxState, A extends ReduxAction, R, C = any>(
91
- props: PiRegisterPoPuPaProps<S, A, R, C>,
92
- ): void
108
+ props: PiRegisterPoPuPaProps<S, A, R, C>
109
+ ): void;
93
110
  POST<S extends ReduxState, A extends ReduxAction, R, C = any>(
94
- props: PiRegisterPoPuPaProps<S, A, R, C>,
95
- ): void
111
+ props: PiRegisterPoPuPaProps<S, A, R, C>
112
+ ): void;
96
113
  PATCH<S extends ReduxState, A extends ReduxAction, R, C = any>(
97
- props: PiRegisterPoPuPaProps<S, A, R, C>,
98
- ): void
114
+ props: PiRegisterPoPuPaProps<S, A, R, C>
115
+ ): void;
99
116
  DELETE<S extends ReduxState, A extends ReduxAction, R, C = any>(
100
- props: PiRegisterDeleteProps<S, A, R, C>,
101
- ): void
117
+ props: PiRegisterDeleteProps<S, A, R, C>
118
+ ): void;
102
119
  //registerPeriodicGET<S extends ReduxState, A extends ReduxAction, R>(props: PiRegisterPeridicGetProps<S, A, R>): void;
103
120
 
104
- reducer: PiReducer
121
+ reducer: PiReducer;
105
122
  }
106
123
 
107
124
  export const DEFAULT_REDUX_STATE = {
108
- route: { path: [], query: {}, url: "", fromBrowser: false },
125
+ route: {path: [], query: {}, url: "", fromBrowser: false},
109
126
  pihanga: {},
110
- }
127
+ };
111
128
 
112
129
  export type StartProps = {
113
130
  // redux settins
114
- disableSerializableStateCheck?: boolean
115
- disableSerializableActionCheck?: boolean
116
- ignoredActions?: string[]
117
- ignoredActionPaths?: string[]
118
- ignoredStatePaths?: string[]
119
- }
131
+ disableSerializableStateCheck?: boolean;
132
+ disableSerializableActionCheck?: boolean;
133
+ ignoredActions?: string[];
134
+ ignoredActionPaths?: string[];
135
+ ignoredStatePaths?: string[];
136
+ };
120
137
 
121
138
  export function start<S extends Partial<ReduxState>>(
122
139
  initialState: S,
@@ -126,20 +143,20 @@ export function start<S extends Partial<ReduxState>>(
126
143
  const state = {
127
144
  ...DEFAULT_REDUX_STATE,
128
145
  ...initialState,
129
- ...{ route: currentRoute() }, // override route with current one
130
- }
131
- let dispatchF: Dispatch<any> | null = null
146
+ ...{route: currentRoute()}, // override route with current one
147
+ };
148
+ let dispatchF: Dispatch<any> | null = null;
132
149
  const dispatcherW: Dispatch<any> = (a: any): void => {
133
150
  if (dispatchF) {
134
- dispatchF(a)
151
+ dispatchF(a);
135
152
  } else {
136
- logger.error("dispatch function is not properly set")
153
+ logger.error("dispatch function is not properly set");
137
154
  }
138
- }
139
- const [reducer, piReducer] = createReducer(state, dispatcherW)
140
- const route = routerInit(piReducer)
155
+ };
156
+ const [reducer, piReducer] = createReducer(state, dispatcherW);
157
+ const route = routerInit(piReducer);
141
158
 
142
- const ignoredActions = ([] as string[]).concat(props.ignoredActions || [])
159
+ const ignoredActions = ([] as string[]).concat(props.ignoredActions || []);
143
160
  const ignoredActionPaths = [
144
161
  "apiURL", // from IVCAP
145
162
  "mapper",
@@ -148,8 +165,8 @@ export function start<S extends Partial<ReduxState>>(
148
165
  "headers",
149
166
  "cause",
150
167
  "data",
151
- ].concat(props.ignoredActionPaths || [])
152
- const ignoredPaths = ["cause.content"].concat(props.ignoredStatePaths || [])
168
+ ].concat(props.ignoredActionPaths || []);
169
+ const ignoredPaths = ["cause.content"].concat(props.ignoredStatePaths || []);
153
170
 
154
171
  const store = configureStore({
155
172
  reducer,
@@ -163,21 +180,22 @@ export function start<S extends Partial<ReduxState>>(
163
180
  ignoredPaths,
164
181
  ignoreState: props.disableSerializableStateCheck,
165
182
  ignoreAction: props.disableSerializableActionCheck,
166
- }
167
- })
168
- })
183
+ },
184
+ }),
185
+ });
169
186
  // make pihanga's reducer interface available to cards
170
- const anyStore: any = store
171
- anyStore.piReducer = piReducer
172
-
173
- dispatchF = store.dispatch
187
+ const anyStore: any = store;
188
+ anyStore.piReducer = piReducer;
174
189
 
175
- const card = registerCard(piReducer.register, dispatchF)
176
- const updateCard = updateOrRegisterCard(piReducer.register, dispatchF)
177
- const window = <S extends ReduxState>(p: PiMapProps<WindowProps, S, {}>): PiCardRef => {
178
- return card("_window", { cardType: "framework", ...p })
179
- }
190
+ dispatchF = store.dispatch;
180
191
 
192
+ const card = registerCard(piReducer.register, dispatchF);
193
+ const updateCard = updateOrRegisterCard(piReducer.register, dispatchF);
194
+ const window = <S extends ReduxState>(
195
+ p: PiMapProps<WindowProps, S, {}>
196
+ ): PiCardRef => {
197
+ return card("_window", {cardType: "framework", ...p});
198
+ };
181
199
 
182
200
  const register: PiRegister = {
183
201
  window,
@@ -191,14 +209,14 @@ export function start<S extends Partial<ReduxState>>(
191
209
  POST: registerPOST(piReducer),
192
210
  PATCH: registerPATCH(piReducer),
193
211
  DELETE: registerDELETE(piReducer),
194
- }
195
- inits.forEach((f) => f(register))
212
+ };
213
+ inits.forEach((f) => f(register));
196
214
 
197
- piReducer.dispatch({ type: ON_INIT_ACTION })
215
+ piReducer.dispatch({type: ON_INIT_ACTION});
198
216
 
199
- const rootComp = RootComponent(store)
200
- const root = ReactDOM.createRoot(document.getElementById("root")!)
201
- root.render(rootComp)
217
+ const rootComp = RootComponent(store);
218
+ const root = ReactDOM.createRoot(document.getElementById("root")!);
219
+ root.render(rootComp);
202
220
 
203
- return register
221
+ return register;
204
222
  }