move registry to services

This commit is contained in:
Géry Debongnie
2019-01-31 20:42:45 +01:00
parent 7e90aec028
commit f165142430
4 changed files with 18 additions and 11 deletions
+2 -1
View File
@@ -1,7 +1,7 @@
import { EventBus } from "../core/event_bus";
import { Widget } from "../core/widget";
import { Env } from "../env";
import { Registry } from "../registry";
import { Registry } from "./registry";
import { Type } from "../types";
import { IRouter, Query } from "./router";
@@ -65,6 +65,7 @@ export class ActionManager extends EventBus implements IActionManager {
this.router.on("query_changed", this, this.update);
this.update(this.router.getQuery());
}
doAction(request: ActionRequest) {
if (typeof request === "number") {
// this is an action ID
+35
View File
@@ -0,0 +1,35 @@
import { Widget } from "../core/widget";
import { Env } from "../env";
import { Type } from "../types";
//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------
type ActionWidget = Type<Widget<Env, {}>>;
//------------------------------------------------------------------------------
// Registry code
//------------------------------------------------------------------------------
export class Registry {
registries: { [key: string]: { [key: string]: any } } = {
action: {}
};
add(type: "action", name: string, action: ActionWidget): Registry {
if (name in this.registries[type]) {
throw new Error(`Key ${name} already exists!`);
}
this.registries[type][name] = action;
return this;
}
getAction(name: string): ActionWidget {
return this.registries.action[name];
}
}
//------------------------------------------------------------------------------
// Main registry instance
//------------------------------------------------------------------------------
export const registry = new Registry();