Replies: 6 comments 8 replies
-
@mweststrate @FredyC @urugator @faassen any comment, guys? If there is not such API is there a chance you may consider to implement it as I think it can be really helpful in situations like mine. I could try to implement it myself if I was sure that's something that can be approved and merged. Thanks! |
Beta Was this translation helpful? Give feedback.
-
Afaik there is no such API. Personally I don't know how the impl should/could look like or what problems (if any) to expect. @mweststrate could have a better picture.
I don't think that's possible to guarantee without knowing:
|
Beta Was this translation helpful? Give feedback.
-
This question appeared right after I've failed with an attempt to use a separate reaction per template chunk because of some restrictions: after first render, when all reactions have been set up and some change has occurred in one of the nested templates and corresponding reaction triggers "rerendering" of this template and all of its parent templates (that's how Angular's On the other hand if |
Beta Was this translation helpful? Give feedback.
-
I think I've implemented a working proof-of-concept already. Will create a PR in my fork and would be grateful if you or @mweststrate or someone else who knows MobX core well enough could take a look to identify potential problems. 🙏 |
Beta Was this translation helpful? Give feedback.
-
Here it is: th0r#1 |
Beta Was this translation helpful? Give feedback.
-
Sorry, didn't look at the PR yet in depth, which might be correct as well, but I think it can be solved in the current API's already, by 'inheriting' deps from a previous reaction, and not disposing before starting new reaction to keep deps hot: const invalidate = () => {
scheduleComponentRerender();
}
let reaction = new Reaction('foo', invalidate);
reaction.track(() => {
renderComponentTemplate();
});
// ... sometime later ...
const newReaction('foo', invalidate)
newReaction.track(() => {
// register all old deps (exact API might differ, or maybe you can skip getAtom entirely)
getAtom(reaction).depencencies.forEach(d => d.reportObserved())
// All observables accesses in `renderTemplateNestedIntoComponentTemplate` will be *added* to this reaction's dependencies list
renderTemplateNestedIntoComponentTemplate();
});
// (maybe this needs to happen in above track, not sure)
reaction.dispose() // all orig deps have a second dep now, so should not go cold as a result of this dispose
reaction = newReaction; |
Beta Was this translation helpful? Give feedback.
-
Hey guys!
I'm currently working on an Angular / MobX integration as already existing library (https://github.com/mobxjs/mobx-angular) is not very efficient and I believe can be improved!
But I've faced one challenge - Angular renders component templates in chunks which means wrapping
renderComponentTemplate()
into areaction.track()
doesn't work as render functions for some inner parts of component template may be called sometime later.So, the question is whether it's possible to add tracking context to already existing reaction e.g. something like
reaction.addTracking(() => { renderNestedComponentTemplate() })
?Some pseudo-code to better explain what I'm talking about:
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions