update readme.md to add design/architeture notes

This commit is contained in:
Géry Debongnie
2019-01-27 13:31:02 +01:00
parent 5570df8bf0
commit 8b6ce52cd7
4 changed files with 131 additions and 18 deletions
+1 -1
View File
@@ -8,7 +8,7 @@ import { RootWidget } from "./widgets/root_widget";
//------------------------------------------------------------------------------
// Prepare application registry
//------------------------------------------------------------------------------
registry.addAction("discuss", Discuss);
registry.add("action", "discuss", Discuss);
//------------------------------------------------------------------------------
// Application bootstrapping
+9 -12
View File
@@ -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();
+8 -2
View File
@@ -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;