ViewLinker
This service wires up a class instance with custom behavior for dealing with communication between multiple views. The instance is usually decorated with decorators that describe the actions needing to be performed. Such actions are resolving a view, inserting Renderables into the current layout, or querying for specific views and interacting with them.
Due to the async nature of component resolution, it is important to never store the component instances
as they could change over the course of the layouts lifecycle. This is why we set up a ViewResolve
to
get the component we want.
Example:
class MyController {
@ViewResolve({ token: SomeOtherComponent })
getSomeOtherComponent: Observable<SomeOtherComponent>;
@ViewQuery({ token: MyComponent })
onMyViewResolved(component: MyComponent): void {
// MyComponent has stream for selecting something.
component.somethingSelected.subscribe(thing => {
// When MyComponent selected something, set it on SomeOtherComponent.
this.getSomeOtherComponent().subscribe(otherComp => {
otherComp.setSomething(thing);
});
});
}
}
// Lets assume I have the viewLinker instance from the root layout I'm working with.
const myController = new MyController();
viewLinker.autowire(myController);
Static Method Summary
Static Public Methods | ||
public static |
readMetadata(target: *): * |
Constructor Summary
Public Constructor | ||
public |
constructor(_viewManager: *, _injector: *, _manipulator: *) |
Method Summary
Public Methods | ||
public |
autowire(instance: object): Subscription Wires all types of custom behavior for linker |
|
public |
readMetadata(instance: object): ViewLinkerMetadata Reads metadata from a class instance. |
|
public |
readQuery(query: Observable<ViewContainer<T>>, options: ViewQueryReadType | ViewQueryReadOptions): Observable<any> Reads a query observable from the view manager. |
|
public |
wireInsert(instance: object, config: ViewInsertConfig) Wires a view insert on the instance using the provided config. |
|
public |
wireQuery(instance: object, config: ViewQueryConfig): Subscription Wires a query on the instance using the provided config. |
|
public |
wireResolve(instance: object, config: ViewResolveConfig) Wires a resolve method with the given config. |
Static Public Methods
public static readMetadata(target: *): * source
Params:
Name | Type | Attribute | Description |
target | * |
Return:
* |
Public Constructors
public constructor(_viewManager: *, _injector: *, _manipulator: *) source
Params:
Name | Type | Attribute | Description |
_viewManager | * | ||
_injector | * | ||
_manipulator | * |
Public Methods
public autowire(instance: object): Subscription source
Wires all types of custom behavior for linker
Params:
Name | Type | Attribute | Description |
instance | object |
public readMetadata(instance: object): ViewLinkerMetadata source
Reads metadata from a class instance.
Params:
Name | Type | Attribute | Description |
instance | object |
Return:
ViewLinkerMetadata |
public readQuery(query: Observable<ViewContainer<T>>, options: ViewQueryReadType | ViewQueryReadOptions): Observable<any> source
Reads a query observable from the view manager. A ViewQuery
decorated method can be given a different
argument depending on how you need to interact with the view. If we need the component then the
query will wait until the component is in a ready state. If we need the ViewContainer then it
will be given to us regardless of whether the component is ready or not. We can also request the query
observable instead if we want some custom resolution logic.
Params:
Name | Type | Attribute | Description |
query | Observable<ViewContainer<T>> | ||
options | ViewQueryReadType | ViewQueryReadOptions |
|
public wireInsert(instance: object, config: ViewInsertConfig) source
Wires a view insert on the instance using the provided config.
Params:
Name | Type | Attribute | Description |
instance | object | ||
config | ViewInsertConfig |
public wireQuery(instance: object, config: ViewQueryConfig): Subscription source
Wires a query on the instance using the provided config.
Params:
Name | Type | Attribute | Description |
instance | object | ||
config | ViewQueryConfig |