Class: ObservablePlugin
Defined in: src/wirestate-mobx/plugin/observable-plugin.ts:40
Applies MobX decorator annotations to every service the container activates.
Remarks
Optional shortcut. Legacy MobX decorators such as @Observable() only record annotations, and the regular way to apply them is makeObservable(this) in the service constructor. Register this plugin once on a container and the call happens at activation instead: after construction and field initializers, before the service's own @OnActivation, and for every container in the subtree.
A service that still calls makeObservable(this) itself keeps working. A service without annotations, or one decorated with TC39 decorators, which MobX applies immediately, is left alone.
Example
import { Container, Injectable } from "@wirestate/core";
import { Action, Observable, ObservablePlugin } from "@wirestate/mobx";
@Injectable()
class CounterService {
@Observable()
public count: number = 0;
@Action()
public increment(): void {
this.count += 1;
}
}
const container = new Container({ bindings: [CounterService], plugins: [new ObservablePlugin()] });Implements
Constructors
Constructor
new ObservablePlugin(): ObservablePlugin;Returns
ObservablePlugin
Methods
onActivate()
onActivate(instance: object): void;Defined in: src/wirestate-mobx/plugin/observable-plugin.ts:41
Runs after a service instance is activated, before its @OnActivation.
Parameters
| Parameter | Type | Description |
|---|---|---|
instance | object | The activated instance. |
Returns
void