add IRouter interface

This commit is contained in:
Géry Debongnie
2019-01-26 18:12:54 +01:00
parent bfa76e9de5
commit c3fa3042dc
5 changed files with 18 additions and 8 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
type Callback = (...args: any[]) => void;
export type Callback = (...args: any[]) => void;
interface Subscription {
owner: any;
+2 -2
View File
@@ -3,7 +3,7 @@ import { idGenerator } from "./core/utils";
import { WEnv } from "./core/widget";
import { ActionManager } from "./services/action_manager";
import { Ajax } from "./services/ajax";
import { Router } from "./services/router";
import { Router, IRouter } from "./services/router";
export interface Menu {
title: string;
@@ -13,7 +13,7 @@ export interface Menu {
export interface Env extends WEnv {
actionManager: ActionManager;
ajax: Ajax;
router: Router;
router: IRouter;
menus: Menu[];
}
+3 -3
View File
@@ -3,7 +3,7 @@ import { Widget } from "../core/widget";
import { Env } from "../env";
import { CRM } from "../widgets/crm";
import { Discuss } from "../widgets/discuss";
import { Query, Router } from "./router";
import { Query, IRouter } from "./router";
interface Type<T> extends Function {
new (...args: any[]): T;
@@ -33,10 +33,10 @@ const actions: any[] = [
];
export class ActionManager extends EventBus {
router: Router;
router: IRouter;
currentAction: ActionWidget | null = null;
constructor(router: Router) {
constructor(router: IRouter) {
super();
this.router = router;
const query = this.router.getQuery();
+11 -2
View File
@@ -1,4 +1,4 @@
import { EventBus } from "../core/event_bus";
import { EventBus, Callback } from "../core/event_bus";
export type Query = { [key: string]: string };
@@ -6,7 +6,16 @@ function clearSlashes(s: string): string {
return s.replace(/\/$/, "").replace(/^\//, "");
}
export class Router extends EventBus {
type RouterEvent = "query_changed";
export interface IRouter {
navigate(query: Query);
on(event: RouterEvent, owner: any, callback: Callback);
getQuery(): Query;
formatURL(path: string, query: Query): string;
}
export class Router extends EventBus implements IRouter {
currentQuery: Query;
constructor() {
+1
View File
@@ -9,6 +9,7 @@ const template = `
<button t-on-click="resetCounter">Reset first counter</button>
<button t-on-click="resetCounterAsync">Reset counter 2 in 3s</button>
<button t-on-click="toggle">Toggle Clock/counters</button>
<button t-on-click="updateState({})">Rerender this widget</button>
<input/>
<t t-if="state.validcounter">
<t t-widget="Counter" t-ref="counter" t-props="{initialState:4}"/>