"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "newstore/localpersistence.ts" between
hoppscotch-2.0.0.tar.gz and hoppscotch-2.1.0.tar.gz

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

localpersistence.ts  (hoppscotch-2.0.0):localpersistence.ts  (hoppscotch-2.1.0)
/* eslint-disable no-restricted-globals, no-restricted-syntax */ /* eslint-disable no-restricted-globals, no-restricted-syntax */
import clone from "lodash/clone" import clone from "lodash/clone"
import assign from "lodash/assign" import assign from "lodash/assign"
import isEmpty from "lodash/isEmpty" import isEmpty from "lodash/isEmpty"
import * as O from "fp-ts/Option"
import { pipe } from "fp-ts/function"
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 37 skipping to change at line 39
translateToNewRESTCollection, translateToNewRESTCollection,
translateToNewGQLCollection, translateToNewGQLCollection,
} from "./collections" } from "./collections"
import { import {
replaceEnvironments, replaceEnvironments,
environments$, environments$,
Environment, Environment,
addGlobalEnvVariable, addGlobalEnvVariable,
setGlobalEnvVariables, setGlobalEnvVariables,
globalEnv$, globalEnv$,
selectedEnvIndex$,
setCurrentEnvironment,
} from "./environments" } from "./environments"
import { restRequest$, setRESTRequest } from "./RESTSession" import { restRequest$, setRESTRequest } from "./RESTSession"
import { translateToNewRequest } from "~/helpers/types/HoppRESTRequest" import { translateToNewRequest } from "~/helpers/types/HoppRESTRequest"
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
skipping to change at line 188 skipping to change at line 192
) )
} }
replaceEnvironments(environmentsData) replaceEnvironments(environmentsData)
environments$.subscribe((envs) => { environments$.subscribe((envs) => {
window.localStorage.setItem("environments", JSON.stringify(envs)) window.localStorage.setItem("environments", JSON.stringify(envs))
}) })
} }
function setupSelectedEnvPersistence() {
const selectedEnvIndex =
pipe(
// Value from local storage can be nullable
O.fromNullable(
window.localStorage.getItem("selectedEnvIndex")
),
O.map(parseInt), // If not null, parse to integer
O.chain(
O.fromPredicate(
Number.isInteger // Check if the number is proper int (not NaN)
)
),
O.getOrElse(() => -1) // If all the above conditions pass, we are good, el
se set default value (-1)
)
setCurrentEnvironment(selectedEnvIndex)
selectedEnvIndex$.subscribe((index) => {
window.localStorage.setItem("selectedEnvIndex", index.toString())
})
}
function setupGlobalEnvsPersistence() { function setupGlobalEnvsPersistence() {
const globals: Environment["variables"] = JSON.parse( const globals: Environment["variables"] = JSON.parse(
window.localStorage.getItem("globalEnv") || "[]" window.localStorage.getItem("globalEnv") || "[]"
) )
setGlobalEnvVariables(globals) setGlobalEnvVariables(globals)
globalEnv$.subscribe((vars) => { globalEnv$.subscribe((vars) => {
window.localStorage.setItem("globalEnv", JSON.stringify(vars)) window.localStorage.setItem("globalEnv", JSON.stringify(vars))
}) })
skipping to change at line 224 skipping to change at line 251
export function setupLocalPersistence() { export function setupLocalPersistence() {
checkAndMigrateOldSettings() checkAndMigrateOldSettings()
setupSettingsPersistence() setupSettingsPersistence()
setupRequestPersistence() setupRequestPersistence()
setupHistoryPersistence() setupHistoryPersistence()
setupCollectionsPersistence() setupCollectionsPersistence()
setupGlobalEnvsPersistence() setupGlobalEnvsPersistence()
setupEnvironmentsPersistence() setupEnvironmentsPersistence()
setupSelectedEnvPersistence()
} }
/** /**
* Gets a value in LocalStorage. * Gets a value in LocalStorage.
* *
* NOTE: Use LocalStorage to only store non-reactive simple data * NOTE: Use LocalStorage to only store non-reactive simple data
* For more complex data, use stores and connect it to localpersistence * For more complex data, use stores and connect it to localpersistence
*/ */
export function getLocalConfig(name: string) { export function getLocalConfig(name: string) {
return window.localStorage.getItem(name) return window.localStorage.getItem(name)
 End of changes. 4 change blocks. 
0 lines changed or deleted 29 lines changed or added

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