modelFlow has to be used over functions #469
Answered
by
xaviergonz
aboyer1013
asked this question in
Q&A
-
Looking for some guidance here with regards to errors when using inheritance with abstract classes. I'm not sure if this is a mobx-keystone bug or a misunderstanding of abstract classes and how they work in TypeScript. I have to declare the method (fetch2) in the base class in order to resolve the error. Essentially, a noop filler just to get rid of the error. I have some questions:
I appreciate any feedback. Thanks! import {
_async,
_await,
ExtendedModel,
model,
Model,
modelFlow,
idProp,
prop,
modelAction
} from "mobx-keystone";
abstract class BaseModel extends Model({
id: idProp,
name: prop<string>()
}) {
// If this method is removed, the error goes away.
@modelFlow
fetchData = _async(function* (this: BaseModel) {
const promise = new Promise((resolve) => {
setTimeout(() => {
resolve("done");
}, 3000);
});
const response = yield* _await(promise);
console.log("response: ", response);
});
// In order to resolve, this method must be declared in the base model. Uncomment the next line to resolve.
// fetch2: () => void = () => {}
}
// If this class is removed, the error goes away.
@model("ModelA")
class A extends ExtendedModel(BaseModel, {
foo: prop<string>()
}) {}
@model("ModelB")
class B extends ExtendedModel(BaseModel, {
foo: prop<string>()
}) {
// The existence of fetch2 produces an error: modelFlow has to be used over functions
@modelFlow
fetch2 = _async(function* (this: BaseModel) {
const promise = new Promise((resolve) => {
setTimeout(() => {
resolve("done");
}, 3000);
});
const response = yield* _await(promise);
console.log("response: ", response);
});
@modelAction
something() {
this.foo = "foo";
}
}
const a = new A({
foo: "bar",
name: "test"
});
console.log(a.name); |
Beta Was this translation helpful? Give feedback.
Answered by
xaviergonz
Jul 9, 2022
Replies: 1 comment 1 reply
-
@aboyer1013 fixed in 0.69.2 |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
aboyer1013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@aboyer1013 fixed in 0.69.2