@situm/react-native 3.0.0-beta.1 → 3.0.0-beta.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.
Files changed (32) hide show
  1. package/README.md +6 -10
  2. package/android/.gradle/5.6.4/fileChanges/last-build.bin +0 -0
  3. package/android/.gradle/5.6.4/fileHashes/fileHashes.lock +0 -0
  4. package/android/.gradle/5.6.4/gc.properties +0 -0
  5. package/lib/commonjs/wayfinding/components/MapView.js +1 -1
  6. package/lib/commonjs/wayfinding/components/MapView.js.map +1 -1
  7. package/lib/commonjs/wayfinding/hooks/index.js +18 -9
  8. package/lib/commonjs/wayfinding/hooks/index.js.map +1 -1
  9. package/lib/commonjs/wayfinding/store/index.js +117 -89
  10. package/lib/commonjs/wayfinding/store/index.js.map +1 -1
  11. package/lib/commonjs/wayfinding/store/utils.js +16 -10
  12. package/lib/commonjs/wayfinding/store/utils.js.map +1 -1
  13. package/lib/module/wayfinding/components/MapView.js +1 -1
  14. package/lib/module/wayfinding/components/MapView.js.map +1 -1
  15. package/lib/module/wayfinding/hooks/index.js +18 -10
  16. package/lib/module/wayfinding/hooks/index.js.map +1 -1
  17. package/lib/module/wayfinding/store/index.js +116 -89
  18. package/lib/module/wayfinding/store/index.js.map +1 -1
  19. package/lib/module/wayfinding/store/utils.js +13 -8
  20. package/lib/module/wayfinding/store/utils.js.map +1 -1
  21. package/lib/typescript/src/wayfinding/hooks/index.d.ts +2 -1
  22. package/lib/typescript/src/wayfinding/hooks/index.d.ts.map +1 -1
  23. package/lib/typescript/src/wayfinding/store/index.d.ts +9 -0
  24. package/lib/typescript/src/wayfinding/store/index.d.ts.map +1 -1
  25. package/lib/typescript/src/wayfinding/store/utils.d.ts +6 -1
  26. package/lib/typescript/src/wayfinding/store/utils.d.ts.map +1 -1
  27. package/package.json +7 -8
  28. package/src/sdk/types/index.d.ts +18 -18
  29. package/src/wayfinding/components/MapView.tsx +1 -1
  30. package/src/wayfinding/hooks/index.ts +21 -9
  31. package/src/wayfinding/store/index.tsx +76 -48
  32. package/src/wayfinding/store/utils.ts +18 -8
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/wayfinding/hooks/index.ts"],"names":[],"mappings":";AAGA,OAAO,EACL,KAAK,QAAQ,EAUb,KAAK,aAAa,EACnB,MAAM,aAAa,CAAC;AAuCrB,eAAO,MAAM,cAAc,mBAAoB,GAAG,EAAE,wCASnD,CAAC;AAEF,QAAA,MAAM,QAAQ;;;;;;;;;;;;gBAuBF,MAAM;iBACL,MAAM;yBACE,OAAO;2BACL,OAAO;0BACR,OAAO;;;4BAmFU,QAAQ;yCAbK,MAAM;;;;kBAoI5C,MAAM;uBACD,MAAM;4BACD,GAAG;sBACT,OAAO;;;4BA6DD,MAAM,eAAe,aAAa,KAAK,IAAI;uBAChD,MAAM;4BACD,GAAG;4BACH,GAAG;kBACb,MAAM;sBACF,OAAO;;0BAmDI,IAAI;CA6DhC,CAAC;AAEF,eAAe,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/wayfinding/hooks/index.ts"],"names":[],"mappings":";AAGA,OAAO,EACL,KAAK,QAAQ,EAUb,KAAK,aAAa,EACnB,MAAM,aAAa,CAAC;AAwCrB,eAAO,MAAM,cAAc,mBAAoB,GAAG,EAAE,wCASnD,CAAC;AAEF,eAAO,MAAM,gBAAgB;;;;;;;;;;;;gBAuBjB,MAAM;iBACL,MAAM;yBACE,OAAO;2BACL,OAAO;0BACR,OAAO;;;4BAmFU,QAAQ;yCAbK,MAAM;;;;kBAoI5C,MAAM;uBACD,MAAM;4BACD,GAAG;sBACT,OAAO;;;4BA6DD,MAAM,eAAe,aAAa,KAAK,IAAI;uBAChD,MAAM;4BACD,GAAG;4BACH,GAAG;kBACb,MAAM;sBACF,OAAO;;0BAoDI,IAAI;CA6DhC,CAAC;AAEF,QAAA,MAAM,QAAQ,WAQb,CAAC;AAEF,eAAe,QAAQ,CAAC"}
@@ -36,6 +36,15 @@ export declare const selectNavigation: (state: State) => SDKNavigation;
36
36
  export declare const selectDestinationPoiID: (state: State) => number;
37
37
  export declare const selectError: (state: State) => SDKError;
38
38
  export declare const setWebViewRef: (payload?: any) => (state: State) => State, setSdkInitialized: (payload?: any) => (state: State) => State, setAuth: (payload?: any) => (state: State) => State, setLocation: (payload?: any) => (state: State) => State, setLocationStatus: (payload?: any) => (state: State) => State, resetLocation: (payload?: any) => (state: State) => State, setBuildings: (payload?: any) => (state: State) => State, setCurrentBuilding: (payload?: any) => (state: State) => State, setPois: (payload?: any) => (state: State) => State, setDirections: (payload?: any) => (state: State) => State, setNavigation: (payload?: any) => (state: State) => State, setDestinationPoiID: (payload?: any) => (state: State) => State, setError: (payload?: any) => (state: State) => State;
39
+ /**
40
+ * Context specifically to store the only instance of our hook.
41
+ */
42
+ export declare const UseSitumContext: React.Context<{
43
+ useSitum: any;
44
+ }>;
45
+ /**
46
+ * Main context of the application, stores the plugins' state.
47
+ */
39
48
  declare const SitumProvider: React.FC<React.PropsWithChildren<{
40
49
  email?: string;
41
50
  apiKey?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/wayfinding/store/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAiB,gBAAgB,EAAc,MAAM,OAAO,CAAC;AAE3E,OAAO,EACL,QAAQ,EACR,QAAQ,EACR,kBAAkB,EAElB,GAAG,EACH,QAAQ,EACR,aAAa,EACd,MAAM,yBAAyB,CAAC;AAIjC,MAAM,MAAM,UAAU,GAAG,GAAG,CAAC;AAE7B,UAAU,IAAI;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,KAAK;IACpB,UAAU,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAC;IACxC,cAAc,EAAE,OAAO,CAAC;IACxB,IAAI,CAAC,EA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AE5C,CAAC;AAEF,eAAO,MAAM,sBAAsB,UAAW,KAAK,YAElD,CAAC;AAEF,eAAO,MAAM,UAAU,UAAW,KAAK,SAEtC,CAAC;AAEF,eAAO,MAAM,cAAc,UAAW,KAAK,aAE1C,CAAC;AAEF,eAAO,MAAM,oBAAoB,UAAW,KAAK,uBAEhD,CAAC;AAEF,eAAO,MAAM,eAAe,UAAW,KAAK,eAE3C,CAAC;AAEF,eAAO,MAAM,qBAAqB,UAAW,KAAK,aAEjD,CAAC;AAEF,eAAO,MAAM,UAAU,UAAW,KAAK,UAEtC,CAAC;AAEF,eAAO,MAAM,gBAAgB,UAAW,KAAK,QAE5C,CAAC;AAEF,eAAO,MAAM,gBAAgB,UAAW,KAAK,kBAE5C,CAAC;AAEF,eAAO,MAAM,sBAAsB,UAAW,KAAK,WAElD,CAAC;AAEF,eAAO,MAAM,WAAW,UAAW,KAAK,aAEvC,CAAC;AAEF,eAAO,MACL,aAAa,8CACb,iBAAiB,8CACjB,OAAO,8CACP,WAAW,8CACX,iBAAiB,8CACjB,aAAa,8CACb,YAAY,8CACZ,kBAAkB,8CAClB,OAAO,8CACP,aAAa,8CACb,aAAa,8CACb,mBAAmB,8CACnB,QAAQ,4CACO,CAAC;AAElB;;GAEG;AACH,eAAO,MAAM,eAAe;cAA6B,GAAG;EAE3D,CAAC;AAgBF;;GAEG;AACH,QAAA,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAC3B,KAAK,CAAC,iBAAiB,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC,CAiBH,CAAC;AAEF,eAAe,aAAa,CAAC"}
@@ -1,6 +1,11 @@
1
1
  /// <reference types="react" />
2
2
  import { State } from "./index";
3
- export declare const createReducer: <T>(reducers: Record<string, (state: T, payload: any) => T>) => {
3
+ export declare const createReducer: <T>() => (state: T, action: (state: T) => T) => T;
4
+ export declare const createStore: <T>({ initialState, reducers, }: {
5
+ initialState: T;
6
+ reducers: Record<string, (state: T, payload: any) => T>;
7
+ }) => {
8
+ initialState: T;
4
9
  actions: Record<string, (payload?: any) => (state: T) => T>;
5
10
  reducer: (state: T, action: (state: T) => T) => T;
6
11
  };
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../src/wayfinding/store/utils.ts"],"names":[],"mappings":";AAGA,OAAO,EAAgB,KAAK,EAAE,MAAM,SAAS,CAAC;AAE9C,eAAO,MAAM,aAAa,mDACqB,GAAG;uCAMb,GAAG;;CAOvC,CAAC;AAEF,eAAO,MAAM,WAAW,qBAAsB,KAAK,KAAK,GAAG,QAQ1D,CAAC;AAEF,eAAO,MAAM,WAAW,qDAQvB,CAAC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../src/wayfinding/store/utils.ts"],"names":[],"mappings":";AAGA,OAAO,EAAgB,KAAK,EAAE,MAAM,SAAS,CAAC;AAE9C,eAAO,MAAM,aAAa,mDAKzB,CAAC;AAEF,eAAO,MAAM,WAAW;;iDAKuB,GAAG;;;uCAKb,GAAG;;CAOvC,CAAC;AAEF,eAAO,MAAM,WAAW,qBAAsB,KAAK,KAAK,GAAG,QAQ1D,CAAC;AAEF,eAAO,MAAM,WAAW,qDAQvB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@situm/react-native",
3
- "version": "3.0.0-beta.1",
3
+ "version": "3.0.0-beta.3",
4
4
  "description": "Set of utilities that allow any developer to build React Native location based apps using Situm's indoor positioning system.",
5
5
  "private": false,
6
6
  "repository": "https://github.com/situmtech/react-native",
@@ -69,29 +69,28 @@
69
69
  "@babel/runtime": "^7.22.5",
70
70
  "@react-native-community/eslint-config": "^3.2.0",
71
71
  "@types/jest": "^29.5.2",
72
- "@types/react": "^18.2.7",
73
72
  "@types/react-native": "0.72.2",
74
73
  "@types/react-test-renderer": "^18.0.0",
74
+ "@types/react": "^18.2.7",
75
75
  "babel-plugin-module-resolver": "^5.0.0",
76
76
  "commitlint": "^17.6.6",
77
- "eslint": "^8.44.0",
78
77
  "eslint-config-prettier": "^8.8.0",
79
78
  "eslint-plugin-functional": "^5.0.8",
80
79
  "eslint-plugin-import": "^2.27.5",
81
80
  "eslint-plugin-prettier": "^4.2.1",
82
81
  "eslint-plugin-simple-import-sort": "^10.0.0",
82
+ "eslint": "^8.44.0",
83
83
  "jest": "^29.5.0",
84
84
  "metro-react-native-babel-preset": "0.73.7",
85
85
  "prettier": "^2.8.8",
86
- "react": "^18.2.0",
87
- "react-native": "^0.72.1",
88
86
  "react-native-builder-bob": "^0.20.4",
87
+ "react-native": "^0.72.1",
89
88
  "react-test-renderer": "18.2.0",
89
+ "react": "^18.2.0",
90
90
  "typedoc": "^0.24.8",
91
91
  "typescript": "^5.0.4"
92
92
  },
93
93
  "dependencies": {
94
- "eslint-plugin-import": "^2.27.5",
95
94
  "react-dom": "^18.2.0",
96
95
  "react-native-permissions": "*",
97
96
  "react-native-webview": "*"
@@ -127,7 +126,7 @@
127
126
  ]
128
127
  },
129
128
  "sdkVersions": {
130
- "android": "2.88.0@aar",
131
- "ios": "2.61.0"
129
+ "android": "3.0.1@aar",
130
+ "ios": "2.61.1"
132
131
  }
133
132
  }
@@ -444,20 +444,20 @@ export type Circle = {
444
444
 
445
445
  export type LocationRequestOptions = {
446
446
  buildingIdentifier: number;
447
- interval: number;
448
- indoorProvider: string;
449
- useBle: boolean;
450
- useWifi: boolean;
451
- useGps: boolean;
452
- useBarometer: boolean;
453
- motionMode: string;
454
- useForegroundService: boolean;
455
- useDeadReckoning: boolean;
456
- outdoorLocationOptions: OutdoorLocationOptions;
457
- beaconFilters: BeaconFilter[];
458
- smallestDisplacement: number;
459
- realtimeUpdateInterval: string;
460
- autoEnableBleDuringPositioning: boolean;
447
+ interval?: number;
448
+ indoorProvider?: string;
449
+ useBle?: boolean;
450
+ useWifi?: boolean;
451
+ useGps?: boolean;
452
+ useBarometer?: boolean;
453
+ motionMode?: string;
454
+ useForegroundService?: boolean;
455
+ useDeadReckoning?: boolean;
456
+ outdoorLocationOptions?: OutdoorLocationOptions;
457
+ beaconFilters?: BeaconFilter[];
458
+ smallestDisplacement?: number;
459
+ realtimeUpdateInterval?: string;
460
+ autoEnableBleDuringPositioning?: boolean;
461
461
  };
462
462
 
463
463
  /**
@@ -555,10 +555,10 @@ export type DirectionsOptions = {
555
555
  */
556
556
 
557
557
  export type OutdoorLocationOptions = {
558
- continuousMode: boolean;
559
- userDefinedThreshold: boolean;
560
- burstInterval: number;
561
- averageSnrThreshold: number;
558
+ continuousMode?: boolean;
559
+ userDefinedThreshold?: boolean;
560
+ burstInterval?: number;
561
+ averageSnrThreshold?: number;
562
562
  };
563
563
 
564
564
  /**
@@ -193,7 +193,7 @@ const MapView = React.forwardRef<MapViewRef, MapViewProps>(
193
193
  }
194
194
  sendMessageToViewer(webViewRef.current, Mapper.selectPoi(poiId));
195
195
  },
196
- [pois, navigation.status]
196
+ [pois, navigation?.status]
197
197
  );
198
198
 
199
199
  useImperativeHandle(
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { useEffect, useRef, useState } from "react";
2
+ import { useContext, useEffect, useRef, useState } from "react";
3
3
 
4
4
  import {
5
5
  type Building,
@@ -41,6 +41,7 @@ import {
41
41
  setPois,
42
42
  setSdkInitialized,
43
43
  State,
44
+ UseSitumContext,
44
45
  } from "../store/index";
45
46
  import { useDispatch, useSelector } from "../store/utils";
46
47
 
@@ -63,7 +64,7 @@ export const useCallbackRef = <T>(fn: T, deps: any[]) => {
63
64
  return fnRef;
64
65
  };
65
66
 
66
- const useSitum = () => {
67
+ export const useSitumInternal = () => {
67
68
  const dispatch = useDispatch();
68
69
  const isSdkInitialized = useSelector(selectIsSdkInitialized);
69
70
  const user = useSelector(selectUser);
@@ -142,7 +143,7 @@ const useSitum = () => {
142
143
  // Cartography
143
144
  const initializeBuildings = async () =>
144
145
  new Promise<Building[]>((resolve, reject) => {
145
- console.debug("Retrieving buildings from Situm API");
146
+ console.debug("Situm > hook > Retrieving buildings from Situm API");
146
147
 
147
148
  SitumPlugin.fetchBuildings(
148
149
  (buildingArray: Building[]) => {
@@ -154,7 +155,7 @@ const useSitum = () => {
154
155
  console.error(
155
156
  `Situm > hook > Could not retrieve buildings: ${_error}`
156
157
  );
157
- reject(`Could not retrieve buildings: ${_error}`);
158
+ reject(`Situm > hook> Could not retrieve buildings: ${_error}`);
158
159
  dispatch(setError({ message: _error, code: 3011 } as SDKError));
159
160
  }
160
161
  );
@@ -236,11 +237,11 @@ const useSitum = () => {
236
237
  },
237
238
  locationOptions
238
239
  );
239
- console.debug(`Successfully started positioning`);
240
+ console.debug(`Situm > hook > Successfully started positioning`);
240
241
  };
241
242
 
242
243
  const stopPositioning = async () => {
243
- console.debug(`Stopping positioning ...`);
244
+ console.debug(`Situ> hook > Stopping positioning ...`);
244
245
  SitumPlugin.stopPositioning((success: boolean) => {
245
246
  if (success) {
246
247
  dispatch(resetLocation());
@@ -258,7 +259,7 @@ const useSitum = () => {
258
259
  to: Position,
259
260
  directionsOptions?: any
260
261
  ): Promise<State["directions"]> => {
261
- console.debug("Requesting directions");
262
+ console.debug("Situm > hook > Requesting directions");
262
263
  const fromPoint = {
263
264
  floorIdentifier: from.floorIdentifier,
264
265
  buildingIdentifier: from.buildingIdentifier,
@@ -306,7 +307,7 @@ const useSitum = () => {
306
307
 
307
308
  if (!poiDestination || (!poiOrigin && originId !== -1) || lockDirections) {
308
309
  console.debug(
309
- `Situm > hook >Could not compute route for origin: ${originId} or destination: ${destinationId} (lockDirections: ${lockDirections})`
310
+ `Situm > hook > Could not compute route for origin: ${originId} or destination: ${destinationId} (lockDirections: ${lockDirections})`
310
311
  );
311
312
  return;
312
313
  }
@@ -363,6 +364,7 @@ const useSitum = () => {
363
364
  originId: number;
364
365
  updateRoute?: boolean;
365
366
  }) => {
367
+ stopNavigation();
366
368
  calculateRoute({
367
369
  originId,
368
370
  destinationId,
@@ -413,7 +415,7 @@ const useSitum = () => {
413
415
  };
414
416
 
415
417
  const stopNavigation = (): void => {
416
- console.debug("Stopping navigation");
418
+ console.debug("Situm > hook > Stopping navigation");
417
419
  if (!navigation || navigation.status === NavigationStatus.STOP) {
418
420
  return;
419
421
  }
@@ -475,4 +477,14 @@ const useSitum = () => {
475
477
  };
476
478
  };
477
479
 
480
+ const useSitum = () => {
481
+ const context = useContext(UseSitumContext);
482
+
483
+ if (!context) {
484
+ throw new Error("Situm > hook > No SitumProvider found.");
485
+ }
486
+
487
+ return context.useSitum;
488
+ };
489
+
478
490
  export default useSitum;
@@ -10,7 +10,8 @@ import {
10
10
  SDKError,
11
11
  SDKNavigation,
12
12
  } from "../../sdk/types/index.d";
13
- import { createReducer } from "./utils";
13
+ import { useSitumInternal } from "../hooks";
14
+ import { createStore } from "./utils";
14
15
 
15
16
  // TODO: add types
16
17
  export type Directions = any;
@@ -52,48 +53,51 @@ export const SitumContext = createContext<
52
53
  { state: State; dispatch: React.Dispatch<(s: State) => State> } | undefined
53
54
  >(undefined);
54
55
 
55
- const Reducer = createReducer<State>({
56
- setWebViewRef: (state: State, payload: State["webViewRef"]) => {
57
- return { ...state, webViewRef: payload };
58
- },
59
- setSdkInitialized: (state: State, payload: State["sdkInitialized"]) => {
60
- return { ...state, sdkInitialized: payload };
61
- },
62
- setAuth: (state: State, payload: State["user"]) => {
63
- return { ...state, user: payload };
64
- },
65
- setLocation: (state: State, payload: State["location"]) => {
66
- return { ...state, location: payload };
67
- },
68
- setLocationStatus: (state: State, payload: LocationStatusName) => {
69
- return { ...state, location: { ...state.location, status: payload } };
70
- },
71
- resetLocation: (state: State) => {
72
- return {
73
- ...state,
74
- location: initialState.location,
75
- };
76
- },
77
- setBuildings: (state: State, payload: State["buildings"]) => {
78
- return { ...state, buildings: payload };
79
- },
80
- setCurrentBuilding: (state: State, payload: State["currentBuilding"]) => {
81
- return { ...state, currentBuilding: payload };
82
- },
83
- setPois: (state: State, payload: State["pois"]) => {
84
- return { ...state, pois: payload };
85
- },
86
- setDirections: (state: State, payload: State["directions"]) => {
87
- return { ...state, directions: payload };
88
- },
89
- setNavigation: (state: State, payload: State["navigation"]) => {
90
- return { ...state, navigation: payload };
91
- },
92
- setDestinationPoiID: (state: State, payload: State["destinationPoiID"]) => {
93
- return { ...state, destinationPoiID: payload };
94
- },
95
- setError: (state: State, payload: State["error"]) => {
96
- return { ...state, error: payload };
56
+ const store = createStore<State>({
57
+ initialState,
58
+ reducers: {
59
+ setWebViewRef: (state: State, payload: State["webViewRef"]) => {
60
+ return { ...state, webViewRef: payload };
61
+ },
62
+ setSdkInitialized: (state: State, payload: State["sdkInitialized"]) => {
63
+ return { ...state, sdkInitialized: payload };
64
+ },
65
+ setAuth: (state: State, payload: State["user"]) => {
66
+ return { ...state, user: payload };
67
+ },
68
+ setLocation: (state: State, payload: State["location"]) => {
69
+ return { ...state, location: payload };
70
+ },
71
+ setLocationStatus: (state: State, payload: LocationStatusName) => {
72
+ return { ...state, location: { ...state.location, status: payload } };
73
+ },
74
+ resetLocation: (state: State) => {
75
+ return {
76
+ ...state,
77
+ location: initialState.location,
78
+ };
79
+ },
80
+ setBuildings: (state: State, payload: State["buildings"]) => {
81
+ return { ...state, buildings: payload };
82
+ },
83
+ setCurrentBuilding: (state: State, payload: State["currentBuilding"]) => {
84
+ return { ...state, currentBuilding: payload };
85
+ },
86
+ setPois: (state: State, payload: State["pois"]) => {
87
+ return { ...state, pois: payload };
88
+ },
89
+ setDirections: (state: State, payload: State["directions"]) => {
90
+ return { ...state, directions: payload };
91
+ },
92
+ setNavigation: (state: State, payload: State["navigation"]) => {
93
+ return { ...state, navigation: payload };
94
+ },
95
+ setDestinationPoiID: (state: State, payload: State["destinationPoiID"]) => {
96
+ return { ...state, destinationPoiID: payload };
97
+ },
98
+ setError: (state: State, payload: State["error"]) => {
99
+ return { ...state, error: payload };
100
+ },
97
101
  },
98
102
  });
99
103
 
@@ -114,7 +118,7 @@ export const selectLocation = (state: State) => {
114
118
  };
115
119
 
116
120
  export const selectLocationStatus = (state: State) => {
117
- return state.location.status;
121
+ return state.location?.status;
118
122
  };
119
123
 
120
124
  export const selectBuildings = (state: State) => {
@@ -159,16 +163,40 @@ export const {
159
163
  setNavigation,
160
164
  setDestinationPoiID,
161
165
  setError,
162
- } = Reducer.actions;
166
+ } = store.actions;
167
+
168
+ /**
169
+ * Context specifically to store the only instance of our hook.
170
+ */
171
+ export const UseSitumContext = createContext<{ useSitum: any } | undefined>(
172
+ undefined
173
+ );
174
+
175
+ const UseSitumProvider: React.FC<{ children: React.ReactNode }> = ({
176
+ children,
177
+ }) => {
178
+ // TODO: if we have this, there is no need to have a context for the rest of the state
179
+ // as there is only one instance of the hook
180
+ const useSitum = useSitumInternal();
163
181
 
182
+ return (
183
+ <UseSitumContext.Provider value={{ useSitum }}>
184
+ {children}
185
+ </UseSitumContext.Provider>
186
+ );
187
+ };
188
+
189
+ /**
190
+ * Main context of the application, stores the plugins' state.
191
+ */
164
192
  const SitumProvider: React.FC<
165
193
  React.PropsWithChildren<{
166
194
  email?: string;
167
195
  apiKey?: string;
168
196
  }>
169
197
  > = ({ email, apiKey, children }) => {
170
- const [state, dispatch] = useReducer(Reducer.reducer, {
171
- ...initialState,
198
+ const [state, dispatch] = useReducer(store.reducer, {
199
+ ...store.initialState,
172
200
  user: { email, apiKey },
173
201
  });
174
202
 
@@ -179,7 +207,7 @@ const SitumProvider: React.FC<
179
207
  dispatch,
180
208
  }}
181
209
  >
182
- {children}
210
+ <UseSitumProvider>{children}</UseSitumProvider>
183
211
  </SitumContext.Provider>
184
212
  );
185
213
  };
@@ -3,20 +3,30 @@ import { useContext } from "react";
3
3
 
4
4
  import { SitumContext, State } from "./index";
5
5
 
6
- export const createReducer = <T>(
7
- reducers: Record<string, (state: T, payload: any) => T>
8
- ) => {
9
- // Actions
6
+ export const createReducer = <T>() => {
7
+ const reducer = (state: T, action: (state: T) => T): T => {
8
+ return action(state);
9
+ };
10
+ return reducer;
11
+ };
12
+
13
+ export const createStore = <T>({
14
+ initialState,
15
+ reducers,
16
+ }: {
17
+ initialState: T;
18
+ reducers: Record<string, (state: T, payload: any) => T>;
19
+ }) => {
10
20
  const actions = Object.keys(reducers).reduce((acc, r) => {
11
21
  acc[r] = (payload: any) => (state: T) => reducers[r](state, payload);
12
22
  return acc;
13
23
  }, {} as Record<string, (payload?: any) => (state: T) => T>);
14
24
 
15
- // Reducer
16
- const reducer = (state: T, action: (state: T) => T): T => {
17
- return action(state);
25
+ return {
26
+ initialState,
27
+ actions,
28
+ reducer: createReducer<T>(),
18
29
  };
19
- return { actions, reducer };
20
30
  };
21
31
 
22
32
  export const useSelector = (selector: (state: State) => any) => {