@applicaster/zapp-react-dom-app 12.0.2-rc.0 → 13.0.0-alpha.1552112220
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/App/InteractionManager/index.tsx +62 -41
- package/App/Loader/SplashLoader.js +8 -7
- package/App/Loader/loadSessionStorageData.js +0 -1
- package/App/Loader/utils/platform.js +46 -27
- package/App/Router/index.js +6 -7
- package/App/Splash/Spinner.js +0 -1
- package/App/Splash/Splash.js +9 -6
- package/Polyfills/Storage/index.js +15 -26
- package/package.json +6 -6
|
@@ -23,8 +23,6 @@ import {
|
|
|
23
23
|
|
|
24
24
|
import { showConfirmationDialog } from "@applicaster/zapp-react-native-utils/alertUtils";
|
|
25
25
|
|
|
26
|
-
import { withUseSeek } from "@applicaster/zapp-react-native-utils/reactHooks/player";
|
|
27
|
-
|
|
28
26
|
import {
|
|
29
27
|
DISPLAY_STATES,
|
|
30
28
|
DisplayStateContext,
|
|
@@ -48,6 +46,7 @@ import {
|
|
|
48
46
|
|
|
49
47
|
import { OnScreenKeyboard } from "@applicaster/zapp-react-dom-ui-components/Components/OnScreenKeyboard";
|
|
50
48
|
import { KeyboardLongPressManager } from "@applicaster/zapp-react-dom-ui-components/Utils/KeyboardLongPressManager";
|
|
49
|
+
import { KeyInputHandler } from "@applicaster/zapp-react-native-utils/appUtils/keyInputHandler/KeyInputHandler";
|
|
51
50
|
|
|
52
51
|
const { withXray } = getXray();
|
|
53
52
|
const globalAny: any = global;
|
|
@@ -62,14 +61,6 @@ type Props = {
|
|
|
62
61
|
navigator: QuickBrickAppNavigator;
|
|
63
62
|
rivers: {};
|
|
64
63
|
xray: XRayContext;
|
|
65
|
-
seekMethods: {
|
|
66
|
-
onRewindPress: () => void;
|
|
67
|
-
onRewindLongPress: () => void;
|
|
68
|
-
onForwardPress: () => void;
|
|
69
|
-
onForwardLongPress: () => void;
|
|
70
|
-
onRewindPressOut: () => void;
|
|
71
|
-
onForwardPressOut: () => void;
|
|
72
|
-
};
|
|
73
64
|
confirmDialog: typeof confirmationDialogStore;
|
|
74
65
|
};
|
|
75
66
|
|
|
@@ -181,6 +172,11 @@ class InteractionManagerClass extends React.Component<Props, State> {
|
|
|
181
172
|
|
|
182
173
|
window.addEventListener("onLongPress", this.handleLongPress.bind(this));
|
|
183
174
|
|
|
175
|
+
window.addEventListener(
|
|
176
|
+
"onPressRelease",
|
|
177
|
+
this.handleLongPressRelease.bind(this)
|
|
178
|
+
);
|
|
179
|
+
|
|
184
180
|
window.addEventListener(
|
|
185
181
|
"onLongPressRelease",
|
|
186
182
|
this.handleLongPressRelease.bind(this)
|
|
@@ -339,9 +335,34 @@ class InteractionManagerClass extends React.Component<Props, State> {
|
|
|
339
335
|
}
|
|
340
336
|
|
|
341
337
|
onKeyUp(event: KeyboardEvent) {
|
|
338
|
+
const { setDisplayState } = this.props;
|
|
339
|
+
|
|
342
340
|
if (this.keySupportsLongPress(event)) {
|
|
343
341
|
this.longPressDetector.endKeyPressMonitoring(event.code);
|
|
344
342
|
}
|
|
343
|
+
|
|
344
|
+
if (
|
|
345
|
+
keyCode(event).matches(KEYS.Enter) ||
|
|
346
|
+
(__DEV__ && keyCode(event).matches(KEYS.X))
|
|
347
|
+
) {
|
|
348
|
+
focusManager.pressOut();
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
if (
|
|
352
|
+
keyCode(event).matches(KEYS.Forward) ||
|
|
353
|
+
(__DEV__ && keyCode(event).matches(KEYS.C))
|
|
354
|
+
) {
|
|
355
|
+
setDisplayState(DISPLAY_STATES.HUD);
|
|
356
|
+
KeyInputHandler.getInstance().onForwardPressOut();
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
if (
|
|
360
|
+
keyCode(event).matches(KEYS.Rewind) ||
|
|
361
|
+
(__DEV__ && keyCode(event).matches(KEYS.Z))
|
|
362
|
+
) {
|
|
363
|
+
setDisplayState(DISPLAY_STATES.HUD);
|
|
364
|
+
KeyInputHandler.getInstance().onRewindPressOut();
|
|
365
|
+
}
|
|
345
366
|
}
|
|
346
367
|
|
|
347
368
|
onKeyDown(event) {
|
|
@@ -372,6 +393,7 @@ class InteractionManagerClass extends React.Component<Props, State> {
|
|
|
372
393
|
When the player is displayed, we listen to Native Play / Pause / Stop
|
|
373
394
|
buttons. Any other key press will display the transport controls
|
|
374
395
|
*/
|
|
396
|
+
|
|
375
397
|
if (
|
|
376
398
|
displayState === DISPLAY_STATES.PLAYER ||
|
|
377
399
|
displayState === DISPLAY_STATES.HUD
|
|
@@ -404,16 +426,22 @@ class InteractionManagerClass extends React.Component<Props, State> {
|
|
|
404
426
|
return;
|
|
405
427
|
}
|
|
406
428
|
|
|
407
|
-
if (
|
|
429
|
+
if (
|
|
430
|
+
keyCode(event).matches(KEYS.Forward) ||
|
|
431
|
+
(__DEV__ && keyCode(event).matches(KEYS.C))
|
|
432
|
+
) {
|
|
408
433
|
setDisplayState(DISPLAY_STATES.HUD);
|
|
409
|
-
|
|
434
|
+
KeyInputHandler.getInstance().onForwardPress();
|
|
410
435
|
|
|
411
436
|
return;
|
|
412
437
|
}
|
|
413
438
|
|
|
414
|
-
if (
|
|
439
|
+
if (
|
|
440
|
+
keyCode(event).matches(KEYS.Rewind) ||
|
|
441
|
+
(__DEV__ && keyCode(event).matches(KEYS.Z))
|
|
442
|
+
) {
|
|
415
443
|
setDisplayState(DISPLAY_STATES.HUD);
|
|
416
|
-
|
|
444
|
+
KeyInputHandler.getInstance().onRewindPress();
|
|
417
445
|
|
|
418
446
|
return;
|
|
419
447
|
}
|
|
@@ -451,7 +479,9 @@ class InteractionManagerClass extends React.Component<Props, State> {
|
|
|
451
479
|
const isHookInHomescreen = entryData?.payload?.home;
|
|
452
480
|
|
|
453
481
|
const isHookFlowBlocker =
|
|
454
|
-
entryData?.hookPlugin?.module?.isFlowBlocker
|
|
482
|
+
typeof entryData?.hookPlugin?.module?.isFlowBlocker === "function"
|
|
483
|
+
? entryData?.hookPlugin?.module?.isFlowBlocker()
|
|
484
|
+
: entryData?.hookPlugin?.module?.isFlowBlocker;
|
|
455
485
|
|
|
456
486
|
if (isHookInHomescreen && isHookFlowBlocker) {
|
|
457
487
|
this.platformBack();
|
|
@@ -473,7 +503,10 @@ class InteractionManagerClass extends React.Component<Props, State> {
|
|
|
473
503
|
}
|
|
474
504
|
}
|
|
475
505
|
|
|
476
|
-
if (
|
|
506
|
+
if (
|
|
507
|
+
keyCode(event).matches(KEYS.Enter) ||
|
|
508
|
+
(__DEV__ && keyCode(event).matches(KEYS.X))
|
|
509
|
+
) {
|
|
477
510
|
if (displayState === DISPLAY_STATES.PLAYER) {
|
|
478
511
|
setDisplayState(DISPLAY_STATES.HUD);
|
|
479
512
|
} else {
|
|
@@ -688,54 +721,43 @@ class InteractionManagerClass extends React.Component<Props, State> {
|
|
|
688
721
|
}, SEQUENCE_ENTRY_TIME);
|
|
689
722
|
}
|
|
690
723
|
|
|
724
|
+
// TODO: Delete it on next PR if not needed
|
|
691
725
|
private handleLongPress = (event: CustomEvent) => {
|
|
692
726
|
const { keyCode } = event.detail;
|
|
693
|
-
const { displayState } = this.props;
|
|
694
|
-
const playerState = displayState === DISPLAY_STATES.PLAYER;
|
|
695
|
-
const hudState = displayState === DISPLAY_STATES.HUD;
|
|
696
|
-
const playbackState = playerState || hudState;
|
|
697
727
|
this.longPressActive = true;
|
|
698
728
|
this.cancelHudTimeout();
|
|
699
729
|
|
|
700
730
|
switch (keyCode) {
|
|
701
|
-
case KEYS.Forward.code:
|
|
702
|
-
playbackState && this.props.seekMethods.onForwardLongPress();
|
|
703
|
-
break;
|
|
704
|
-
|
|
705
|
-
case KEYS.Rewind.code:
|
|
706
|
-
playbackState && this.props.seekMethods.onRewindLongPress();
|
|
707
|
-
break;
|
|
708
|
-
|
|
709
731
|
case KEYS.Enter.code:
|
|
732
|
+
case KEYS.X.code:
|
|
710
733
|
focusManager.longPress();
|
|
711
734
|
break;
|
|
712
735
|
}
|
|
713
736
|
};
|
|
714
737
|
|
|
738
|
+
// TODO: Delete it on next PR if not needed
|
|
715
739
|
private handleLongPressRelease = (event: CustomEvent) => {
|
|
716
740
|
const { keyCode } = event.detail;
|
|
717
741
|
this.longPressActive = false;
|
|
718
742
|
this.resetHudTimeout();
|
|
719
743
|
|
|
720
744
|
switch (keyCode) {
|
|
721
|
-
case KEYS.Forward.code:
|
|
722
|
-
this.props.seekMethods.onForwardPressOut();
|
|
723
|
-
break;
|
|
724
|
-
|
|
725
|
-
case KEYS.Rewind.code:
|
|
726
|
-
this.props.seekMethods.onRewindPressOut();
|
|
727
|
-
break;
|
|
728
|
-
|
|
729
745
|
case KEYS.Enter.code:
|
|
730
|
-
|
|
746
|
+
case KEYS.X.code:
|
|
747
|
+
// focusManager.pressOut();
|
|
731
748
|
break;
|
|
732
749
|
}
|
|
733
750
|
};
|
|
734
751
|
|
|
735
752
|
private keySupportsLongPress(event: KeyboardEvent): boolean {
|
|
736
|
-
return [
|
|
737
|
-
|
|
738
|
-
|
|
753
|
+
return [
|
|
754
|
+
KEYS.Forward.code,
|
|
755
|
+
KEYS.Rewind.code,
|
|
756
|
+
KEYS.Enter.code,
|
|
757
|
+
KEYS.Z.code,
|
|
758
|
+
KEYS.X.code,
|
|
759
|
+
KEYS.C.code,
|
|
760
|
+
].includes(event.code);
|
|
739
761
|
}
|
|
740
762
|
|
|
741
763
|
render() {
|
|
@@ -754,7 +776,6 @@ class InteractionManagerClass extends React.Component<Props, State> {
|
|
|
754
776
|
|
|
755
777
|
export const InteractionManager = R.compose(
|
|
756
778
|
withNavigator,
|
|
757
|
-
withUseSeek,
|
|
758
779
|
withXray,
|
|
759
780
|
connectToStore(R.pick(["rivers"])),
|
|
760
781
|
PlayerContentContext.withConsumer,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
/* global tizen */
|
|
3
2
|
import * as React from "react";
|
|
4
3
|
import * as R from "ramda";
|
|
4
|
+
import PropTypes from "prop-types";
|
|
5
5
|
|
|
6
6
|
import { connectToStore } from "@applicaster/zapp-react-native-redux";
|
|
7
7
|
import { QUICK_BRICK_EVENTS } from "@applicaster/zapp-react-native-bridge/QuickBrick";
|
|
@@ -9,17 +9,12 @@ import { QUICK_BRICK_EVENTS } from "@applicaster/zapp-react-native-bridge/QuickB
|
|
|
9
9
|
import { QuickBrickEvents } from "../../Polyfills/QuickBrickCommunicationModule";
|
|
10
10
|
import { Splash } from "../Splash";
|
|
11
11
|
|
|
12
|
-
type Props = {
|
|
13
|
-
appLaunched: boolean,
|
|
14
|
-
children: any,
|
|
15
|
-
};
|
|
16
|
-
|
|
17
12
|
const getAppLaunched = R.compose(
|
|
18
13
|
R.assoc("appLaunched", R.__, {}),
|
|
19
14
|
R.path(["appState", "appLaunched"])
|
|
20
15
|
);
|
|
21
16
|
|
|
22
|
-
class SplashHandler extends React.Component
|
|
17
|
+
class SplashHandler extends React.Component {
|
|
23
18
|
constructor(props) {
|
|
24
19
|
super(props);
|
|
25
20
|
|
|
@@ -76,6 +71,12 @@ class SplashHandler extends React.Component<Props> {
|
|
|
76
71
|
}
|
|
77
72
|
}
|
|
78
73
|
|
|
74
|
+
SplashHandler.propTypes = {
|
|
75
|
+
appLaunched: PropTypes.bool.isRequired,
|
|
76
|
+
children: PropTypes.node.isRequired,
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
SplashHandler.shouldShowSplash = true;
|
|
79
80
|
SplashHandler.shouldShowSplash = true;
|
|
80
81
|
|
|
81
82
|
export const SplashLoader = connectToStore(getAppLaunched)(SplashHandler);
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
/* global webOS */
|
|
3
2
|
/* global tizen */
|
|
4
3
|
/* eslint-disable no-console */
|
|
@@ -12,11 +11,28 @@ import {
|
|
|
12
11
|
PLATFORMS,
|
|
13
12
|
} from "./const";
|
|
14
13
|
|
|
14
|
+
/**
|
|
15
|
+
* @typedef {"tv" | "web" | "other"} DeviceType
|
|
16
|
+
* @typedef {"samsung_tv" | "lg_tv" | unknown} CustomPlatformTypes
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Retrieves the user agent string from the browser or global navigator.
|
|
21
|
+
* @returns {string} The user agent string.
|
|
22
|
+
*/
|
|
15
23
|
export const getUserAgent = () =>
|
|
16
24
|
window?.navigator?.userAgent || global?.navigator?.userAgent;
|
|
17
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Checks if the device is HD (1280 width).
|
|
28
|
+
* @returns {boolean} True if the device is HD, false otherwise.
|
|
29
|
+
*/
|
|
18
30
|
export const isHD = () => window.innerWidth === 1280;
|
|
19
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Checks if the platform is LG.
|
|
34
|
+
* @returns {boolean} True if the platform is LG, false otherwise.
|
|
35
|
+
*/
|
|
20
36
|
export const isLgPlatform = () => {
|
|
21
37
|
const userAgent = getUserAgent();
|
|
22
38
|
|
|
@@ -24,10 +40,13 @@ export const isLgPlatform = () => {
|
|
|
24
40
|
return false;
|
|
25
41
|
}
|
|
26
42
|
|
|
27
|
-
// Note: LG uses the number 0 in their userAgent, possibly because of Palm WebOS
|
|
28
43
|
return hasWebOS || userAgent.includes(PLATFORMS.webos);
|
|
29
44
|
};
|
|
30
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Checks if the platform is Samsung.
|
|
48
|
+
* @returns {boolean} True if the platform is Samsung, false otherwise.
|
|
49
|
+
*/
|
|
31
50
|
export const isSamsungPlatform = () => {
|
|
32
51
|
const userAgent = getUserAgent();
|
|
33
52
|
|
|
@@ -43,42 +62,39 @@ export const isSamsungPlatform = () => {
|
|
|
43
62
|
};
|
|
44
63
|
|
|
45
64
|
/**
|
|
46
|
-
* Checks if
|
|
47
|
-
*
|
|
48
|
-
* Use this method when you need to identify the platform on runtime
|
|
49
|
-
* before the VIZIO Companion Library has loaded
|
|
65
|
+
* Checks if the platform is Vizio by using the user agent string.
|
|
66
|
+
* @returns {boolean} True if the platform is Vizio, false otherwise.
|
|
50
67
|
*/
|
|
51
68
|
export const isVizioPlatform = () => {
|
|
52
69
|
const userAgent = getUserAgent();
|
|
53
70
|
|
|
54
|
-
|
|
71
|
+
return (
|
|
55
72
|
userAgent.includes(PLATFORMS.vizio) ||
|
|
56
73
|
userAgent.includes(PLATFORMS.smartcast) ||
|
|
57
|
-
userAgent.includes(PLATFORMS.conjure)
|
|
58
|
-
|
|
59
|
-
return isVizioAgent;
|
|
74
|
+
userAgent.includes(PLATFORMS.conjure)
|
|
75
|
+
);
|
|
60
76
|
};
|
|
61
77
|
|
|
62
78
|
/**
|
|
63
|
-
* Checks if
|
|
64
|
-
*
|
|
65
|
-
* because it mainly checks whether we have access to apis, which may not be available yet
|
|
79
|
+
* Checks if the Vizio APIs are available.
|
|
80
|
+
* @returns {boolean} True if the Vizio APIs are available, false otherwise.
|
|
66
81
|
*/
|
|
67
82
|
export const hasVizioAPIs = () => {
|
|
68
|
-
|
|
83
|
+
return (
|
|
69
84
|
typeof window.VIZIO !== "undefined" &&
|
|
70
|
-
window?.applicaster?.vizioLibraryDidLoad
|
|
71
|
-
|
|
72
|
-
return hasAPIs;
|
|
85
|
+
window?.applicaster?.vizioLibraryDidLoad
|
|
86
|
+
);
|
|
73
87
|
};
|
|
74
88
|
|
|
75
89
|
/**
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
* @returns {"tv" | "web" | "other"} value
|
|
90
|
+
* Determines the device type based on the platform.
|
|
91
|
+
* @returns {DeviceType} The device type ("tv", "web", or "other").
|
|
79
92
|
*/
|
|
80
93
|
export const getDeviceType = () => {
|
|
81
|
-
|
|
94
|
+
/** @type {CustomPlatformTypes} */
|
|
95
|
+
const platformOS = Platform.OS;
|
|
96
|
+
|
|
97
|
+
switch (platformOS) {
|
|
82
98
|
case "samsung_tv":
|
|
83
99
|
return isSamsungPlatform() ? "tv" : "web";
|
|
84
100
|
case "lg_tv":
|
|
@@ -89,14 +105,15 @@ export const getDeviceType = () => {
|
|
|
89
105
|
};
|
|
90
106
|
|
|
91
107
|
/**
|
|
92
|
-
*
|
|
93
|
-
* @param {string} key - key
|
|
108
|
+
* Renames keys based on a predefined map.
|
|
109
|
+
* @param {string} key - The key to rename.
|
|
110
|
+
* @returns {string} The renamed key.
|
|
94
111
|
*/
|
|
95
112
|
export const renameKeys = (key) => desiredKeysMap?.[key] || key;
|
|
96
113
|
|
|
97
114
|
/**
|
|
98
|
-
*
|
|
99
|
-
*
|
|
115
|
+
* Retrieves the connection info from WebOS.
|
|
116
|
+
* @returns {Promise<{networkType: string} | null>} A promise that resolves with the connection info or null.
|
|
100
117
|
*/
|
|
101
118
|
export const getWebOSConnectionInfo = () => {
|
|
102
119
|
return new Promise((resolve, reject) => {
|
|
@@ -109,7 +126,6 @@ export const getWebOSConnectionInfo = () => {
|
|
|
109
126
|
webOS.service.request("luna://com.palm.connectionmanager", {
|
|
110
127
|
method: "getStatus",
|
|
111
128
|
parameters: { subscribe: false },
|
|
112
|
-
|
|
113
129
|
onSuccess: (args) => {
|
|
114
130
|
const types = Object.keys(args)
|
|
115
131
|
.filter((key) => args[key].state === "connected")
|
|
@@ -117,7 +133,6 @@ export const getWebOSConnectionInfo = () => {
|
|
|
117
133
|
|
|
118
134
|
resolve({ networkType: types });
|
|
119
135
|
},
|
|
120
|
-
|
|
121
136
|
onFailure: (error) => {
|
|
122
137
|
console.error(
|
|
123
138
|
"getWebOSConnectionInfo: There was an error getting connection info",
|
|
@@ -130,6 +145,10 @@ export const getWebOSConnectionInfo = () => {
|
|
|
130
145
|
});
|
|
131
146
|
};
|
|
132
147
|
|
|
148
|
+
/**
|
|
149
|
+
* Retrieves the connection info from Tizen.
|
|
150
|
+
* @returns {Promise<{networkType: string} | null>} A promise that resolves with the connection info or null.
|
|
151
|
+
*/
|
|
133
152
|
export const getTizenConnectionInfo = () => {
|
|
134
153
|
return new Promise((resolve, reject) => {
|
|
135
154
|
if (!isSamsungPlatform) {
|
package/App/Router/index.js
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
1
|
import React from "react";
|
|
2
|
+
import PropTypes from "prop-types";
|
|
4
3
|
|
|
5
4
|
import { Router } from "react-router";
|
|
6
5
|
import { createMemoryHistory } from "history";
|
|
7
6
|
|
|
8
|
-
type Props = {
|
|
9
|
-
children: any,
|
|
10
|
-
};
|
|
11
|
-
|
|
12
7
|
const history = createMemoryHistory();
|
|
13
8
|
|
|
14
|
-
export const ZappDomRouter = ({ children, ...otherProps }
|
|
9
|
+
export const ZappDomRouter = ({ children, ...otherProps }) => (
|
|
15
10
|
<Router history={history} {...otherProps}>
|
|
16
11
|
{children}
|
|
17
12
|
</Router>
|
|
18
13
|
);
|
|
14
|
+
|
|
15
|
+
ZappDomRouter.propTypes = {
|
|
16
|
+
children: PropTypes.node.isRequired,
|
|
17
|
+
};
|
package/App/Splash/Spinner.js
CHANGED
package/App/Splash/Splash.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import React from "react";
|
|
3
2
|
|
|
4
|
-
import
|
|
3
|
+
import PropTypes from "prop-types";
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
remoteConfigurations: any,
|
|
8
|
-
};
|
|
5
|
+
import { verifyAssets } from "@applicaster/zapp-react-dom-ui-components/Helpers/protectHelper";
|
|
9
6
|
|
|
10
|
-
export const SplashComponent = ({ remoteConfigurations }
|
|
7
|
+
export const SplashComponent = ({ remoteConfigurations }) => {
|
|
11
8
|
const image = verifyAssets(remoteConfigurations.assets, [
|
|
12
9
|
"universal",
|
|
13
10
|
"splash",
|
|
@@ -19,3 +16,9 @@ export const SplashComponent = ({ remoteConfigurations }: Props) => {
|
|
|
19
16
|
</div>
|
|
20
17
|
);
|
|
21
18
|
};
|
|
19
|
+
|
|
20
|
+
SplashComponent.propTypes = {
|
|
21
|
+
remoteConfigurations: PropTypes.shape({
|
|
22
|
+
assets: PropTypes.object.isRequired,
|
|
23
|
+
}).isRequired,
|
|
24
|
+
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import * as R from "ramda";
|
|
3
2
|
|
|
4
3
|
import {
|
|
@@ -7,11 +6,11 @@ import {
|
|
|
7
6
|
} from "@applicaster/zapp-react-native-utils/functionUtils";
|
|
8
7
|
import { mapKeys } from "@applicaster/zapp-react-native-utils/objectUtils";
|
|
9
8
|
|
|
10
|
-
export type StorageI = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
};
|
|
9
|
+
// export type StorageI = {
|
|
10
|
+
// setItem: (string, string, ?string) => Promise<any>,
|
|
11
|
+
// getItem: (string, ?string) => Promise<any>,
|
|
12
|
+
// getAllItems: () => Promise<any>,
|
|
13
|
+
// };
|
|
15
14
|
|
|
16
15
|
export const STORAGE_TYPES = ["localStorage", "sessionStorage"];
|
|
17
16
|
|
|
@@ -25,10 +24,7 @@ const NAMESPACE_SEPARATOR = "_::_";
|
|
|
25
24
|
* @param {?String} namespace
|
|
26
25
|
* @returns {String}
|
|
27
26
|
*/
|
|
28
|
-
export function applyNamespaceToKeyName(
|
|
29
|
-
key: string,
|
|
30
|
-
namespace: ?string
|
|
31
|
-
): string {
|
|
27
|
+
export function applyNamespaceToKeyName(key, namespace) {
|
|
32
28
|
return namespace ? `${namespace}${NAMESPACE_SEPARATOR}${key}` : key;
|
|
33
29
|
}
|
|
34
30
|
|
|
@@ -40,7 +36,7 @@ export function applyNamespaceToKeyName(
|
|
|
40
36
|
* @param {Function} fn function to run
|
|
41
37
|
* @returns {Promise}
|
|
42
38
|
*/
|
|
43
|
-
function tryAndResolve(fn
|
|
39
|
+
function tryAndResolve(fn) {
|
|
44
40
|
try {
|
|
45
41
|
return R.compose(
|
|
46
42
|
(value) => Promise.resolve(value),
|
|
@@ -62,7 +58,7 @@ function tryAndResolve(fn: (any) => any): Promise<any> {
|
|
|
62
58
|
* @returns {Function} storageObject.callMethod: invokes methods on the storage object
|
|
63
59
|
* @returns {Function} storageObject.getKeys: returns all existing keys in the storage object
|
|
64
60
|
*/
|
|
65
|
-
function getStorageObject(type
|
|
61
|
+
function getStorageObject(type) {
|
|
66
62
|
const storage = R.prop(type, window);
|
|
67
63
|
|
|
68
64
|
if (!R.includes(type, STORAGE_TYPES) || !storage) {
|
|
@@ -80,7 +76,7 @@ function getStorageObject(type: string): (any) => void | Promise<any> {
|
|
|
80
76
|
* @param {Array} args array of arguments to use when invoking the method
|
|
81
77
|
* @returns response of the method call
|
|
82
78
|
*/
|
|
83
|
-
function callMethod(method
|
|
79
|
+
function callMethod(method, ...args) {
|
|
84
80
|
return storage[method](...args);
|
|
85
81
|
}
|
|
86
82
|
|
|
@@ -107,9 +103,9 @@ function getStorageObject(type: string): (any) => void | Promise<any> {
|
|
|
107
103
|
/**
|
|
108
104
|
* returns an object to interact with a storage module (localStorage or sessionStorage)
|
|
109
105
|
* @param {String} type of storage
|
|
110
|
-
* @returns {
|
|
106
|
+
* @returns {StorageI}
|
|
111
107
|
*/
|
|
112
|
-
export function getStorageModule(type
|
|
108
|
+
export function getStorageModule(type) {
|
|
113
109
|
const Storage = getStorageObject(type);
|
|
114
110
|
|
|
115
111
|
/**
|
|
@@ -120,11 +116,7 @@ export function getStorageModule(type: string): StorageI {
|
|
|
120
116
|
* @param {?String} namespace
|
|
121
117
|
* @returns {Promise<Boolean|Error>}
|
|
122
118
|
*/
|
|
123
|
-
function setItem(
|
|
124
|
-
key: string,
|
|
125
|
-
value: string,
|
|
126
|
-
namespace: ?string = DEFAULT_NAMESPACE
|
|
127
|
-
): Promise<boolean | Error> {
|
|
119
|
+
function setItem(key, value, namespace = DEFAULT_NAMESPACE) {
|
|
128
120
|
const keyName = applyNamespaceToKeyName(
|
|
129
121
|
key,
|
|
130
122
|
namespace || DEFAULT_NAMESPACE
|
|
@@ -144,10 +136,7 @@ export function getStorageModule(type: string): StorageI {
|
|
|
144
136
|
* @param {?String} namespace
|
|
145
137
|
* @returns {Promise<Any|Error>}
|
|
146
138
|
*/
|
|
147
|
-
function getItem(
|
|
148
|
-
key: string,
|
|
149
|
-
namespace: ?string = DEFAULT_NAMESPACE
|
|
150
|
-
): Promise<any> {
|
|
139
|
+
function getItem(key, namespace = DEFAULT_NAMESPACE) {
|
|
151
140
|
const keyName = applyNamespaceToKeyName(
|
|
152
141
|
key,
|
|
153
142
|
namespace || DEFAULT_NAMESPACE
|
|
@@ -163,7 +152,7 @@ export function getStorageModule(type: string): StorageI {
|
|
|
163
152
|
* @param {?String} namespace
|
|
164
153
|
* @returns {Promise<Boolean|Error>}
|
|
165
154
|
*/
|
|
166
|
-
function removeItem(key
|
|
155
|
+
function removeItem(key, namespace = DEFAULT_NAMESPACE) {
|
|
167
156
|
const keyName = applyNamespaceToKeyName(key, namespace);
|
|
168
157
|
|
|
169
158
|
return tryAndResolve(() => Storage.callMethod("removeItem", keyName));
|
|
@@ -174,7 +163,7 @@ export function getStorageModule(type: string): StorageI {
|
|
|
174
163
|
* @param {?String} namespace
|
|
175
164
|
* @returns {Promise<Object|Error>}
|
|
176
165
|
*/
|
|
177
|
-
function getAllItems(namespace
|
|
166
|
+
function getAllItems(namespace = null) {
|
|
178
167
|
return tryAndResolve(() => {
|
|
179
168
|
const keys = Storage.getKeys();
|
|
180
169
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-dom-app",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "13.0.0-alpha.1552112220",
|
|
4
4
|
"description": "Zapp App Component for Applicaster's Quick Brick React Native App",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
},
|
|
23
23
|
"homepage": "https://github.com/applicaster/zapp-react-dom-app#readme",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@applicaster/zapp-react-dom-ui-components": "
|
|
26
|
-
"@applicaster/zapp-react-native-bridge": "
|
|
27
|
-
"@applicaster/zapp-react-native-redux": "
|
|
28
|
-
"@applicaster/zapp-react-native-ui-components": "
|
|
29
|
-
"@applicaster/zapp-react-native-utils": "
|
|
25
|
+
"@applicaster/zapp-react-dom-ui-components": "13.0.0-alpha.1552112220",
|
|
26
|
+
"@applicaster/zapp-react-native-bridge": "13.0.0-alpha.1552112220",
|
|
27
|
+
"@applicaster/zapp-react-native-redux": "13.0.0-alpha.1552112220",
|
|
28
|
+
"@applicaster/zapp-react-native-ui-components": "13.0.0-alpha.1552112220",
|
|
29
|
+
"@applicaster/zapp-react-native-utils": "13.0.0-alpha.1552112220",
|
|
30
30
|
"abortcontroller-polyfill": "^1.7.5",
|
|
31
31
|
"history": "^4.7.2",
|
|
32
32
|
"react-router-dom": "^5.1.2",
|