Skip to main content

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

NameTypeDescription
serviceThisServiceModule instance
listener() => voidRedux's store subscription

Returns

Unsubscribe

Defined in

packages/reactant-module/src/interfaces.ts:147