-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[Glimmer2] inline if #12920
[Glimmer2] inline if #12920
Conversation
@@ -0,0 +1,11 @@ | |||
import { toBool as emberToBool } from './if-unless'; | |||
|
|||
//TODO: GJ: docs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rwjblue says the docs for if should be moved to this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And thanks for noting this. In 1.13 we lost a ton of docs b/c PRs were merged without this stuff. Definitely worth doing up front.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, I'll do that
☔ The latest upstream changes (presumably #12924) made this pull request unmergeable. Please resolve the merge conflicts. |
I'm going to work on this later tonight and hopefully bring it to completion |
There are a number of shared tests which fail in moduleFor('Helpers test: {{if}} used with another helper', class extends SharedHelperConditionalsTest {
templateFor({ cond, truthy, falsy }) {
return `{{concat (if ${cond} ${truthy} ${falsy})}}`;
}
}); I want to avoid marking these shared tests with a moduleFor('@glimmer Helpers test: {{if}} used with another helper', class extends SharedHelperConditionalsTest {
templateFor({ cond, truthy, falsy }) {
return `{{concat (if ${cond} ${truthy} ${falsy})}}`;
}
}); |
I'm seeing 14 test failures for both moduleFor('@glimmer Helpers test: {{if}} used in attribute position', class extends SharedHelperConditionalsTest {
templateFor({ cond, truthy, falsy }) {
return `<div data-foo="{{if ${cond} ${truthy} ${falsy}}}" />`;
}
textValue() {
return jQuery('div', this.element).toArray().map(
function(el) { return jQuery(el).data('foo'); }
).join('');
}
}); an example failing test is |
@GavinJoyce I think the problem is you didn't quote the "truthy" and "falsy" properly: it currently something like By the way, I think it will be better to add |
@chancancode thanks, I'll implement the I don't think it is a quoting problem, the
I can't immediately see why this isn't working, but I'm pretty sure I'm doing something wrong. I'll change it to use |
Ah, you are right! I forgot that we changed it to be dynamic |
TODO: figure out why this passes: moduleFor('Helpers test: {{if}} used in attribute position', class extends SharedHelperConditionalsTest {
wrapperFor(templates) {
return `<div>${templates.join('')}</div>`;
}
templateFor({ cond, truthy, falsy }) {
return `{{if ${cond} ${truthy} ${falsy}}}`;
}
textValue() {
return jQuery('div', this.element).text();
}
}); but this doesn't: moduleFor('Helpers test: {{if}} used in attribute position', class extends SharedHelperConditionalsTest {
wrapperFor(templates) {
return `<div data-foo="${templates.join('')}" />`;
}
templateFor({ cond, truthy, falsy }) {
return `{{if ${cond} ${truthy} ${falsy}}}`;
}
textValue() {
return jQuery('div', this.element).data('foo');
}
}); |
@paddyobrien solved this for me. It turns out that jQuery caches the data attribute values when accessing the values using:
This solves it:
|
Ahh I see. It's probably good to use attr anyway so jQuery doesn't try to parse the text |
This is ready for review |
@chancancode - Would you mind reviewing? |
@GavinJoyce can you do me a favor and annotate the deleted test case with comments like these? #12914 (comment) We are trying to be careful to not lose coverage as we migrate these, and having those annotations would make it a lot easier to review! ❤️ The tests doesn't always have to be a direct port. We implicitly test a lot more things with the new harness/pattern, so it is quite possible we absorbed some existing test cases into other test cases implicitly (e.g. we used to have separate test cases for re-render, but we now test re-render all the time, so it makes sense to just delete it). |
@chancancode sure, I'll do that now |
|
||
}, BASIC_TRUTHY_TESTS, BASIC_FALSY_TESTS); | ||
|
||
moduleFor('@glimmer Helpers test: {{if}} used with another helper', class extends SharedHelperConditionalsTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@glimmer
only as several of these tests fail in @htmlbars
(see #12925)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😢
@chancancode I've added a I've also added annotations for the two modules which are |
QUnit.module(`[${packageName}] ${description}`, { | ||
let modulePackagePrefixMatch = description.match(/^@(\w*)/); //eg '@glimmer' or '@htmlbars' | ||
let modulePackagePrefix = modulePackagePrefixMatch ? modulePackagePrefixMatch[1] : ''; | ||
let descriptionWithoutPackagePrefix = description.replace(/^@\w* /, ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this adds support for module prefixes such as @glimmer
and @htmlbars
and is needed as the new comprehensive shared tests have highlighted some issues with htmlbars
Let me know if you'd like me to annotate anything else |
@GavinJoyce sorry! I should have looked more carefully – I copied the comment from here assuming it would make sense. Can you review the existing tests and either delete (with the annotation) them or migrate them into the new test files? If some of them are too hard to port we can leave them in the old file and come back to them later; but I suspect your work already covered the majority of them, so seems good to have you review and delete them while your memory is still fresh. Great work so far by the way, thank you so much for picking this up!! |
Ah, thanks for the clarification. Sure, I'll do that on Saturday which will be the next time I'll get to work on this. I'm happy to continue working on glimmer2 integration once this has merged too, we're very excited to begin using it Intercom |
return args[1]; | ||
} else { | ||
let falsyArgument = args[2]; | ||
return falsyArgument === undefined ? '' : falsyArgument; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose this is needed to pass the tests at the moment? Can you add a TODO here? I believe we should unconditional return args[2]
here (even if it's undefined) and let a different part of the system handle converting undefined
, null
, etc to ""
(which we haven't implemented yet).
It's probably good to add a test for this case if we don't already have one (I think it would have to be @htmlbars
for now), but perhaps that should be part of the general checklist item of "Add tests for rending false, undefined, null etc in content-test.js, similar to..."
this.render(`{{if condition truthy}}`, { condition: true, truthy: null });
this.render(`{{if condition truthy}}`, { condition: true, truthy: undefined });
this.render(`{{if condition truthy}}`, { condition: true, truthy: false });
...etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, this was added to allow the moved it can omit the falsy argument
test to pass. I'll modify this test to be @htmlbars
and add a TODO as you suggest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this got lost in the merge too, we retained the TODO comment but lost the @htmlbars marker
@chancancode thanks for your feedback. I've made the following changes:
|
this.runTask(() => set(this.context, 'condition', true)); | ||
|
||
this.assertText('yes'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
We should test both starting conditions (starting with true
and starting with false
), like this: https://github.com/emberjs/ember.js/blob/master/packages/ember-glimmer/tests/integration/syntax/if-unless-test.js#L52-L79
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, done
I ran out of time for this review session, I'll return to it another time! But I have left some "big picture" comments for you to chew on at the moment! |
Thanks for your feedback @chancancode. I'm keen to nail these testing patterns early so that the we can quickly and comprehensively integrate the rest of glimmer2 into ember |
this.assertText('falsy'); | ||
} | ||
|
||
['@test it updates when given a falsey second argument']() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤘 (I guess this must be a regression test?)
@@ -78,6 +86,7 @@ export class RenderingTest extends TestCase { | |||
let owner = this.owner = buildOwner(); | |||
let env = this.env = new Environment({ dom, owner }); | |||
this.renderer = new Renderer(dom, { destinedForDOM: true, env }); | |||
this.$ = jQuery; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, this is not what I meant, I mean something like how this.$()
works in components, but I can fix it
Merge + minor cleanup for #12920
This is really awesome! Thanks for taking the time to work on this @GavinJoyce ❤️ 💚 💛 💙 💜 |
part of the Glimmer Big-Picture Integration Checklist
TODO:
@glimmer
onlyBASIC_TRUTHY_TESTS
&BASIC_FALSY_TESTS
SharedConditionalsTest
so that it can be used by both block and inline helpers@glimmer
or@htmlbars
prefixes