Extract Storage and apply it in actions
This commit is contained in:
parent
f39baf5059
commit
63b5077d7a
79
dist/Storage.js
vendored
Normal file
79
dist/Storage.js
vendored
Normal file
|
@ -0,0 +1,79 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var react_native_1 = require("react-native");
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Rip this out into its own npm package:
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
var AsyncLocalStorage = {
|
||||
getItem: function (key) { return new Promise(function (resolve, reject) {
|
||||
try {
|
||||
var value = window.localStorage.getItem(key);
|
||||
resolve(value);
|
||||
}
|
||||
catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
}); },
|
||||
setItem: function (key, value) { return new Promise(function (resolve, reject) {
|
||||
try {
|
||||
window.localStorage.setItem(key, value);
|
||||
resolve(value);
|
||||
}
|
||||
catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
}); },
|
||||
removeItem: function (key) { return new Promise(function (resolve, reject) {
|
||||
try {
|
||||
var value = window.localStorage.getItem(key);
|
||||
window.localStorage.removeItem(key);
|
||||
resolve(value);
|
||||
}
|
||||
catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
}); },
|
||||
clear: function () { return new Promise(function (resolve, reject) {
|
||||
try {
|
||||
window.localStorage.clear();
|
||||
resolve(true);
|
||||
}
|
||||
catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
}); },
|
||||
getAllKeys: function () { return new Promise(function (resolve, reject) {
|
||||
try {
|
||||
var allKeys = Object.keys(window.localStorage);
|
||||
resolve(allKeys);
|
||||
}
|
||||
catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
}); },
|
||||
multiGet: function (keys) { return new Promise(function (resolve, reject) {
|
||||
try {
|
||||
var values = keys.map(function (key) { return [key, window.localStorage.getItem(key)]; });
|
||||
resolve(values);
|
||||
}
|
||||
catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
}); },
|
||||
multiSet: function (keyValuePairs) { return new Promise(function (resolve, reject) {
|
||||
try {
|
||||
keyValuePairs.forEach(function (keyValuePair) { return window.localStorage.setItem(keyValuePair[0], keyValuePair[1]); });
|
||||
var newKeyValuePairs = keyValuePairs.map(function (keyValuePair) { return [keyValuePair[0], window.localStorage.getItem(keyValuePair[0])]; });
|
||||
resolve(newKeyValuePairs);
|
||||
}
|
||||
catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
}); },
|
||||
};
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// ^ Rip this out into its own npm package
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
var Storage = window.localStorage ? AsyncLocalStorage : react_native_1.AsyncStorage;
|
||||
exports.default = Storage;
|
||||
//# sourceMappingURL=Storage.js.map
|
1
dist/Storage.js.map
vendored
Normal file
1
dist/Storage.js.map
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"Storage.js","sourceRoot":"","sources":["../src/Storage.ts"],"names":[],"mappings":";;AAAA,6CAA2C;AAE3C,sIAAsI;AACtI,yCAAyC;AACzC,sIAAsI;AAEtI,IAAM,iBAAiB,GAAG;IACxB,OAAO,EAAE,UAAC,GAAW,IAAmB,OAAA,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;QAClE,IAAI,CAAC;YACH,IAAM,KAAK,GAAkB,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;YAC7D,OAAO,CAAC,KAAK,CAAC,CAAA;QAChB,CAAC;QAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,CAAA;QACf,CAAC;IACH,CAAC,CAAC,EAPsC,CAOtC;IAEF,OAAO,EAAE,UAAC,GAAW,EAAE,KAAa,IAAK,OAAA,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;QACnE,IAAI,CAAC;Y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C,sIAAsI;AAEtI,IAAM,OAAO,GAAG,MAAM,CAAC,YAAY,GAAG,iBAAiB,GAAG,2BAAY,CAAA;AACtE,kBAAe,OAAO,CAAA"}
|
79
dist/actions.js
vendored
79
dist/actions.js
vendored
|
@ -34,9 +34,11 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
var _this = this;
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var axios_1 = require("axios");
|
||||
var types_1 = require("./types");
|
||||
var Storage_1 = require("./Storage");
|
||||
var auth_1 = require("./services/auth"); // <- maybe this is where you pass in the platform paramter, specifying if it is for a browser or for React Native
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Pure Redux actions:
|
||||
|
@ -215,51 +217,72 @@ var generateAuthActions = function (config) {
|
|||
}; };
|
||||
var signOutUser = function () { return function (dispatch) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var userSignOutCredentials, error_4;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
var userSignOutCredentials, _a, _b, error_4;
|
||||
return __generator(this, function (_c) {
|
||||
switch (_c.label) {
|
||||
case 0:
|
||||
userSignOutCredentials = {
|
||||
'access-token': localStorage.getItem('access-token'),
|
||||
client: localStorage.getItem('client'),
|
||||
uid: localStorage.getItem('uid'),
|
||||
};
|
||||
dispatch(exports.signOutRequestSent());
|
||||
_a.label = 1;
|
||||
_a = {};
|
||||
_b = 'access-token';
|
||||
return [4 /*yield*/, Storage_1.default.getItem('access-token')];
|
||||
case 1:
|
||||
_a.trys.push([1, 3, , 4]);
|
||||
_a[_b] = (_c.sent());
|
||||
return [4 /*yield*/, Storage_1.default.getItem('client')];
|
||||
case 2:
|
||||
_a.client = (_c.sent());
|
||||
return [4 /*yield*/, Storage_1.default.getItem('uid')];
|
||||
case 3:
|
||||
userSignOutCredentials = (_a.uid = (_c.sent()),
|
||||
_a);
|
||||
dispatch(exports.signOutRequestSent());
|
||||
_c.label = 4;
|
||||
case 4:
|
||||
_c.trys.push([4, 6, , 7]);
|
||||
return [4 /*yield*/, axios_1.default({
|
||||
method: 'DELETE',
|
||||
url: authUrl + "/sign_out",
|
||||
data: userSignOutCredentials,
|
||||
})];
|
||||
case 2:
|
||||
_a.sent();
|
||||
case 5:
|
||||
_c.sent();
|
||||
auth_1.deleteAuthHeaders();
|
||||
// Have to check what type of platform it is, depending on the key provided by the end-user... like "browser", "iphone", or "android", etc.:
|
||||
auth_1.deleteAuthHeadersFromLocalStorage();
|
||||
dispatch(exports.signOutRequestSucceeded());
|
||||
return [3 /*break*/, 4];
|
||||
case 3:
|
||||
error_4 = _a.sent();
|
||||
return [3 /*break*/, 7];
|
||||
case 6:
|
||||
error_4 = _c.sent();
|
||||
dispatch(exports.signOutRequestFailed());
|
||||
throw error_4;
|
||||
case 4: return [2 /*return*/];
|
||||
case 7: return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
}; };
|
||||
var verifyCredentials = function (store) {
|
||||
// Gotta check what the platform is:
|
||||
if (localStorage.getItem('access-token')) {
|
||||
var verificationParams = {
|
||||
'access-token': localStorage.getItem('access-token'),
|
||||
client: localStorage.getItem('client'),
|
||||
uid: localStorage.getItem('uid'),
|
||||
};
|
||||
store.dispatch(verifyToken(verificationParams));
|
||||
}
|
||||
};
|
||||
var verifyCredentials = function (store) { return __awaiter(_this, void 0, void 0, function () {
|
||||
var verificationParams, _a, _b;
|
||||
return __generator(this, function (_c) {
|
||||
switch (_c.label) {
|
||||
case 0: return [4 /*yield*/, Storage_1.default.getItem('access-token')];
|
||||
case 1:
|
||||
if (!_c.sent()) return [3 /*break*/, 5];
|
||||
_a = {};
|
||||
_b = 'access-token';
|
||||
return [4 /*yield*/, Storage_1.default.getItem('access-token')];
|
||||
case 2:
|
||||
_a[_b] = (_c.sent());
|
||||
return [4 /*yield*/, Storage_1.default.getItem('client')];
|
||||
case 3:
|
||||
_a.client = (_c.sent());
|
||||
return [4 /*yield*/, Storage_1.default.getItem('uid')];
|
||||
case 4:
|
||||
verificationParams = (_a.uid = (_c.sent()),
|
||||
_a);
|
||||
store.dispatch(verifyToken(verificationParams));
|
||||
_c.label = 5;
|
||||
case 5: return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); };
|
||||
return {
|
||||
registerUser: registerUser,
|
||||
verifyToken: verifyToken,
|
||||
|
|
2
dist/actions.js.map
vendored
2
dist/actions.js.map
vendored
File diff suppressed because one or more lines are too long
80
dist/services/auth.js
vendored
80
dist/services/auth.js
vendored
|
@ -38,81 +38,7 @@ var _this = this;
|
|||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var axios_1 = require("axios");
|
||||
var utility_1 = require("./utility");
|
||||
var react_native_1 = require("react-native");
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Rip this out into its own npm package:
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
var AsyncLocalStorage = {
|
||||
getItem: function (key) { return new Promise(function (resolve, reject) {
|
||||
try {
|
||||
var value = window.localStorage.getItem(key);
|
||||
resolve(value);
|
||||
}
|
||||
catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
}); },
|
||||
setItem: function (key, value) { return new Promise(function (resolve, reject) {
|
||||
try {
|
||||
window.localStorage.setItem(key, value);
|
||||
resolve(value);
|
||||
}
|
||||
catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
}); },
|
||||
removeItem: function (key) { return new Promise(function (resolve, reject) {
|
||||
try {
|
||||
var value = window.localStorage.getItem(key);
|
||||
window.localStorage.removeItem(key);
|
||||
resolve(value);
|
||||
}
|
||||
catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
}); },
|
||||
clear: function () { return new Promise(function (resolve, reject) {
|
||||
try {
|
||||
window.localStorage.clear();
|
||||
resolve(true);
|
||||
}
|
||||
catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
}); },
|
||||
getAllKeys: function () { return new Promise(function (resolve, reject) {
|
||||
try {
|
||||
var allKeys = Object.keys(window.localStorage);
|
||||
resolve(allKeys);
|
||||
}
|
||||
catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
}); },
|
||||
multiGet: function (keys) { return new Promise(function (resolve, reject) {
|
||||
try {
|
||||
var values = keys.map(function (key) { return [key, window.localStorage.getItem(key)]; });
|
||||
resolve(values);
|
||||
}
|
||||
catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
}); },
|
||||
multiSet: function (keyValuePairs) { return new Promise(function (resolve, reject) {
|
||||
try {
|
||||
keyValuePairs.forEach(function (keyValuePair) { return window.localStorage.setItem(keyValuePair[0], keyValuePair[1]); });
|
||||
var newKeyValuePairs = keyValuePairs.map(function (keyValuePair) { return [keyValuePair[0], window.localStorage.getItem(keyValuePair[0])]; });
|
||||
resolve(newKeyValuePairs);
|
||||
}
|
||||
catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
}); },
|
||||
};
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// ^ Rip this out into its own npm package
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
var Storage = window.localStorage ? AsyncLocalStorage : react_native_1.AsyncStorage;
|
||||
var Storage_1 = require("../Storage");
|
||||
// try {
|
||||
// Storage = AsyncStorage
|
||||
// } catch (e) {
|
||||
|
@ -134,7 +60,7 @@ exports.setAuthHeaders = function (headers) {
|
|||
exports.persistAuthHeadersInLocalStorage = function (headers) {
|
||||
// use multiSet:
|
||||
authHeaderKeys.forEach(function (key) {
|
||||
Storage.setItem(key, headers[key]);
|
||||
Storage_1.default.setItem(key, headers[key]);
|
||||
});
|
||||
};
|
||||
exports.deleteAuthHeaders = function () {
|
||||
|
@ -147,7 +73,7 @@ exports.deleteAuthHeadersFromLocalStorage = function () { return __awaiter(_this
|
|||
return __generator(this, function (_a) {
|
||||
// can use multiRemove once you've written it:
|
||||
authHeaderKeys.forEach(function (key) {
|
||||
Storage.removeItem(key);
|
||||
Storage_1.default.removeItem(key);
|
||||
// localStorage.removeItem(key)
|
||||
});
|
||||
return [2 /*return*/];
|
||||
|
|
2
dist/services/auth.js.map
vendored
2
dist/services/auth.js.map
vendored
|
@ -1 +1 @@
|
|||
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/services/auth.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iBA+IA;;AA/IA,+BAAyB;AACzB,qCAAkD;AAMlD,6CAA2C;AAE3C,sIAAsI;AACtI,yCAAyC;AACzC,sIAAsI;AAEtI,IAAM,iBAAiB,GAAG;IACxB,OAAO,EAAE,UAAC,GAAW,IAAmB,OAAA,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;QAClE,IAAI,CAAC;YACH,IAAM,KAAK,GAAkB,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;YAC7D,OAAO,CAAC,KAAK,CAAC,CAAA;QAChB,CAAC;QAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,CAAA;QACf,CAAC;IACH,CAAC,CAAC,EAPsC,CAOtC;IAEF,OAAO,EAAE,UAAC,GAAW,EAAE,KAAa,IAAK,OAAA,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;QACnE,IAAI,CAAC;YACH,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;YACvC,OAAO,CAAC,KAAK,CAAC,CAAA;QAChB,CAAC;QAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,CAAA;QACf,CAAC;IACH,CAAC,CAAC,EAPuC,CAOvC;IAEF,UAAU,EAAE,UAAC,GAAW,IAAmB,OAAA,IAAI,OAAO,CAAC,UAAC,OAAO,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AAc,CAAC,OAAO,CAAC,UAAC,GAAW;YACjC,iBAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;YACvB,+BAA+B;QACjC,CAAC,CAAC,CAAA;;;KACH,CAAA;AAEY,QAAA,6BAA6B,GAAG,UAC3C,cAAoC,EACpC,QAAsB;IAEtB,IAAM,sBAAsB,GAAyB,gCAAsB,CAAC,cAAc,CAAC,CAAA;IAC3F,IAAM,yBAAyB,GAAa,MAAM,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAA;IAC/E,IAAM,sBAAsB,GAAyB,EAAE,CAAA;IACvD,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,UAAC,GAAW;QAClD,EAAE,CAAC,CAAC,yBAAyB,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YAClD,sBAAsB,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAC/E,CAAC;IACH,CAAC,CAAC,CAAA;IACF,MAAM,CAAC,sBAAsB,CAAA;AAC/B,CAAC,CAAA"}
|
79
src/Storage.ts
Normal file
79
src/Storage.ts
Normal file
|
@ -0,0 +1,79 @@
|
|||
import { AsyncStorage } from 'react-native'
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Rip this out into its own npm package:
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const AsyncLocalStorage = {
|
||||
getItem: (key: string): Promise<any> => new Promise((resolve, reject) => {
|
||||
try {
|
||||
const value: string | null = window.localStorage.getItem(key)
|
||||
resolve(value)
|
||||
} catch (error) {
|
||||
reject(error)
|
||||
}
|
||||
}),
|
||||
|
||||
setItem: (key: string, value: string) => new Promise((resolve, reject) => {
|
||||
try {
|
||||
window.localStorage.setItem(key, value)
|
||||
resolve(value)
|
||||
} catch (error) {
|
||||
reject(error)
|
||||
}
|
||||
}),
|
||||
|
||||
removeItem: (key: string): Promise<any> => new Promise((resolve, reject) => {
|
||||
try {
|
||||
const value: string | null = window.localStorage.getItem(key)
|
||||
window.localStorage.removeItem(key)
|
||||
resolve(value)
|
||||
} catch (error) {
|
||||
reject(error)
|
||||
}
|
||||
}),
|
||||
|
||||
clear: () => new Promise((resolve, reject) => {
|
||||
try {
|
||||
window.localStorage.clear()
|
||||
resolve(true)
|
||||
} catch (error) {
|
||||
reject(error)
|
||||
}
|
||||
}),
|
||||
|
||||
getAllKeys: () => new Promise((resolve, reject) => {
|
||||
try {
|
||||
const allKeys = Object.keys(window.localStorage)
|
||||
resolve(allKeys)
|
||||
} catch (error) {
|
||||
reject(error)
|
||||
}
|
||||
}),
|
||||
|
||||
multiGet: (keys: string[]) => new Promise((resolve, reject) => {
|
||||
try {
|
||||
const values = keys.map(key => [ key, window.localStorage.getItem(key) ])
|
||||
resolve(values)
|
||||
} catch (error) {
|
||||
reject(error)
|
||||
}
|
||||
}),
|
||||
|
||||
multiSet: (keyValuePairs: string[][]) => new Promise((resolve, reject) => {
|
||||
try {
|
||||
keyValuePairs.forEach(keyValuePair => window.localStorage.setItem(keyValuePair[0], keyValuePair[1]))
|
||||
const newKeyValuePairs = keyValuePairs.map(keyValuePair => [ keyValuePair[0], window.localStorage.getItem(keyValuePair[0]) ])
|
||||
resolve(newKeyValuePairs)
|
||||
} catch (error) {
|
||||
reject(error)
|
||||
}
|
||||
}),
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// ^ Rip this out into its own npm package
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const Storage = window.localStorage ? AsyncLocalStorage : AsyncStorage
|
||||
export default Storage
|
|
@ -36,6 +36,7 @@ import {
|
|||
SignOutRequestSucceededAction,
|
||||
SignOutRequestFailedAction,
|
||||
} from './types'
|
||||
import Storage from './Storage'
|
||||
import {
|
||||
deleteAuthHeaders,
|
||||
deleteAuthHeadersFromLocalStorage,
|
||||
|
@ -214,9 +215,9 @@ const generateAuthActions = (config: { [key: string]: any }): ActionsExport => {
|
|||
|
||||
const signOutUser = () => async function (dispatch: Dispatch<{}>): Promise<void> {
|
||||
const userSignOutCredentials: UserSignOutCredentials = {
|
||||
'access-token': localStorage.getItem('access-token') as string,
|
||||
client: localStorage.getItem('client') as string,
|
||||
uid: localStorage.getItem('uid') as string,
|
||||
'access-token': await Storage.getItem('access-token') as string,
|
||||
client: await Storage.getItem('client') as string,
|
||||
uid: await Storage.getItem('uid') as string,
|
||||
}
|
||||
dispatch(signOutRequestSent())
|
||||
try {
|
||||
|
@ -235,13 +236,13 @@ const generateAuthActions = (config: { [key: string]: any }): ActionsExport => {
|
|||
}
|
||||
}
|
||||
|
||||
const verifyCredentials = (store: Store<{}>): void => {
|
||||
const verifyCredentials = async (store: Store<{}>): Promise<void> => {
|
||||
// Gotta check what the platform is:
|
||||
if (localStorage.getItem('access-token')) {
|
||||
if (await Storage.getItem('access-token')) {
|
||||
const verificationParams: VerificationParams = {
|
||||
'access-token': localStorage.getItem('access-token') as string,
|
||||
client: localStorage.getItem('client') as string,
|
||||
uid: localStorage.getItem('uid') as string,
|
||||
'access-token': await Storage.getItem('access-token') as string,
|
||||
client: await Storage.getItem('client') as string,
|
||||
uid: await Storage.getItem('uid') as string,
|
||||
}
|
||||
store.dispatch<any>(verifyToken(verificationParams))
|
||||
}
|
||||
|
|
|
@ -5,84 +5,7 @@ import {
|
|||
AuthResponse,
|
||||
SingleLayerStringMap,
|
||||
} from '../types'
|
||||
import { AsyncStorage } from 'react-native'
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Rip this out into its own npm package:
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const AsyncLocalStorage = {
|
||||
getItem: (key: string): Promise<any> => new Promise((resolve, reject) => {
|
||||
try {
|
||||
const value: string | null = window.localStorage.getItem(key)
|
||||
resolve(value)
|
||||
} catch (error) {
|
||||
reject(error)
|
||||
}
|
||||
}),
|
||||
|
||||
setItem: (key: string, value: string) => new Promise((resolve, reject) => {
|
||||
try {
|
||||
window.localStorage.setItem(key, value)
|
||||
resolve(value)
|
||||
} catch (error) {
|
||||
reject(error)
|
||||
}
|
||||
}),
|
||||
|
||||
removeItem: (key: string): Promise<any> => new Promise((resolve, reject) => {
|
||||
try {
|
||||
const value: string | null = window.localStorage.getItem(key)
|
||||
window.localStorage.removeItem(key)
|
||||
resolve(value)
|
||||
} catch (error) {
|
||||
reject(error)
|
||||
}
|
||||
}),
|
||||
|
||||
clear: () => new Promise((resolve, reject) => {
|
||||
try {
|
||||
window.localStorage.clear()
|
||||
resolve(true)
|
||||
} catch (error) {
|
||||
reject(error)
|
||||
}
|
||||
}),
|
||||
|
||||
getAllKeys: () => new Promise((resolve, reject) => {
|
||||
try {
|
||||
const allKeys = Object.keys(window.localStorage)
|
||||
resolve(allKeys)
|
||||
} catch (error) {
|
||||
reject(error)
|
||||
}
|
||||
}),
|
||||
|
||||
multiGet: (keys: string[]) => new Promise((resolve, reject) => {
|
||||
try {
|
||||
const values = keys.map(key => [ key, window.localStorage.getItem(key) ])
|
||||
resolve(values)
|
||||
} catch (error) {
|
||||
reject(error)
|
||||
}
|
||||
}),
|
||||
|
||||
multiSet: (keyValuePairs: string[][]) => new Promise((resolve, reject) => {
|
||||
try {
|
||||
keyValuePairs.forEach(keyValuePair => window.localStorage.setItem(keyValuePair[0], keyValuePair[1]))
|
||||
const newKeyValuePairs = keyValuePairs.map(keyValuePair => [ keyValuePair[0], window.localStorage.getItem(keyValuePair[0]) ])
|
||||
resolve(newKeyValuePairs)
|
||||
} catch (error) {
|
||||
reject(error)
|
||||
}
|
||||
}),
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// ^ Rip this out into its own npm package
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
let Storage = window.localStorage ? AsyncLocalStorage : AsyncStorage
|
||||
import Storage from '../Storage'
|
||||
|
||||
// try {
|
||||
// Storage = AsyncStorage
|
||||
|
|
Loading…
Reference in New Issue
Block a user