Replies: 1 comment 2 replies
That's true, but more importantly options never change in your example. class FieldWithOptions {
constructor(private readonly optionsStore: { options: { value: string } }) {
reaction(
() => this.someStore.options,
() => {
console.log('Reacting');
}
);
}
}
class SomeStore {
@observable value = 'initial value';
readonly field: FieldWithOptions ;
constructor() {
makeObservable(this);
// Initialize FieldWithOptions after makeObservable call, so that `SomeStore` is already observable in FieldWithOptions constructor
this.field = new FieldWithOptions(this);
}
@computed
get options() {
return {
value: this.value,
};
}
}or standalone computed/observable class FieldWithOptions {
constructor(private readonly options: { get: () => { value: string } }>) {
reaction(
() => this.someStore.options.get(),
() => {
console.log('Reacting');
}
);
}
}
class SomeStore {
@observable value = 'initial value';
readonly options = computed(() => {
return {
value: this.value,
};
});
readonly field: FieldWithOptions;
constructor() {
makeObservable(this);
this.field = new FieldWithOptions(this.options);
}}
} |
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
i have something like this, and reaction never react on option changes. as i understand at the moment of field initialization options are not observable yet. how can i fix it:
All reactions