Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public recreateDb () {
if (this._localForageCollection._config) {
const existingConfig = Object.assign({}, this._localForageCollection._config)
if (existingConfig.storeName) {
// localForage.dropInstance(existingConfig) // drop the store and create the new one
const destVersionNumber = this._localForageCollection && this._localForageCollection._dbInfo ? this._localForageCollection._dbInfo.version + 1 : 0
if (destVersionNumber > 0) {
this._localForageCollection = localForage.createInstance({ ...existingConfig, version: destVersionNumber })
} else {
this._localForageCollection = localForage.createInstance(existingConfig)
}
Logger.log('DB recreated with', existingConfig, destVersionNumber)()
}
}
}
import { autorunAsync, createTransformer, toJS as mobxToJS } from 'mobx'
import localforage from 'localforage'
import config from './config'
import { hydrate as editorTabHydrate } from './components/Tab/actions'
import { hydrate as settingsHydrate } from './components/Setting/state'
import { hydrate as pluginsHydrate } from './components/Plugins/actions'
import fileState, { hydrate as fileHydrate } from './commons/File/state'
const mainStore = localforage.createInstance({
name: 'mainProject'
})
// store needed to persist
// the custom transform func
// the delay to set
function persistStore (store, transform) {
autorunAsync(() => {
const customTransform = transform || createTransformer(store => mobxToJS(store))
const transformedStore = customTransform(store)
// 初次等spacekey出现存
if (config.spaceKey && !mainStore._config.storeName) {
mainStore.config({ storeName: config.spaceKey })
} else if (mainStore._config.storeName && (config.globalKey || !config.isPlatform)) {
if (config.hasRehydrated) {
const createEngine = (whitelist = []) => {
// This `createEngine` function modified
// https://raw.githubusercontent.com/mathieudutour/redux-storage-engine-localforage/master/src/index.js
const reduxStore = localforage.createInstance({
name: 'BeatMapper redux state',
});
function rejectWithMessage(error) {
return Promise.reject(error.message);
}
reduxStore.config(config);
let engine = {
load() {
return reduxStore
.getItem(key)
.then(jsonState => JSON.parse(jsonState) || {})
.catch(rejectWithMessage);
},
console.warn(`Couldn't set domain for resolving CORS. If this is prod change 'MICROPAD_URL'.`);
}
const baseReducer: BaseReducer = new BaseReducer();
export const store = createStore(
baseReducer.reducer,
baseReducer.initialState,
composeWithDevTools(applyMiddleware(epicMiddleware))
);
export const NOTEPAD_STORAGE = localforage.createInstance({
name: 'MicroPad',
storeName: 'notepads'
});
export const ASSET_STORAGE = localforage.createInstance({
name: 'MicroPad',
storeName: 'assets'
});
export const SYNC_STORAGE = localforage.createInstance({
name: 'MicroPad',
storeName: 'sync'
});
export const TOAST_HANDLER = new ToastEventHandler();
export function getStorage(): { [name: string]: LocalForage } {
return {
notepadStorage: NOTEPAD_STORAGE,
assetStorage: ASSET_STORAGE,
syncStorage: SYNC_STORAGE
export function beforeRegistration ({ Vue, config, store, isServer }) {
const storeView = currentStoreView()
const dbNamePrefix = storeView.storeCode ? storeView.storeCode + '-' : ''
Vue.prototype.$db.cartsCollection = new UniversalStorage(localForage.createInstance({
name: (config.storeViews.commonCache ? '' : dbNamePrefix) + 'shop',
storeName: 'carts',
driver: localForage[config.localForage.defaultDrivers['carts']]
}))
}
export function config(): LocalForage {
return localforage.createInstance({
name: "wed",
storeName: "files",
});
}
export function beforeRegistration ({ Vue, config, store, isServer }) {
const storeView = currentStoreView()
const dbNamePrefix = storeView.storeCode ? storeView.storeCode + '-' : ''
Vue.prototype.$db.claimsCollection = new UniversalStorage(localForage.createInstance({
name: (config.storeViews.commonCache ? '' : dbNamePrefix) + 'shop',
storeName: 'claims',
driver: localForage[config.localForage.defaultDrivers['claims']]
}))
}
function config() {
return localforage.createInstance({
name: "wed",
storeName: "files",
});
}
protected _createLocalForage(name: string): any {
return LocalForage.createInstance({ name });
}