-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
32 lines (29 loc) · 903 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
* © 2022 WavePlay <[email protected]>
*/
import { Stashy } from './core'
import { CookieBackend } from './backend/cookie'
import { LocalStorageBackend } from './backend/local-storage'
import { AsyncStorageBackend } from './backend/async-storage'
import { isNative, isSSR } from './utils'
import type { StashyBackend } from './backend/_base'
function getDefaultBackend(platform: 'native' | 'ssr' | 'web'): StashyBackend {
if (isNative() && platform === 'native') {
return new AsyncStorageBackend()
} else if (isSSR() && platform === 'ssr') {
return new CookieBackend()
} else if (!isNative() && !isSSR() && platform === 'web') {
return new LocalStorageBackend()
} else {
return null
}
}
const stashy = new Stashy({
backend: {
native: getDefaultBackend('native'),
ssr: getDefaultBackend('ssr'),
web: getDefaultBackend('web')
}
})
export * from './core'
export default stashy