-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: S. Amir Mohammad Najafi <[email protected]>
- Loading branch information
Showing
3 changed files
with
31 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import {routeContextConsumer, type RouteContext} from '@alwatr/router'; | ||
|
||
import type {SignalMixinInterface} from './signal.js'; | ||
import type {Constructor} from '@alwatr/type'; | ||
|
||
export declare class RouterMixinInterface extends SignalMixinInterface {} | ||
|
||
export function RouterMixin<T extends Constructor<SignalMixinInterface>>( | ||
superClass: T, | ||
): Constructor<RouterMixinInterface> & T { | ||
class RouterMixinClass extends superClass { | ||
override connectedCallback(): void { | ||
super.connectedCallback(); | ||
this._signalListenerList.push( | ||
routeContextConsumer.subscribe(this._routeContextUpdated), | ||
); | ||
} | ||
|
||
/** | ||
* On route context update. | ||
*/ | ||
protected _routeContextUpdated(routeContext: RouteContext): void { | ||
this._logger.logMethodArgs('_routeContextUpdated', routeContext); | ||
this.requestUpdate(); | ||
} | ||
} | ||
|
||
return RouterMixinClass as unknown as Constructor<RouterMixinInterface> & T; | ||
} |