Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
push(path: string | LocationDescriptorObject, state?: any) {
// Do not navigate if the path object matches
const nextPath = typeof path === 'string' ? path : createPath(path);
if (nextPath === createPath(this.history.location)) return;
if (Date.now() - this.lastPush > this.wait) {
// TypeScript doesn't recognize our push as a proxy for History.push's
// overloaded signature, and it's really hard to fix this properly
this.history.push(path as string, state);
} else {
try {
this.history.replace(path as string, state);
} catch (e) {
// Ignore Safari's history.replaceState() rate limit error.
// See https://github.com/nusmodifications/nusmods/issues/763
if (
e.name === 'SecurityError' &&
e.message.includes('Attempt to use history.replaceState()')
) {
return;
push(path: string | LocationShape, state?: any) {
// Do not navigate if the path object matches
const nextPath = typeof path === 'string' ? path : createPath(path);
if (nextPath === createPath(this.history.location)) return;
if (Date.now() - this.lastPush > this.wait) {
this.history.push(path, state);
} else {
this.history.replace(path, state);
}
this.lastPush = Date.now();
}
}
run: async (paramsStr: string) => {
const params: TextDocumentPositionParams = JSON.parse(paramsStr)
const result = await getDefinitionURL(
{ urlToFile, requestGraphQL },
extensionsController.services,
params
)
.pipe(first())
.toPromise()
if (!result) {
throw new Error('No definition found.')
}
if (result.url === H.createPath(history.location)) {
// The user might be confused if they click "Go to definition" and don't go anywhere, which
// occurs if they are *already* on the definition. Give a helpful tip if they do this.
//
// Note that these tips won't show up if the definition URL is already known by the time they
// click "Go to definition", because then it's a normal link and not a button that executes
// this command. TODO: It would be nice if they also showed up in that case.
if (result.multiple) {
// The user may not have noticed the panel at the bottom of the screen, so tell them
// explicitly.
throw new Error('Multiple definitions shown in panel below.')
}
throw new Error('Already at the definition.')
}
history.push(result.url)
},
})
function symbolIsActive(symbolLocation: string, currentLocation: H.Location): boolean {
const current = parseBrowserRepoURL(H.createPath(currentLocation))
const symbol = parseBrowserRepoURL(symbolLocation)
return (
current.repoName === symbol.repoName &&
current.rev === symbol.rev &&
current.filePath === symbol.filePath &&
isEqual(current.position, symbol.position)
)
}
createRootLocation: (rootLocation, consumerLocation, consumerId) => {
const searchParams = new URLSearchParams(rootLocation.search);
searchParams.set(consumerId, createPath(consumerLocation));
const {pathname, state} = rootLocation;
return {
pathname,
search: searchParams.toString(),
state
};
}
};
export function createRootLocationForOtherConsumer(
currentRootLocation: RootLocationDescriptorObject,
consumerLocation: history.LocationDescriptorObject,
historyKey: string,
consumerPathsQueryParamName: string
): history.LocationDescriptorObject {
const allSearchParams = createSearchParams(currentRootLocation);
const consumerPaths = allSearchParams.get(consumerPathsQueryParamName);
const newConsumerPaths = addConsumerPath(
consumerPaths,
historyKey,
history.createPath(consumerLocation)
);
allSearchParams.set(consumerPathsQueryParamName, newConsumerPaths);
return {
pathname: currentRootLocation.pathname,
search: serializeSearchParams(allSearchParams),
hash: currentRootLocation.hash
};
}
export function urlFromState(enhancedRoutes, state) {
const toDispatch = []
const updatedRoutes = {}
let url = false
const currentUrl = createPath(state.routing.location)
state.routing.matchedRoutes.forEach((route) => {
const s = enhancedRoutes[route]
const newParams = s.paramsFromState(state)
const newState = s.stateFromParams(newParams)
if (changed(s.params, newParams).length) {
updatedRoutes[route] = {
...enhancedRoutes[route],
params: newParams,
state: newState,
}
toDispatch.push(actions.setParamsAndState(route, newParams, newState))
if (!url) url = s['@parser'].reverse(newParams)
}
})
const tempState = {
...state,
export function matchRoutes(enhancedRoutes, state, action, updateParams = true) {
const toDispatch = []
const lastMatches = state.routing.matchedRoutes
const path = createPath(action.payload)
const matchedRoutes = state.routing.routes.ids
.filter(filter(enhancedRoutes, path))
const exiting = diff(lastMatches, matchedRoutes)
const entering = diff(matchedRoutes, lastMatches)
if (exiting.length || entering.length) {
toDispatch.push(actions.matchRoutes(matchedRoutes))
if (exiting.length) toDispatch.push(actions.exitRoutes(exiting))
if (entering.length) toDispatch.push(actions.enterRoutes(entering))
}
if (updateParams) {
const { updatedRoutes: newEnhancedRoutes, acts } =
stateFromLocation(enhancedRoutes, state, path)
acts.forEach(act => toDispatch.push(act))
return {
newEnhancedRoutes,
toDispatch
function createURL(location) {
return typeof location === 'string' ? location : createPath(location)
}
getPath(path) {
if (path != null) {
return createPath(parsePath(path));
}
return createPath(this.getLocation());
},