一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
39 行
1.1 KiB
TypeScript
39 行
1.1 KiB
TypeScript
export type OnNavigateCallback = ()=> Promise<boolean>;
|
|
|
|
export default class NavService {
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type -- Set by each app to its redux dispatch; defaults to a no-op and per-app action types diverge, so it is typed loosely here (see BaseModel.dispatch)
|
|
public static dispatch: Function = () => {};
|
|
private static handlers_: OnNavigateCallback[] = [];
|
|
|
|
public static async go(routeName: string, additionalProps: Record<string, unknown>|null = null) {
|
|
if (this.handlers_.length) {
|
|
const r = await this.handlers_[this.handlers_.length - 1]();
|
|
if (r) return r;
|
|
}
|
|
|
|
this.dispatch({
|
|
type: 'NAV_GO',
|
|
routeName: routeName,
|
|
...additionalProps,
|
|
});
|
|
return false;
|
|
}
|
|
|
|
public static addHandler(handler: OnNavigateCallback) {
|
|
for (let i = this.handlers_.length - 1; i >= 0; i--) {
|
|
const h = this.handlers_[i];
|
|
if (h === handler) return;
|
|
}
|
|
|
|
this.handlers_.push(handler);
|
|
}
|
|
|
|
public static removeHandler(handler: OnNavigateCallback) {
|
|
for (let i = this.handlers_.length - 1; i >= 0; i--) {
|
|
const h = this.handlers_[i];
|
|
if (h === handler) this.handlers_.splice(i, 1);
|
|
}
|
|
}
|
|
}
|