forked from mystiq/hydrogen-web
Complete converting Navigation.js to ts
This commit is contained in:
parent
04d5b9bfda
commit
3efc426fed
1 changed files with 10 additions and 8 deletions
|
@ -34,6 +34,7 @@ type SegmentType = {
|
||||||
"member": string;
|
"member": string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export class Navigation<T> {
|
export class Navigation<T> {
|
||||||
private readonly _allowsChild: AllowsChild;
|
private readonly _allowsChild: AllowsChild;
|
||||||
private _path: Path<T>;
|
private _path: Path<T>;
|
||||||
|
@ -54,8 +55,8 @@ export class Navigation<T> {
|
||||||
return this._path;
|
return this._path;
|
||||||
}
|
}
|
||||||
|
|
||||||
push(type, value = undefined): void {
|
push<K extends keyof T>(type: K, ...value: T[K] extends true? [undefined?]: [T[K]]): void {
|
||||||
const newPath = this.path.with(new Segment(type, value));
|
const newPath = this.path.with(new Segment(type, ...value));
|
||||||
if (newPath) {
|
if (newPath) {
|
||||||
this.applyPath(newPath);
|
this.applyPath(newPath);
|
||||||
}
|
}
|
||||||
|
@ -106,8 +107,8 @@ export class Navigation<T> {
|
||||||
return new Path(segments, this._allowsChild);
|
return new Path(segments, this._allowsChild);
|
||||||
}
|
}
|
||||||
|
|
||||||
segment<K extends keyof T>(type: K, value: T[K]): Segment<T> {
|
segment<K extends keyof T>(type: K, ...value: T[K] extends true? [undefined?]: [T[K]]): Segment<T> {
|
||||||
return new Segment(type, value);
|
return new Segment(type, ...value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,10 +131,11 @@ function segmentValueEqual<T>(a?: T[keyof T], b?: T[keyof T]): boolean {
|
||||||
|
|
||||||
|
|
||||||
export class Segment<T, K extends keyof T = any> {
|
export class Segment<T, K extends keyof T = any> {
|
||||||
constructor(
|
public value: T[K];
|
||||||
public type: K,
|
|
||||||
public value: T[K] = (value === undefined ? true : value) as T[K]
|
constructor(public type: K, ...value: T[K] extends true? [undefined?]: [T[K]]) {
|
||||||
) {}
|
this.value = (value[0] === undefined ? true : value[0]) as unknown as T[K];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Path<T> {
|
class Path<T> {
|
||||||
|
|
Loading…
Reference in a new issue