-
Notifications
You must be signed in to change notification settings - Fork 39
Conversation
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.
A few minor readme updates, very much looking forward to this change landing, thanks!
README.md
Outdated
@@ -851,18 +854,32 @@ class MyClass extends WidgetBase { | |||
|
|||
### Containers & Injectors | |||
|
|||
There is built-in support for side-loading/injecting values into sections of the widget tree and mapping them to a widget's properties. This is achieved by registering a `@dojo/widget-core/Injector` instance against a `registry` that is available to your application (i.e. set on the projector instance, `projector.setProperties({ registry })`). | |||
There is built-in support for side-loading/injecting values into sections of the widget tree and mapping them to a widget's properties. This is achieved by registering an injector factory with a `registry` and setting the registry as a property on the application's `projector` to ensure that is available to your application. |
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.
"to ensure that is available" please be more specific than "that is"
README.md
Outdated
|
||
Create an `Injector` instance and pass the `payload` that needs to be injected to the constructor: | ||
The injector factory gets passed an `invalidator` function that can be called when something has changed that requires connected widgets to `invalidate`. |
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.
can be called -> can get called
README.md
Outdated
registry.defineInjector('my-injector', injector); | ||
registry.defineInjector('my-injector', (invalidator) => { | ||
// This could be a store, but for this example is simply an instance | ||
// that accepts the injector and calls it when any of it's internal |
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 -> its
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.
Nice 👍 . Saw one typo and had one small question/suggestion.
README.md
Outdated
|
||
`getProperties` receives the `payload` from an `injector` and `properties` from the container HOC component. These are used to map into the wrapped widget's properties. | ||
`getProperties` receives the `payload` return from the injector function and the `properties` passed to the container HOC component. These are used to map into the wrapped widget's properties. |
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.
return -> returned
src/Registry.ts
Outdated
@@ -152,7 +157,7 @@ export class Registry extends Evented<{}, RegistryLabel, RegistryEventObject> im | |||
} | |||
} | |||
|
|||
public defineInjector(label: RegistryLabel, item: Injector): void { | |||
public defineInjector(label: RegistryLabel, item: InjectorFactory): void { |
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.
Since this is no longer the item
that actually ends up in the registry, maybe it'd be clearer to just name this injectorFactory
, or injector
?
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.
I can defo change that
@maier49 Think i've addressed you're feedback 👍 |
if (!this._injectorRegistry || !this.hasInjector(label)) { | ||
return null; | ||
} | ||
|
||
return this._injectorRegistry.get(label) as T; | ||
return this._injectorRegistry.get(label)!; |
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.
In the return were InjectorItem<T> | undefined
wouldn't we be able to avoid the !
?
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.
We already check whether the item exists, so we know at this point it is not undefined
and I wanted to avoid changing the API any more than required.
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.
@devpaul ^
const registeredInjectors = registeredInjectorsMap.get(this) || []; | ||
if (registeredInjectors.length === 0) { | ||
registeredInjectorsMap.set(this, registeredInjectors); | ||
} | ||
if (registeredInjectors.indexOf(injector) === -1) { | ||
if (registeredInjectors.indexOf(injectorItem) === -1) { |
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.
Can we use a WeakSet<injectorItem>
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.
This is a marked improvement over extending Injector 💯 Had a couple questions related to implementation. The architecture is sound
Type: feature
The following has been addressed in the PR:
prettier
as per the readme code style guidelinesDescription:
It has been identified that the ergonomics around using an
Injector
class as the base type when defining an injector in a registry can be awkward.Evented.emit()
, unlike everywhere else in Dojo 2, where we tend to provide abstractions on top of listening and emitting events.Injector
class and make it stateful which was never the intention.This change moves to accepting a functional factory that gets provided an invalidator and returns a function that when called will return the intended payload to be injected into the registered widgets.
If the payload never changes then the
invalidator
function can just be ignored.Resolves #911