mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
add IRouter interface
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
type Callback = (...args: any[]) => void;
|
export type Callback = (...args: any[]) => void;
|
||||||
|
|
||||||
interface Subscription {
|
interface Subscription {
|
||||||
owner: any;
|
owner: any;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { idGenerator } from "./core/utils";
|
|||||||
import { WEnv } from "./core/widget";
|
import { WEnv } from "./core/widget";
|
||||||
import { ActionManager } from "./services/action_manager";
|
import { ActionManager } from "./services/action_manager";
|
||||||
import { Ajax } from "./services/ajax";
|
import { Ajax } from "./services/ajax";
|
||||||
import { Router } from "./services/router";
|
import { Router, IRouter } from "./services/router";
|
||||||
|
|
||||||
export interface Menu {
|
export interface Menu {
|
||||||
title: string;
|
title: string;
|
||||||
@@ -13,7 +13,7 @@ export interface Menu {
|
|||||||
export interface Env extends WEnv {
|
export interface Env extends WEnv {
|
||||||
actionManager: ActionManager;
|
actionManager: ActionManager;
|
||||||
ajax: Ajax;
|
ajax: Ajax;
|
||||||
router: Router;
|
router: IRouter;
|
||||||
menus: Menu[];
|
menus: Menu[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { Widget } from "../core/widget";
|
|||||||
import { Env } from "../env";
|
import { Env } from "../env";
|
||||||
import { CRM } from "../widgets/crm";
|
import { CRM } from "../widgets/crm";
|
||||||
import { Discuss } from "../widgets/discuss";
|
import { Discuss } from "../widgets/discuss";
|
||||||
import { Query, Router } from "./router";
|
import { Query, IRouter } from "./router";
|
||||||
|
|
||||||
interface Type<T> extends Function {
|
interface Type<T> extends Function {
|
||||||
new (...args: any[]): T;
|
new (...args: any[]): T;
|
||||||
@@ -33,10 +33,10 @@ const actions: any[] = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
export class ActionManager extends EventBus {
|
export class ActionManager extends EventBus {
|
||||||
router: Router;
|
router: IRouter;
|
||||||
currentAction: ActionWidget | null = null;
|
currentAction: ActionWidget | null = null;
|
||||||
|
|
||||||
constructor(router: Router) {
|
constructor(router: IRouter) {
|
||||||
super();
|
super();
|
||||||
this.router = router;
|
this.router = router;
|
||||||
const query = this.router.getQuery();
|
const query = this.router.getQuery();
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { EventBus } from "../core/event_bus";
|
import { EventBus, Callback } from "../core/event_bus";
|
||||||
|
|
||||||
export type Query = { [key: string]: string };
|
export type Query = { [key: string]: string };
|
||||||
|
|
||||||
@@ -6,7 +6,16 @@ function clearSlashes(s: string): string {
|
|||||||
return s.replace(/\/$/, "").replace(/^\//, "");
|
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;
|
currentQuery: Query;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ const template = `
|
|||||||
<button t-on-click="resetCounter">Reset first counter</button>
|
<button t-on-click="resetCounter">Reset first counter</button>
|
||||||
<button t-on-click="resetCounterAsync">Reset counter 2 in 3s</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="toggle">Toggle Clock/counters</button>
|
||||||
|
<button t-on-click="updateState({})">Rerender this widget</button>
|
||||||
<input/>
|
<input/>
|
||||||
<t t-if="state.validcounter">
|
<t t-if="state.validcounter">
|
||||||
<t t-widget="Counter" t-ref="counter" t-props="{initialState:4}"/>
|
<t t-widget="Counter" t-ref="counter" t-props="{initialState:4}"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user