"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "packages/hoppscotch-app/newstore/environments.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.

environments.ts  (hoppscotch-2.2.1):environments.ts  (hoppscotch-3.0.0)
import { cloneDeep } from "lodash" import { Environment } from "@hoppscotch/data"
import isEqual from "lodash/isEqual" import { cloneDeep, isEqual } from "lodash-es"
import { combineLatest, Observable } from "rxjs" import { combineLatest, Observable } from "rxjs"
import { distinctUntilChanged, map, pluck } from "rxjs/operators" import { distinctUntilChanged, map, pluck } from "rxjs/operators"
import DispatchingStore, { import DispatchingStore, {
defineDispatchers, defineDispatchers,
} from "~/newstore/DispatchingStore" } from "~/newstore/DispatchingStore"
export type Environment = {
name: string
variables: {
key: string
value: string
}[]
}
const defaultEnvironmentsState = { const defaultEnvironmentsState = {
environments: [ environments: [
{ {
name: "My Environment Variables", name: "My Environment Variables",
variables: [], variables: [],
}, },
] as Environment[], ] as Environment[],
globals: [] as Environment["variables"], globals: [] as Environment["variables"],
skipping to change at line 104 skipping to change at line 96
...cloneDeep(newEnvironment), ...cloneDeep(newEnvironment),
name: `${newEnvironment.name} - Duplicate`, name: `${newEnvironment.name} - Duplicate`,
}, },
], ],
} }
}, },
deleteEnvironment( deleteEnvironment(
{ environments, currentEnvironmentIndex }: EnvironmentStore, { environments, currentEnvironmentIndex }: EnvironmentStore,
{ envIndex }: { envIndex: number } { envIndex }: { envIndex: number }
) { ) {
let newCurrEnvIndex = currentEnvironmentIndex
// Scenario 1: Currently Selected Env is removed -> Set currently selected t
o none
if (envIndex === currentEnvironmentIndex) newCurrEnvIndex = -1
// Scenario 2: Currently Selected Env Index > Deletion Index -> Current Sele
ction Index Shifts One Position to the left -> Correct Env Index by moving back
1 index
if (envIndex < currentEnvironmentIndex)
newCurrEnvIndex = currentEnvironmentIndex - 1
// Scenario 3: Currently Selected Env Index < Deletion Index -> No change ha
ppens at selection position -> Noop
return { return {
environments: environments.filter((_, index) => index !== envIndex), environments: environments.filter((_, index) => index !== envIndex),
currentEnvironmentIndex: currentEnvironmentIndex: newCurrEnvIndex,
envIndex === currentEnvironmentIndex ? -1 : currentEnvironmentIndex,
} }
}, },
renameEnvironment( renameEnvironment(
{ environments }: EnvironmentStore, { environments }: EnvironmentStore,
{ envIndex, newName }: { envIndex: number; newName: string } { envIndex, newName }: { envIndex: number; newName: string }
) { ) {
return { return {
environments: environments.map((env, index) => environments: environments.map((env, index) =>
index === envIndex index === envIndex
? { ? {
skipping to change at line 270 skipping to change at line 271
export const globalEnv$ = environmentsStore.subject$.pipe( export const globalEnv$ = environmentsStore.subject$.pipe(
pluck("globals"), pluck("globals"),
distinctUntilChanged() distinctUntilChanged()
) )
export const selectedEnvIndex$ = environmentsStore.subject$.pipe( export const selectedEnvIndex$ = environmentsStore.subject$.pipe(
pluck("currentEnvironmentIndex"), pluck("currentEnvironmentIndex"),
distinctUntilChanged() distinctUntilChanged()
) )
export const currentEnvironment$ = combineLatest([ export const currentEnvironment$ = environmentsStore.subject$.pipe(
environments$, map(({ currentEnvironmentIndex, environments }) => {
selectedEnvIndex$, if (currentEnvironmentIndex === -1) {
]).pipe(
map(([envs, selectedIndex]) => {
if (selectedIndex === -1) {
const env: Environment = { const env: Environment = {
name: "No environment", name: "No environment",
variables: [], variables: [],
} }
return env return env
} else { } else {
return envs[selectedIndex] return environments[currentEnvironmentIndex]
} }
}) })
) )
export type AggregateEnvironment = { export type AggregateEnvironment = {
key: string key: string
value: string value: string
sourceEnv: string sourceEnv: string
} }
skipping to change at line 544 skipping to change at line 542
dispatcher: "updateEnvironmentVariable", dispatcher: "updateEnvironmentVariable",
payload: { payload: {
envIndex, envIndex,
variableIndex, variableIndex,
updatedKey: key, updatedKey: key,
updatedValue: value, updatedValue: value,
}, },
}) })
} }
export function getEnviroment(index: number) { export function getEnvironment(index: number) {
return environmentsStore.value.environments[index] return environmentsStore.value.environments[index]
} }
 End of changes. 7 change blocks. 
20 lines changed or deleted 22 lines changed or added

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