"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "packages/hoppscotch-app/newstore/localpersistence.ts" between
hoppscotch-2.2.1.tar.gz and hoppscotch-3.0.0.tar.gz

About: Hoppscotch is a light-weight, web based API development suite.

localpersistence.ts  (hoppscotch-2.2.1):localpersistence.ts  (hoppscotch-3.0.0)
/* eslint-disable no-restricted-globals, no-restricted-syntax */ /* eslint-disable no-restricted-globals, no-restricted-syntax */
import clone from "lodash/clone" import { clone, cloneDeep, assign, isEmpty } from "lodash-es"
import assign from "lodash/assign"
import isEmpty from "lodash/isEmpty"
import * as O from "fp-ts/Option" import * as O from "fp-ts/Option"
import { pipe } from "fp-ts/function" import { pipe } from "fp-ts/function"
import { import {
safelyExtractRESTRequest, safelyExtractRESTRequest,
translateToNewRequest, translateToNewRequest,
translateToNewRESTCollection, translateToNewRESTCollection,
translateToNewGQLCollection, translateToNewGQLCollection,
Environment,
} from "@hoppscotch/data" } from "@hoppscotch/data"
import { cloneDeep } from "lodash"
import { import {
settingsStore, settingsStore,
bulkApplySettings, bulkApplySettings,
defaultSettings, defaultSettings,
applySetting, applySetting,
HoppAccentColor, HoppAccentColor,
HoppBgColor, HoppBgColor,
} from "./settings" } from "./settings"
import { import {
restHistoryStore, restHistoryStore,
skipping to change at line 40 skipping to change at line 38
} from "./history" } from "./history"
import { import {
restCollectionStore, restCollectionStore,
graphqlCollectionStore, graphqlCollectionStore,
setGraphqlCollections, setGraphqlCollections,
setRESTCollections, setRESTCollections,
} from "./collections" } from "./collections"
import { import {
replaceEnvironments, replaceEnvironments,
environments$, environments$,
Environment,
addGlobalEnvVariable, addGlobalEnvVariable,
setGlobalEnvVariables, setGlobalEnvVariables,
globalEnv$, globalEnv$,
selectedEnvIndex$, selectedEnvIndex$,
setCurrentEnvironment, setCurrentEnvironment,
} from "./environments" } from "./environments"
import { import {
getDefaultRESTRequest, getDefaultRESTRequest,
restRequest$, restRequest$,
setRESTRequest, setRESTRequest,
} from "./RESTSession" } from "./RESTSession"
import { WSRequest$, setWSRequest } from "./WebSocketSession" import { WSRequest$, setWSRequest } from "./WebSocketSession"
import { SIORequest$, setSIORequest } from "./SocketIOSession" import { SIORequest$, setSIORequest } from "./SocketIOSession"
import { SSERequest$, setSSERequest } from "./SSESession" import { SSERequest$, setSSERequest } from "./SSESession"
import { MQTTRequest$, setMQTTRequest } from "./MQTTSession" import { MQTTRequest$, setMQTTRequest } from "./MQTTSession"
import { bulkApplyLocalState, localStateStore } from "./localstate"
import { StorageLike } from "@vueuse/core"
function checkAndMigrateOldSettings() { function checkAndMigrateOldSettings() {
const vuexData = JSON.parse(window.localStorage.getItem("vuex") || "{}") const vuexData = JSON.parse(window.localStorage.getItem("vuex") || "{}")
if (isEmpty(vuexData)) return if (isEmpty(vuexData)) return
const { postwoman } = vuexData const { postwoman } = vuexData
if (!isEmpty(postwoman?.settings)) { if (!isEmpty(postwoman?.settings)) {
const settingsData = assign(clone(defaultSettings), postwoman.settings) const settingsData = assign(clone(defaultSettings), postwoman.settings)
skipping to change at line 117 skipping to change at line 116
} }
if (window.localStorage.getItem("nuxt-color-mode")) { if (window.localStorage.getItem("nuxt-color-mode")) {
const color = window.localStorage.getItem("nuxt-color-mode") as HoppBgColor const color = window.localStorage.getItem("nuxt-color-mode") as HoppBgColor
applySetting("BG_COLOR", color) applySetting("BG_COLOR", color)
window.localStorage.removeItem("nuxt-color-mode") window.localStorage.removeItem("nuxt-color-mode")
} }
} }
function setupLocalStatePersistence() {
const localStateData = JSON.parse(
window.localStorage.getItem("localState") ?? "{}"
)
if (localStateData) bulkApplyLocalState(localStateData)
localStateStore.subject$.subscribe((state) => {
window.localStorage.setItem("localState", JSON.stringify(state))
})
}
function setupSettingsPersistence() { function setupSettingsPersistence() {
const settingsData = JSON.parse( const settingsData = JSON.parse(
window.localStorage.getItem("settings") || "{}" window.localStorage.getItem("settings") || "{}"
) )
if (settingsData) { if (settingsData) {
bulkApplySettings(settingsData) bulkApplySettings(settingsData)
} }
settingsStore.subject$.subscribe((settings) => { settingsStore.subject$.subscribe((settings) => {
skipping to change at line 316 skipping to change at line 327
else return x else return x
}) })
} }
window.localStorage.setItem("restRequest", JSON.stringify(reqClone)) window.localStorage.setItem("restRequest", JSON.stringify(reqClone))
}) })
} }
export function setupLocalPersistence() { export function setupLocalPersistence() {
checkAndMigrateOldSettings() checkAndMigrateOldSettings()
setupLocalStatePersistence()
setupSettingsPersistence() setupSettingsPersistence()
setupRequestPersistence() setupRequestPersistence()
setupHistoryPersistence() setupHistoryPersistence()
setupCollectionsPersistence() setupCollectionsPersistence()
setupGlobalEnvsPersistence() setupGlobalEnvsPersistence()
setupEnvironmentsPersistence() setupEnvironmentsPersistence()
setupSelectedEnvPersistence() setupSelectedEnvPersistence()
setupWebsocketPersistence() setupWebsocketPersistence()
setupSocketIOPersistence() setupSocketIOPersistence()
setupSSEPersistence() setupSSEPersistence()
skipping to change at line 356 skipping to change at line 368
window.localStorage.setItem(key, value) window.localStorage.setItem(key, value)
} }
/** /**
* Clear config value in LocalStorage. * Clear config value in LocalStorage.
* @param key Key to be cleared * @param key Key to be cleared
*/ */
export function removeLocalConfig(key: string) { export function removeLocalConfig(key: string) {
window.localStorage.removeItem(key) window.localStorage.removeItem(key)
} }
/**
* The storage system we are using in the application.
* NOTE: This is a placeholder for being used in app.
* This entire redirection of localStorage is to allow for
* not refactoring the entire app code when we refactor when
* we are building the native (which may lack localStorage,
* or use a custom system)
*/
export const hoppLocalConfigStorage: StorageLike = localStorage
 End of changes. 8 change blocks. 
5 lines changed or deleted 17 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)