@statsig/react-native-core 0.0.1-beta.29 → 0.0.1-beta.30
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/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statsig/react-native-core",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.30",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@statsig/client-core": "0.0.1-beta.
|
|
6
|
-
"@statsig/react-bindings": "0.0.1-beta.
|
|
5
|
+
"@statsig/client-core": "0.0.1-beta.30",
|
|
6
|
+
"@statsig/react-bindings": "0.0.1-beta.30"
|
|
7
7
|
},
|
|
8
8
|
"peerDependencies": {
|
|
9
9
|
"react": "^16.6.3 || ^17.0.0 || ^18.0.0",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { StatsigClientInterface } from '@statsig/client-core';
|
|
2
2
|
export type StatsigAsyncCacheWarming = {
|
|
3
3
|
result: Promise<void>;
|
|
4
|
+
isResolved: boolean;
|
|
4
5
|
};
|
|
5
6
|
export declare function warmCachingFromAsyncStorage(client: StatsigClientInterface): StatsigAsyncCacheWarming;
|
|
@@ -12,20 +12,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.warmCachingFromAsyncStorage = void 0;
|
|
13
13
|
const client_core_1 = require("@statsig/client-core");
|
|
14
14
|
function warmCachingFromAsyncStorage(client) {
|
|
15
|
-
|
|
16
|
-
result:
|
|
15
|
+
const output = {
|
|
16
|
+
result: Promise.resolve(),
|
|
17
|
+
isResolved: false,
|
|
17
18
|
};
|
|
19
|
+
output.result = _loadCacheAsync(client.dataAdapter).finally(() => {
|
|
20
|
+
output.isResolved = true;
|
|
21
|
+
});
|
|
22
|
+
return output;
|
|
18
23
|
}
|
|
19
24
|
exports.warmCachingFromAsyncStorage = warmCachingFromAsyncStorage;
|
|
20
25
|
function _loadCacheAsync(adapter) {
|
|
21
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
-
const keys = yield client_core_1.Storage.
|
|
27
|
+
const keys = yield client_core_1.Storage._getAllKeys();
|
|
23
28
|
const results = {};
|
|
24
29
|
yield Promise.all(keys.map((key) => __awaiter(this, void 0, void 0, function* () {
|
|
25
30
|
if (!key.startsWith(client_core_1.DataAdapterCachePrefix)) {
|
|
26
31
|
return;
|
|
27
32
|
}
|
|
28
|
-
const cache = yield client_core_1.Storage.
|
|
33
|
+
const cache = yield client_core_1.Storage._getItem(key);
|
|
29
34
|
if (!cache) {
|
|
30
35
|
return;
|
|
31
36
|
}
|
|
@@ -6,17 +6,20 @@ const react_1 = require("react");
|
|
|
6
6
|
const client_core_1 = require("@statsig/client-core");
|
|
7
7
|
const react_bindings_1 = require("@statsig/react-bindings");
|
|
8
8
|
function StatsigProviderWithCacheWarming(props) {
|
|
9
|
-
const [isWarmed, setIsWarmed] = (0, react_1.useState)(
|
|
9
|
+
const [isWarmed, setIsWarmed] = (0, react_1.useState)(props.cacheWarming.isResolved);
|
|
10
10
|
(0, react_1.useEffect)(() => {
|
|
11
|
+
if (isWarmed) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
11
14
|
props.cacheWarming.result
|
|
12
15
|
.catch((e) => {
|
|
13
|
-
client_core_1.Log.error('
|
|
16
|
+
client_core_1.Log.error('Statig cache warming error', e);
|
|
14
17
|
})
|
|
15
18
|
.finally(() => {
|
|
16
19
|
props.client.initializeSync();
|
|
17
20
|
setIsWarmed(true);
|
|
18
21
|
});
|
|
19
|
-
}, [props.client, props.cacheWarming.result]);
|
|
22
|
+
}, [props.client, props.cacheWarming.result, isWarmed]);
|
|
20
23
|
if (!isWarmed) {
|
|
21
24
|
return null;
|
|
22
25
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
+
export type { StatsigProviderWithCacheWarmingProps } from './StatsigProviderWithCacheWarming';
|
|
2
|
+
export { StatsigProviderWithCacheWarming } from './StatsigProviderWithCacheWarming';
|
|
1
3
|
export * from './AsyncStorageWarming';
|
|
2
4
|
export * from './StatsigProviderWithCacheWarming';
|
package/src/index.js
CHANGED
|
@@ -14,10 +14,19 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.StatsigProviderWithCacheWarming = void 0;
|
|
17
18
|
const async_storage_1 = require("@react-native-async-storage/async-storage");
|
|
18
19
|
const react_native_1 = require("react-native");
|
|
19
20
|
const client_core_1 = require("@statsig/client-core");
|
|
20
|
-
client_core_1.Storage.
|
|
21
|
-
|
|
21
|
+
client_core_1.Storage._setProvider({
|
|
22
|
+
_getProviderName: () => 'AsyncStorage',
|
|
23
|
+
_getItem: (key) => async_storage_1.default.getItem(key),
|
|
24
|
+
_setItem: (key, value) => async_storage_1.default.setItem(key, value),
|
|
25
|
+
_removeItem: (key) => async_storage_1.default.removeItem(key),
|
|
26
|
+
_getAllKeys: () => async_storage_1.default.getAllKeys(),
|
|
27
|
+
});
|
|
28
|
+
react_native_1.AppState.addEventListener('change', (nextAppState) => (0, client_core_1._notifyVisibilityChanged)(nextAppState === 'active' ? 'foreground' : 'background'));
|
|
29
|
+
var StatsigProviderWithCacheWarming_1 = require("./StatsigProviderWithCacheWarming");
|
|
30
|
+
Object.defineProperty(exports, "StatsigProviderWithCacheWarming", { enumerable: true, get: function () { return StatsigProviderWithCacheWarming_1.StatsigProviderWithCacheWarming; } });
|
|
22
31
|
__exportStar(require("./AsyncStorageWarming"), exports);
|
|
23
32
|
__exportStar(require("./StatsigProviderWithCacheWarming"), exports);
|