remove vuex
This commit is contained in:
parent
7ae22bbb75
commit
365e7c9235
5 changed files with 5 additions and 123 deletions
|
|
@ -54,8 +54,7 @@
|
|||
"vue": "3.5.22",
|
||||
"vue-i18n": "11",
|
||||
"vue-router": "4.6.4",
|
||||
"vue-virtual-scroller": "^2.0.0-beta.7",
|
||||
"vuex": "4.1.0"
|
||||
"vue-virtual-scroller": "^2.0.0-beta.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "7.28.5",
|
||||
|
|
|
|||
|
|
@ -27,73 +27,6 @@ const defaultStorage = (() => {
|
|||
return storage
|
||||
})()
|
||||
|
||||
export default function createPersistedState({
|
||||
key = 'vuex-lz',
|
||||
paths = [],
|
||||
getState = (key, storage) => {
|
||||
const value = storage.getItem(key)
|
||||
return value
|
||||
},
|
||||
setState = (key, state, storage) => {
|
||||
if (!loaded) {
|
||||
console.info('waiting for old state to be loaded...')
|
||||
return Promise.resolve()
|
||||
} else {
|
||||
return storage.setItem(key, state)
|
||||
}
|
||||
},
|
||||
reducer = defaultReducer,
|
||||
storage = defaultStorage,
|
||||
subscriber = (store) => (handler) => store.subscribe(handler),
|
||||
} = {}) {
|
||||
return getState(key, storage).then((savedState) => {
|
||||
return (store) => {
|
||||
try {
|
||||
if (savedState !== null && typeof savedState === 'object') {
|
||||
// build user cache
|
||||
const usersState = savedState.users || {}
|
||||
usersState.usersObject = {}
|
||||
const users = usersState.users || []
|
||||
each(users, (user) => {
|
||||
usersState.usersObject[user.id] = user
|
||||
})
|
||||
savedState.users = usersState
|
||||
|
||||
store.replaceState(merge({}, store.state, savedState))
|
||||
}
|
||||
loaded = true
|
||||
} catch (e) {
|
||||
console.error("Couldn't load state")
|
||||
console.error(e)
|
||||
loaded = true
|
||||
}
|
||||
subscriber(store)((mutation, state) => {
|
||||
try {
|
||||
if (saveImmedeatelyActions.includes(mutation.type)) {
|
||||
setState(key, reducer(cloneDeep(state), paths), storage).then(
|
||||
(success) => {
|
||||
if (success !== undefined) {
|
||||
if (mutation.type === 'setOption') {
|
||||
useInterfaceStore().settingsSaved({ success })
|
||||
}
|
||||
}
|
||||
},
|
||||
(error) => {
|
||||
if (mutation.type === 'setOption') {
|
||||
useInterfaceStore().settingsSaved({ error })
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Couldn't persist state:")
|
||||
console.error(e)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* This persists state for pinia, which falls back to read from the vuex state
|
||||
* if pinia persisted state does not exist.
|
||||
|
|
|
|||
27
src/main.js
27
src/main.js
|
|
@ -1,7 +1,6 @@
|
|||
/* global process */
|
||||
|
||||
import { createPinia } from 'pinia'
|
||||
import { createStore } from 'vuex'
|
||||
|
||||
import 'custom-event-polyfill'
|
||||
import './lib/event_target_polyfill.js'
|
||||
|
|
@ -17,11 +16,8 @@ import { createI18n } from 'vue-i18n'
|
|||
|
||||
import afterStoreSetup from './boot/after_store.js'
|
||||
import messages from './i18n/messages.js'
|
||||
import createPersistedState, {
|
||||
piniaPersistPlugin,
|
||||
} from './lib/persisted_state.js'
|
||||
import { piniaPersistPlugin } from './lib/persisted_state.js'
|
||||
import { piniaPushNotificationsPlugin } from './lib/push_notifications_plugin.js'
|
||||
import vuexModules from './modules/index.js'
|
||||
|
||||
import { piniaLanguagePlugin } from 'src/lib/language.js'
|
||||
import { piniaStylePlugin } from 'src/lib/style.js'
|
||||
|
|
@ -69,20 +65,12 @@ const persistedStateOptions = {
|
|||
|
||||
try {
|
||||
let storageError
|
||||
const plugins = []
|
||||
const pinia = createPinia()
|
||||
pinia.use(piniaPersistPlugin())
|
||||
pinia.use(piniaLanguagePlugin)
|
||||
pinia.use(piniaStylePlugin)
|
||||
pinia.use(piniaPushNotificationsPlugin)
|
||||
|
||||
try {
|
||||
const persistedState = await createPersistedState(persistedStateOptions)
|
||||
plugins.push(persistedState)
|
||||
} catch (e) {
|
||||
console.error('Storage error', e)
|
||||
storageError = e
|
||||
}
|
||||
document.querySelector('#splash').classList.remove('initial-hidden')
|
||||
document.querySelector('#mascot').src =
|
||||
`/static/pleromatan_apology${isFox}_small.webp`
|
||||
|
|
@ -93,17 +81,8 @@ const persistedStateOptions = {
|
|||
'update.art_by',
|
||||
{ linkToArtist: 'pipivovott' },
|
||||
)
|
||||
const store = createStore({
|
||||
modules: vuexModules,
|
||||
plugins,
|
||||
options: {
|
||||
devtools: process.env.NODE_ENV !== 'production',
|
||||
},
|
||||
strict: false, // Socket modifies itself, let's ignore this for now.
|
||||
// strict: process.env.NODE_ENV !== 'production'
|
||||
})
|
||||
// Temporarily passing pinia and vuex stores along with storageError result until migration is fully complete.
|
||||
return await afterStoreSetup({ pinia, store, storageError, i18n })
|
||||
// Temporarily passing pinia stores along with storageError result until migration is fully complete.
|
||||
return await afterStoreSetup({ pinia, storageError, i18n })
|
||||
} catch (e) {
|
||||
splashError(i18n, e)
|
||||
}
|
||||
|
|
|
|||
22
test/fixtures/mock_store.js
vendored
22
test/fixtures/mock_store.js
vendored
|
|
@ -1,22 +0,0 @@
|
|||
import { cloneDeep } from 'lodash'
|
||||
import { createStore } from 'vuex'
|
||||
|
||||
import vuexModules from 'src/modules/index.js'
|
||||
|
||||
const tweakModules = (modules) => {
|
||||
const res = {}
|
||||
Object.entries(modules).forEach(([name, module]) => {
|
||||
const m = { ...module }
|
||||
m.state = cloneDeep(module.state)
|
||||
res[name] = m
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
const makeMockStore = () => {
|
||||
return createStore({
|
||||
modules: tweakModules(vuexModules),
|
||||
})
|
||||
}
|
||||
|
||||
export default makeMockStore
|
||||
|
|
@ -2877,7 +2877,7 @@
|
|||
"@vue/compiler-dom" "3.5.35"
|
||||
"@vue/shared" "3.5.35"
|
||||
|
||||
"@vue/devtools-api@^6.0.0-beta.11", "@vue/devtools-api@^6.5.0", "@vue/devtools-api@^6.6.4":
|
||||
"@vue/devtools-api@^6.5.0", "@vue/devtools-api@^6.6.4":
|
||||
version "6.6.4"
|
||||
resolved "https://registry.yarnpkg.com/@vue/devtools-api/-/devtools-api-6.6.4.tgz#cbe97fe0162b365edc1dba80e173f90492535343"
|
||||
integrity sha512-sGhTPMuXqZ1rVOk32RylztWkfXTRhuS7vgAKv0zjqk8gbsHkJ7xfFf+jbySxt7tWObEJwyKaHMikV/WGDiQm8g==
|
||||
|
|
@ -9190,13 +9190,6 @@ vue@^3.5.35:
|
|||
"@vue/server-renderer" "3.5.35"
|
||||
"@vue/shared" "3.5.35"
|
||||
|
||||
vuex@4.1.0:
|
||||
version "4.1.0"
|
||||
resolved "https://registry.yarnpkg.com/vuex/-/vuex-4.1.0.tgz#aa1b3ea5c7385812b074c86faeeec2217872e36c"
|
||||
integrity sha512-hmV6UerDrPcgbSy9ORAtNXDr9M4wlNP4pEFKye4ujJF8oqgFFuxDCdOLS3eNoRTtq5O3hoBDh9Doj1bQMYHRbQ==
|
||||
dependencies:
|
||||
"@vue/devtools-api" "^6.0.0-beta.11"
|
||||
|
||||
w3c-xmlserializer@^5.0.0:
|
||||
version "5.0.0"
|
||||
resolved "https://registry.yarnpkg.com/w3c-xmlserializer/-/w3c-xmlserializer-5.0.0.tgz#f925ba26855158594d907313cedd1476c5967f6c"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue