Replies: 1 comment
-
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);
}}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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:
Beta Was this translation helpful? Give feedback.
All reactions