-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
this.refresh() failed to update DOM #27
Comments
Thanks for messing around with Crank! I got your example working here: https://codesandbox.io/s/crank-router-n25wq One thing I would caution against is calling components directly, as you’ve done in your example. Components can be sync functions, async functions, sync generators or async generators, so it’s not a matter of simply calling the function and getting elements. Hover over the node variable and see its inferred type if you want to see what I’m talking about. You have to handle all these cases if you want to call components directly, which is why I think it’s preferable to let Crank call your components for you. You can do this by not calling the component but creating an element with it. Let me know if any of this is unclear, |
@brainkim Your sandbox crashed in my Chrome 81: |
That looks like an error that was thrown by the mobx API? I’m not too familiar with how mobx works. Surprisingly, changing the hash still works somehow :) |
The observer() is intended to wrap a react component |
@brainkim I don't think so. Every error throws in MobX call stack will be caught by MobX, and then show a debug log. Could you give me an example code of "change hash"? |
@lishine It's just an adopter, not specific for React, for example: |
My bad |
Hey, let me know if you need any MobX specific help here - writing an adapter for MobX should be relatively simple although I think reactivity should be first class. |
@brainkim @benjamingr |
That package sort of misses the point of push vs. pull :D That said MobX observables themselves should be async iterable and if they're not - we can add that there. |
Could you make this clearer by some example codes? |
@TechQuery yes and sorry that comment by me was kind of rude. "Misses the point" isn't a very charitable way to speak, Rx is a push based abstraction (like MobX and Vue observables and they are actually the same thing). Async iterators are iterable they are a pull based abstraction. I go a bit into the differences here (I also have the slides) - but basically:
The advantage of observables and "push based" is that the fact it's simpler and the producer has more control. Pull based means things support back-pressure and building pipelines is possible. Namely, any implementation of observables with async iterators would just be a "pump" and would be very confusing in terms of back-pressure and it would also be a lot slower than a function call. After all the simplest push abstraction is a function call - and observables are in principle just: class Observable { constructor(subscribe) { this.subscribe = subscribe; } } It's a way to defer a function call to later (when you call subscribe) and then that function calls you eagerly. |
@benjamingr @benlesh also built a package to use RxJS with In old proposal edition, the return value of Async Generator was an Observable, so I think it makes sense to build an Iterable Observable object. |
RxJS observables are also async iterable as far as I know. If you're reading oldschool proposals - compositional functions is funner than for.. on :D |
@benjamingr async function* Component() {
const stream = makeStream()
for await (const state of stream)
yield <div>{state}</div>;
} If we use typical Observables, manual updating must be done: async function* Component() {
var state;
observable.subscribe(data => {
state = data;
this.refresh();
});
while (true)
yield <div>{state}</div>;
} In my opinion, the target of Generator & Async syntax is reducing count of Callbacks. |
What I was saying is that the above example (of for... await) would work with an Rx observable as well :] |
@benjamingr I didn't know RxJS can do this, so I wrote my own with TypeScript, I may try it later, thanks. |
@brainkim @benjamingr I finished the first Beta version of |
@TechQuery this is cool. I’ve been working on a router implementation myself using the history module that powers react router and works in the browser and node https://github.com/ReactTraining/history. I’ll take a look through your module and will raise some issues/PRs if you’d like! This is my initial router code https://codesandbox.io/s/charming-goodall-p2mo7 |
@brainkim |
@TechQuery There actually isn’t a need to call this.refresh with async generator components. When a crank component returns an async iterator object, it will continuously pull values from it until the component is unmounted. This means you could theoretically write code like: function Component() {
return new History().listen(this).map((routeData) => (
<div>{routeData}</div>
))[Symbol.asyncIterator]();
} I dunno if this code would work in your example, this is just to give you an idea of what you could do with async iterators. The two caveats I have are as follows:
Happy experimenting! If all questions you have are resolved, then you may want to close the issue. If on the other hand, any of this didn’t make sense, ask again and I will try to be more concrete (I’m trying to answer as many issues as I can right now so I’m moving quickly). |
Closing for housekeeping purposes. Feel free to continue the discussion. |
I wanted
I tried to use Crank with MobX, and then I wrote
observer()
adopter for Crank.I wrote
https://codesandbox.io/s/crank-router-7f5o3?file=/src/observer.ts
I got
Every invoking of
this.refresh()
created correct VDOM node, but the real DOM updated nothing...The text was updated successfully, but these errors were encountered: