Skip to content

Commit

Permalink
(refactor): export AsyncLocalStorage as object
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
agilgur5 committed Jul 11, 2019
1 parent b1afcd6 commit bf4eb01
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
29 changes: 15 additions & 14 deletions src/asyncLocalStorage.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -21,3 +20,5 @@ function callWithPromise (func, ...args) {
return Promise.reject(err)
}
}

export default AsyncLocalStorage
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit bf4eb01

Please sign in to comment.