-
-
Notifications
You must be signed in to change notification settings - Fork 115
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
Added support for Promise
s in #if
and #each
.
#424
Conversation
@DanielDornhardt this is likely an Autoform issue. If so please open in Autoform and we continue to investigate there |
Would this be for Blaze 3 or 2? |
Hi @jankapunkt I mean it's probably autoform related, but as this is a change in the backwards compatibility of blaze it could potentially concern other code too I think. Also this is not yet in a meteor release, so should we make it an issue in autoform when actually the issue isn't with autoform but with the blaze change? Of course it'd make sense to investigate & see if there's a simple fix, I'm all for pragmatism here. But I just don't know whether this'd be the way to go? -> I'll make a small repo with a replication of the issue and share it here & in the autoform repo. @StorytellerCZ : It'd probably be for Blaze 2 too, as it'd be required for people to get their projects ready for 3 I guess. |
Hi, i've made a small replication & also a loom video for a quick impression. I'll also cross-post in the Loom Video: https://www.loom.com/share/a202e704da8c4600a386c5ece7e5a287?sid=cbfcff77-30fe-4832-9185-df37baf3af5e Link to the repo: https://github.com/trusted-care/autoform-sandbox-blaze-async |
Hi, I think I found the issue @radekmie : Here's a short demo: https://www.loom.com/share/8c5e5e4fa12e4858859c38d925e1c04a?sid=55c827d8-d0a5-422c-ae62-e9214678d981 |
Yeah, I see that it's not really |
Thank you @radekmie I'll check it out! :) |
Lookin' better! :D Thank you a lot! We'll see how far this will get us! |
This PR is done! I had to change the logic for I still think this is entirely backward-compatible for non-weird cases (i.e., |
Hey @radekmie , I tried "if" in our project (I am a collegue of Daniel) and added it inside an html attribute like
This is not working and the browser is running on very high load. |
@sebastianspiller I looked into it and unfortunately it's not that simple. The reason is the way Blaze handle attributes. Let's make an example: <template name="spacebars_async_tests_attributes">
<img id="{{#if x}}1{{else}}0{{/if}}">
</template> Translates to: Template.__checkName("spacebars_async_tests_attributes");
Template["spacebars_async_tests_attributes"] = new Template("Template.spacebars_async_tests_attributes", (function() {
var view = this;
return HTML.IMG({
id: function() {
return Blaze.If(function() {
return Spacebars.call(view.lookup("x"));
}, function() {
return "1";
}, function() {
return "0";
})}
});
})); The culprit is that I tried to work around it, but there's no easy way around it. I'd even argue there's no way to fix it without touching the compiler and changing the way attributes are handled. And that's a lot. |
Hi... I mean - the a) if that's an infinite loop, that probably should be prevented / the user should be warned if that's not supported c) maybe a + b can make an efficient developer rack his brain a bit whether a small compiler hack couldn't be warranted in order to avoid the busywork of both a) and b) 😄 |
I agree that for now, a detection + clear error would be needed for it to work. In the future, it could be improved by somehow marking the attribute as async and for example wrap it with |
Mmh... sounds nice... especially this part:
😄 A wise guy said something like this in the beginning of the year: "We could probably handle that on the AST level probably, by working with the AST it should be possible to replace the call.chain.resolution within blaze with a series of Is there a possibility in this direction here too? |
I just pushed some @jankapunkt, @StorytellerCZ, @Grubba27 I consider this one done. |
LGTM, what do you think @jankapunkt ? |
Could not we target the devel(v2.x) branch for this PR? This does not look to me as a breaking change. |
Having this in 2.x / 2.14 for example would definitely help people prep for Meteor 3.0 as they could start transitioning earlier and wouldn't have to convert everything all at once once they try to migrate to 3.0... And yes, for whether this'd be a breaking change, we're running with this patch for a few months now and it looks good. This PR: [https://github.com//pull/428](Implemented async attributes and content. #428) should also go into 2.x / 2.14 I think because all these things are the things which help people to prepare their projects now instead of having to wait for a stable Meteor 3.0 and having to do everything then. |
Sure, I'll rebase it. |
c6bdf78
to
f5b1152
Compare
In this pull request, I follow up on #412 and #413 by supporting
Promise
s in#if
/#unless
and#each
. The idea is basically the same as how it works in#let
except for where we actually store theReactiveVar
s.To do:
#if
/#unless
andare not rendering anything before the#each
Promise
resolves. That's to make it clear that there's nothing there. I'm open for suggestions though, as I can imagine cases where{{else}}
is more expected.#each
will treat unresolvedPromise
s as empty sequences and thus render the{{else}}
block. We may change that in the future.#if
/#unless
andare not rendering anything for rejected#each
Promise
s. This is a sane choice, but I want to confirm that with the community.#each
will treat rejectedPromise
s as empty sequences and thus render the{{else}}
block. We may change that in the future.if.__conditionVar
andeach.argVar
. They're not used anywhere, but sometimes it makes sense (e.g.,#with
depends on that).Note: #428 got merged into this branch!