From bf4eb0159c1c8e8bd71db53c601beed07965c90f Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 8 Jul 2019 00:00:23 -0400 Subject: [PATCH] (refactor): export AsyncLocalStorage as object - will need to export more from here with TS, like an interface, so won't be able to `import * as` in the future - also give it a default export --- src/asyncLocalStorage.js | 29 +++++++++++++++-------------- src/index.js | 2 +- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/asyncLocalStorage.js b/src/asyncLocalStorage.js index 802e6bc..7072aa2 100644 --- a/src/asyncLocalStorage.js +++ b/src/asyncLocalStorage.js @@ -1,17 +1,16 @@ -export function clear () { - return callWithPromise(window.localStorage.clear) -} - -export function getItem (key) { - return callWithPromise(window.localStorage.getItem, key) -} - -export function removeItem (key) { - return callWithPromise(window.localStorage.removeItem, key) -} - -export function setItem (key, value) { - return callWithPromise(window.localStorage.setItem, key, value) +export const AsyncLocalStorage = { + clear () { + return callWithPromise(window.localStorage.clear) + }, + getItem (key) { + return callWithPromise(window.localStorage.getItem, key) + }, + removeItem (key) { + return callWithPromise(window.localStorage.removeItem, key) + }, + setItem (key, value) { + return callWithPromise(window.localStorage.setItem, key, value) + } } function callWithPromise (func, ...args) { @@ -21,3 +20,5 @@ function callWithPromise (func, ...args) { return Promise.reject(err) } } + +export default AsyncLocalStorage diff --git a/src/index.js b/src/index.js index e192b67..df9f34a 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,6 @@ import { onSnapshot, applySnapshot } from 'mobx-state-tree' -import * as AsyncLocalStorage from './asyncLocalStorage.js' +import AsyncLocalStorage from './asyncLocalStorage.js' export const persist = (name, store, options = {}) => { let {storage, jsonify, whitelist, blacklist} = options