@aprilium/tripsm_global-states 0.0.72 → 0.0.73

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/lib/index.d.ts ADDED
@@ -0,0 +1,49 @@
1
+ /// <reference types="redux-persist/types/types" />
2
+ import { Store } from 'redux';
3
+ import { Saga } from 'redux-saga';
4
+ import { PersistGate } from 'redux-persist/integration/react';
5
+ import { PersistConfig } from 'redux-persist';
6
+ import { State as passengerState } from '@aprilium/tripsm_passenger/lib/state';
7
+ import { State as constantState } from '@aprilium/tripsm_constants/lib/state';
8
+ import { State as tripState } from '@aprilium/tripsm_trip/lib/state';
9
+ import { State as groupState } from '@aprilium/tripsm_trip-group/lib/state';
10
+ import { State as userState } from '@aprilium/tripsm_user/lib/state';
11
+ import passengerSaga from '@aprilium/tripsm_passenger/lib/effects';
12
+ import constantsSaga from '@aprilium/tripsm_constants/lib/effects';
13
+ import TripSaga from '@aprilium/tripsm_trip/lib/effects';
14
+ export declare const sagaMiddleware: import("redux-saga").SagaMiddleware<object>;
15
+ export declare const reducers: {
16
+ passenger: import("immer-reducer").ImmerReducerFunction<typeof import("@aprilium/tripsm_passenger/lib/state").PassengerState>;
17
+ constants: import("immer-reducer").ImmerReducerFunction<typeof import("@aprilium/tripsm_constants/lib/state").ConstantState>;
18
+ trip: import("immer-reducer").ImmerReducerFunction<typeof import("@aprilium/tripsm_trip/lib/state").TripState>;
19
+ group: any;
20
+ user: any;
21
+ };
22
+ export declare const initialSagas: {
23
+ passenger: typeof passengerSaga;
24
+ constants: typeof constantsSaga;
25
+ trip: typeof TripSaga;
26
+ group: any;
27
+ user: any;
28
+ };
29
+ export type States = {
30
+ passenger: passengerState;
31
+ constants: constantState;
32
+ group: groupState;
33
+ trip: tripState;
34
+ user: userState;
35
+ };
36
+ export type StateName = 'passenger' | 'constants' | 'trip' | 'group' | 'user';
37
+ export declare function setUrlConfig(coreApi: string, debugMode?: boolean): void;
38
+ export declare const sagas: any[];
39
+ export declare function initSagaMiddleware(extraSagas?: Array<Saga>, // local sagas from frontEnd Client
40
+ waitForRehydrate?: boolean): void;
41
+ declare function configStore(extraMiddleWares: any[] | undefined, // Adding other middlewares
42
+ persistConfig: PersistConfig<unknown, any, any, any>, // Configuration for persistState
43
+ extraStates?: any, // Adding other states in the store
44
+ replaceAllStates?: boolean): {
45
+ store: Store<any, any>;
46
+ persistor: import("redux-persist").Persistor;
47
+ PersistGate: typeof PersistGate;
48
+ };
49
+ export default configStore;
package/lib/index.js ADDED
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __generator = (this && this.__generator) || function (thisArg, body) {
14
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
15
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
16
+ function verb(n) { return function (v) { return step([n, v]); }; }
17
+ function step(op) {
18
+ if (f) throw new TypeError("Generator is already executing.");
19
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
20
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
21
+ if (y = 0, t) op = [op[0] & 2, t.value];
22
+ switch (op[0]) {
23
+ case 0: case 1: t = op; break;
24
+ case 4: _.label++; return { value: op[1], done: false };
25
+ case 5: _.label++; y = op[1]; op = [0]; continue;
26
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
27
+ default:
28
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
29
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
30
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
31
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
32
+ if (t[2]) _.ops.pop();
33
+ _.trys.pop(); continue;
34
+ }
35
+ op = body.call(thisArg, _);
36
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
37
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
38
+ }
39
+ };
40
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
41
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
42
+ if (ar || !(i in from)) {
43
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
44
+ ar[i] = from[i];
45
+ }
46
+ }
47
+ return to.concat(ar || Array.prototype.slice.call(from));
48
+ };
49
+ var __importDefault = (this && this.__importDefault) || function (mod) {
50
+ return (mod && mod.__esModule) ? mod : { "default": mod };
51
+ };
52
+ Object.defineProperty(exports, "__esModule", { value: true });
53
+ exports.initSagaMiddleware = exports.sagas = exports.setUrlConfig = exports.initialSagas = exports.reducers = exports.sagaMiddleware = void 0;
54
+ var redux_1 = require("redux");
55
+ var redux_saga_1 = __importDefault(require("redux-saga"));
56
+ var effects_1 = require("redux-saga/effects");
57
+ var react_1 = require("redux-persist/integration/react");
58
+ var redux_persist_1 = require("redux-persist");
59
+ var lib_1 = require("@aprilium/tripsm_passenger/lib");
60
+ var lib_2 = require("@aprilium/tripsm_constants/lib");
61
+ var lib_3 = require("@aprilium/tripsm_passenger/lib");
62
+ var lib_4 = require("@aprilium/tripsm_user/lib");
63
+ var state_1 = require("@aprilium/tripsm_passenger/lib/state");
64
+ var state_2 = require("@aprilium/tripsm_constants/lib/state");
65
+ var state_3 = require("@aprilium/tripsm_trip/lib/state");
66
+ var state_4 = require("@aprilium/tripsm_trip-group/lib/state");
67
+ var state_5 = require("@aprilium/tripsm_user/lib/state");
68
+ //import sagas
69
+ var effects_2 = __importDefault(require("@aprilium/tripsm_passenger/lib/effects"));
70
+ var effects_3 = __importDefault(require("@aprilium/tripsm_constants/lib/effects"));
71
+ var effects_4 = __importDefault(require("@aprilium/tripsm_trip/lib/effects"));
72
+ var effects_5 = __importDefault(require("@aprilium/tripsm_trip-group/lib/effects"));
73
+ var effects_6 = __importDefault(require("@aprilium/tripsm_user/lib/effects"));
74
+ exports.sagaMiddleware = (0, redux_saga_1.default)();
75
+ exports.reducers = {
76
+ passenger: state_1.passengerReducerFunction,
77
+ constants: state_2.ConstantsReducerFunction,
78
+ trip: state_3.TripReducerFunction,
79
+ group: state_4.GroupReducerFunction,
80
+ user: state_5.userReducerFunction
81
+ };
82
+ exports.initialSagas = {
83
+ passenger: effects_2.default,
84
+ constants: effects_3.default,
85
+ trip: effects_4.default,
86
+ group: effects_5.default,
87
+ user: effects_6.default
88
+ };
89
+ function setUrlConfig(coreApi, debugMode) {
90
+ if (debugMode === void 0) { debugMode = false; }
91
+ lib_1.urlsConfig.setURls({
92
+ CORE_BASE_URL: coreApi,
93
+ DEBUG_MODE: debugMode
94
+ });
95
+ lib_2.urlsConfig.setURls({
96
+ CORE_BASE_URL: coreApi,
97
+ DEBUG_MODE: debugMode
98
+ });
99
+ lib_3.urlsConfig.setURls({
100
+ CORE_BASE_URL: coreApi,
101
+ DEBUG_MODE: debugMode
102
+ });
103
+ lib_4.urlsConfig.setURls({
104
+ CORE_BASE_URL: coreApi,
105
+ DEBUG_MODE: debugMode
106
+ });
107
+ }
108
+ exports.setUrlConfig = setUrlConfig;
109
+ exports.sagas = Object.keys(exports.initialSagas).map(function (key) { return exports.initialSagas[key]; });
110
+ function initSagaMiddleware(extraSagas, // local sagas from frontEnd Client
111
+ waitForRehydrate) {
112
+ if (extraSagas === void 0) { extraSagas = []; }
113
+ if (waitForRehydrate === void 0) { waitForRehydrate = false; }
114
+ console.log("extraSagas", extraSagas);
115
+ var _sagas = __spreadArray(__spreadArray([], exports.sagas, true), extraSagas, true);
116
+ console.log("_sagas", _sagas);
117
+ // It will initialize all sagas
118
+ function rootSaga() {
119
+ var instSagas;
120
+ return __generator(this, function (_a) {
121
+ switch (_a.label) {
122
+ case 0:
123
+ if (!waitForRehydrate) return [3 /*break*/, 2];
124
+ return [4 /*yield*/, (0, effects_1.take)(redux_persist_1.REHYDRATE)];
125
+ case 1:
126
+ _a.sent();
127
+ _a.label = 2;
128
+ case 2: return [4 /*yield*/, _sagas.map(function (saga) {
129
+ return __generator(this, function (_a) {
130
+ switch (_a.label) {
131
+ case 0: return [4 /*yield*/, (0, effects_1.fork)(saga)];
132
+ case 1:
133
+ _a.sent();
134
+ return [2 /*return*/];
135
+ }
136
+ });
137
+ })];
138
+ case 3:
139
+ instSagas = _a.sent();
140
+ return [4 /*yield*/, (0, effects_1.all)(instSagas)];
141
+ case 4:
142
+ _a.sent();
143
+ return [2 /*return*/];
144
+ }
145
+ });
146
+ }
147
+ // Start the listener
148
+ exports.sagaMiddleware.run(rootSaga);
149
+ }
150
+ exports.initSagaMiddleware = initSagaMiddleware;
151
+ function configStore(extraMiddleWares, // Adding other middlewares
152
+ persistConfig, // Configuration for persistState
153
+ extraStates, // Adding other states in the store
154
+ replaceAllStates // It will keep only extraStates
155
+ ) {
156
+ if (extraMiddleWares === void 0) { extraMiddleWares = []; }
157
+ if (extraStates === void 0) { extraStates = {}; }
158
+ if (replaceAllStates === void 0) { replaceAllStates = false; }
159
+ console.log("configuration du store");
160
+ console.log("extra middleware", extraMiddleWares);
161
+ var _reducers = (0, redux_1.combineReducers)(__assign(__assign({}, exports.reducers), extraStates));
162
+ if (replaceAllStates) {
163
+ _reducers = (0, redux_1.combineReducers)(__assign({}, extraStates));
164
+ }
165
+ var _middleWares = __spreadArray(__spreadArray([], extraMiddleWares, true), [exports.sagaMiddleware], false);
166
+ // @ts-ignore
167
+ var persistedReducer = (0, redux_persist_1.persistReducer)(persistConfig, _reducers);
168
+ var store = (0, redux_1.createStore)(persistedReducer, redux_1.applyMiddleware.apply(void 0, _middleWares));
169
+ var persistor = (0, redux_persist_1.persistStore)(store);
170
+ return { store: store, persistor: persistor, PersistGate: react_1.PersistGate };
171
+ }
172
+ exports.default = configStore;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aprilium/tripsm_global-states",
3
- "version": "0.0.72",
3
+ "version": "0.0.73",
4
4
  "description": "global states",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -15,11 +15,9 @@
15
15
  "@aprilium/tripsm_passenger": "^0.0.47",
16
16
  "@aprilium/tripsm_common": "^0.0.6",
17
17
  "@aprilium/tripsm_constants": "^0.0.11",
18
- "@aprilium/tripsm_trip": "^0.0.1",
18
+ "@aprilium/tripsm_trip": "^0.0.3",
19
19
  "@aprilium/tripsm_trip-group": "^0.0.1",
20
20
  "@aprilium/tripsm_user":"^0.0.6",
21
- "@aprilium/tripsm_country":"^0.0.1",
22
- "@aprilium/tripsm_IdentityType":"^0.0.1",
23
21
  "@types/react": "^17.0.0",
24
22
  "axios": "^0.21.1",
25
23
  "immer": "^9.0.15",