pinafore/routes/_store/store.js

67 lines
1.9 KiB
JavaScript
Raw Normal View History

2018-03-03 23:15:50 +01:00
import { observers } from './observers/observers'
import { computations } from './computations/computations'
import { mixins } from './mixins/mixins'
2018-01-28 22:09:39 +01:00
import { LocalStorageStore } from './LocalStorageStore'
import { observe } from 'svelte-extras'
2018-01-28 22:09:39 +01:00
const persistedState = {
autoplayGifs: false,
composeData: {},
2018-01-28 22:09:39 +01:00
currentInstance: null,
currentRegisteredInstanceName: undefined,
currentRegisteredInstance: undefined,
disableCustomScrollbars: false,
disableLongAriaLabels: false,
instanceNameInSearch: '',
instanceThemes: {},
2018-01-28 22:09:39 +01:00
loggedInInstances: {},
loggedInInstancesInOrder: [],
markMediaAsSensitive: false,
neverMarkMediaAsSensitive: false,
omitEmojiInDisplayNames: undefined,
2018-02-08 18:15:25 +01:00
pinnedPages: {},
pushSubscription: null,
reduceMotion: !process.browser || window.matchMedia('(prefers-reduced-motion: reduce)').matches
}
const nonPersistedState = {
customEmoji: {},
instanceInfos: {},
instanceLists: {},
online: !process.browser || navigator.onLine,
pinnedStatuses: {},
pushNotificationsSupport: process.browser && ('serviceWorker' in navigator && 'PushManager' in window && 'getKey' in window.PushSubscription.prototype),
queryInSearch: '',
repliesShown: {},
sensitivesShown: {},
spoilersShown: {},
statusModifications: {},
verifyCredentials: {}
}
const state = Object.assign({}, persistedState, nonPersistedState)
const keysToStoreInLocalStorage = new Set(Object.keys(persistedState))
class PinaforeStore extends LocalStorageStore {
constructor (state) {
super(state, keysToStoreInLocalStorage)
}
}
PinaforeStore.prototype.observe = observe
export const store = new PinaforeStore(state)
2018-01-28 22:09:39 +01:00
mixins(PinaforeStore)
computations(store)
2018-02-21 06:29:59 +01:00
observers(store)
2018-01-28 22:09:39 +01:00
2018-02-20 05:15:24 +01:00
if (process.browser && process.env.NODE_ENV !== 'production') {
window.store = store // for debugging
2018-02-20 05:28:31 +01:00
}
// needed for tests
if (process.browser) {
window.__forceOnline = online => store.set({ online })
}