mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
update readme.md to add design/architeture notes
This commit is contained in:
@@ -8,7 +8,7 @@ import { RootWidget } from "./widgets/root_widget";
|
||||
//------------------------------------------------------------------------------
|
||||
// Prepare application registry
|
||||
//------------------------------------------------------------------------------
|
||||
registry.addAction("discuss", Discuss);
|
||||
registry.add("action", "discuss", Discuss);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Application bootstrapping
|
||||
|
||||
@@ -14,23 +14,20 @@ type ActionWidget = Type<Widget<Env>>;
|
||||
// Registry code
|
||||
//------------------------------------------------------------------------------
|
||||
export class Registry {
|
||||
actions: { [key: string]: ActionWidget } = {};
|
||||
registries: { [key: string]: { [key: string]: any } } = {
|
||||
action: {}
|
||||
};
|
||||
|
||||
addAction(name: string, action: ActionWidget): Registry {
|
||||
return this.addToRegistry(this.actions, name, action);
|
||||
}
|
||||
|
||||
private addToRegistry<T>(
|
||||
map: { [k: string]: T },
|
||||
name: string,
|
||||
elem: T
|
||||
): Registry {
|
||||
if (name in map) {
|
||||
add(type: "action", name: string, action: ActionWidget): Registry {
|
||||
if (name in this.registries[type]) {
|
||||
throw new Error(`Key ${name} already exists!`);
|
||||
}
|
||||
map[name] = elem;
|
||||
this.registries[type][name] = action;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Main registry instance
|
||||
//------------------------------------------------------------------------------
|
||||
export const registry = new Registry();
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { EventBus, Callback } from "../core/event_bus";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types and helpers
|
||||
//------------------------------------------------------------------------------
|
||||
export type Query = { [key: string]: string };
|
||||
|
||||
function clearSlashes(s: string): string {
|
||||
@@ -9,12 +12,15 @@ function clearSlashes(s: string): string {
|
||||
type RouterEvent = "query_changed";
|
||||
|
||||
export interface IRouter {
|
||||
navigate(query: Query);
|
||||
on(event: RouterEvent, owner: any, callback: Callback);
|
||||
navigate(query: Query): void;
|
||||
on(event: RouterEvent, owner: any, callback: Callback): void;
|
||||
getQuery(): Query;
|
||||
formatURL(path: string, query: Query): string;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Router
|
||||
//------------------------------------------------------------------------------
|
||||
export class Router extends EventBus implements IRouter {
|
||||
currentQuery: Query;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user