choo icon indicating copy to clipboard operation
choo copied to clipboard

Asynchronous render

Open diffcunha opened this issue 7 years ago • 11 comments
trafficstars

Fixes #645

diffcunha avatar Mar 14 '18 15:03 diffcunha

This code requires that any browser or node instance that doesn't support async be compiled using babel and the polyfill being included.

Being that we still have support enabled for IE 11 and Safari (browser which represent more than 1% of usage), this adds a lot of weight to choo. (babel-poylfill is around 85k depending on compression which is MUCH larger than choo)

toddself avatar Mar 14 '18 15:03 toddself

I just realised that, I'm removing async/await now

diffcunha avatar Mar 14 '18 16:03 diffcunha

Also, check out my comments in #645 -- there are other ways to do this without needing to change how choo works

toddself avatar Mar 14 '18 16:03 toddself

I forgot to mention but this change is also backward compatible, normal sync rendering will still work

diffcunha avatar Mar 14 '18 17:03 diffcunha

Promise still needs to be shimmed for IE 11 (so we'd likely also need to include a promises implementation in core).

toddself avatar Mar 14 '18 17:03 toddself

Does it have to be included in core? It could be up to the developer to decide if she wants it or not and which shim to use. Otherwise we could use es6-promise in core, it takes 2.4 KB gziped

diffcunha avatar Mar 15 '18 13:03 diffcunha

I think this whole PR could fit for a store. Since the the .use function expose the app instance, you can change whatever you want there, maybe is a good idea to have it as astore and make some tests and bench on top of it.

YerkoPalma avatar Mar 15 '18 13:03 YerkoPalma

@YerkoPalma that's actually a good idea. I could definitely do it but, there is a recent change to delegate store initialisation (https://github.com/choojs/choo/pull/638), it makes it harder since the patching would only be applied after calling start or toString and I also need to patch those 2

diffcunha avatar Mar 15 '18 15:03 diffcunha

@toddself I updated the PR so that the a Promise shim is only required if the developer wants to go with async rendering. If there are no promises being passed to html, everything works just like before.

diffcunha avatar Mar 16 '18 18:03 diffcunha

I really like this implementation, as it brings the best of both worlds and it's not a breaking change. I would add some more tests with mixed values (promises, literals) as well.

mcollina avatar Mar 17 '18 07:03 mcollina

Any update on this? :)

Anything a noob contributor (me lol) could help out with?

Powersource avatar Apr 14 '19 19:04 Powersource