Module: core/subscribe
Functions
subscribe
▸ subscribe(service
, listener
): Unsubscribe
Description
You can use subscribe
to subscribe to state changes in any class module.
Example
@injectable()
class Counter {
constructor() {
subscribe(this, () => {
if (this.count === 3) {
console.log(`new value: ${newValue}`);
}
});
}
@state
count = 0;
@action
increase() {
this.count += 0;
}
}
const app = testBed({
modules: [],
main: Counter,
});
Parameters
Name | Type | Description |
---|---|---|
service | ThisService | Module instance |
listener | () => void | Redux's store subscription |
Returns
Unsubscribe