MCPcopy
hub / github.com/conwnet/github1s / initialize

Method initialize

extensions/github1s/src/router/index.ts:37–56  ·  view source on GitHub ↗
(urlManager: UrlManager)

Source from the content-addressed store, hash-verified

35
36 // initialize the router with current url in browser
37 async initialize(urlManager: UrlManager) {
38 this._manager = urlManager;
39 this._parser = await adapterManager.getCurrentAdapter().resolveRouterParser();
40 const { path: pathname, query, fragment } = vscode.Uri.parse(await this._manager.href());
41 const path = pathname + (query ? `?${query}` : '') + (fragment ? `#${fragment}` : '');
42
43 this._state = await this._parser.parsePath(path);
44 this._history = createMemoryHistory({ initialEntries: [path] });
45
46 this._history.listen(async ({ action, location }) => {
47 const prevState = this._state;
48 const targetPath = `${location.pathname}${location.search}${location.hash}`;
49 const routerParser = await adapterManager.getCurrentAdapter().resolveRouterParser();
50
51 this._manager?.[action === Action.Push ? 'push' : 'replace'](targetPath);
52 this._state = await routerParser.parsePath(targetPath);
53 super.notifyListeners(this._state, prevState);
54 });
55 this._barrier.open();
56 }
57
58 // get the routerState for current url
59 public async getState(): Promise<RouterState> {

Callers 3

activateFunction · 0.80
createStorageServiceMethod · 0.80

Calls 6

getCurrentAdapterMethod · 0.80
hrefMethod · 0.80
notifyListenersMethod · 0.80
resolveRouterParserMethod · 0.65
openMethod · 0.65
parsePathMethod · 0.45

Tested by

no test coverage detected