-
Notifications
You must be signed in to change notification settings - Fork 39
Conversation
private _get(label: RegistryLabel, globalPrecedence: boolean, getFunctionName: 'getInjector' | 'get', labelMap: Map<Registry, RegistryLabel[]>): any { | ||
const registries = globalPrecedence ? [ this._baseRegistry, this._registry ] : [ this._registry, this._baseRegistry ]; | ||
for (let i = 0; i < registries.length; i++) { | ||
const registry: any = registries[i]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No other decent type than any
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's so we can use an index using the string
function name that is passed.
If the getFunctionName
(which typing I realise is a bad name), is restricted to just 'get'
or 'getInjector'
then using registry[getFunctionName]('')
works but not if is it's typed as 'get' | 'getInjector'
, any ideas?
private _get(label: RegistryLabel, globalPrecedence: boolean, getFunctionName: 'getInjector' | 'get', labelMap: Map<Registry, RegistryLabel[]>): any {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm... Recent versions of TypeScript allow you to access properties by method name just fine, if the variable is a string literal, unless I am missing something here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was fine is I typed the argument is just 'get'
or just 'getInjector'
but not when I typed it as 'getInjector' | 'get'
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strange, the playground example types it as 'getInjector' | 'get'
... wonder what is wrong.
src/RegistryHandler.ts
Outdated
if (event.action === 'loaded') { | ||
else if (registeredLabels.indexOf(label) === -1) { | ||
const handle = registry.on(label, (event: RegistryEventObject) => { | ||
if (event.action === 'loaded' && (<any> this)[getFunctionName](label) === event.item) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(this as any)
and why the any
cast?
Type: feature
The following has been addressed in the PR:
Description:
The more that registries have been explored, the more apparent it has become that the main use cases will be to support lazy loading widgets and for injecting values into the widget tree.
These changes remove
registry
as a supported property for all widgets, so that aregistry
is only supported for aprojector
(or app level). Thisregistry
will be passed as thebaseRegistry
for all widgets within the projector tree.As well as the
baseRegistry
, each widget will have access to define entries into a local registry created per instance. These locally defined entries will take precedence over entries with the same label defined in thebaseRegistry
.The
registries
property (theRegistryHandler
) onWidgetBase
has been re-named toregistry
, as consumers will work with the handler as is they would a single registry.In advanced cases, it is possible to invert the default precedence on a case by case basis, by passing a boolean with the label to the get (
get
/getInjector
) functions, so that, if there is a item in the base registry it will be returned ahead of an item defined in the local registry.This could be useful to enable a particular default to be overridden for a widget, for example a loading widget. Locally this would be registered as
this.registry.define('my-widget-loading', DefaultLoading);
but used with the extra boolean flagthis.registry.get('my-widget-loading', true);
so that consumers could add a custom widget to their application registry to override theDefaultLoading
widget.