-
-
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] Fix class bindings #13337
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,39 @@ function wrapClassAttribute(args) { | |
return args; | ||
} | ||
|
||
function wrapClassBindingAttribute(args) { | ||
let hasClassBinding = args.named.has('classBinding'); | ||
|
||
if (hasClassBinding) { | ||
let { value , type } = args.named.at('classBinding'); | ||
if (type === 'value') { | ||
let [ prop, truthy, falsy ] = value.split(':'); | ||
let spec; | ||
if (prop === '') { | ||
spec = ['helper', ['-class'], [truthy], null]; | ||
} else if (falsy) { | ||
let parts = prop.split('.'); | ||
spec = ['helper', ['-class'], [['get', parts], truthy, falsy], null]; | ||
} else if (truthy) { | ||
let parts = prop.split('.'); | ||
spec = ['helper', ['-class'], [['get', parts], truthy], null]; | ||
} | ||
|
||
if (spec) { | ||
let syntax; | ||
if (args.named.has('class')) { | ||
// If class already exists, merge | ||
let classValue = args.named.at('class').value; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This currently won't work with helpers. If we need to support this, we'll need a way to generate a spec from a helper. |
||
syntax = HelperSyntax.fromSpec(['helper', ['concat'], [classValue, ' ', spec]]); | ||
} else { | ||
syntax = HelperSyntax.fromSpec(spec); | ||
} | ||
args.named.add('class', syntax); | ||
} | ||
} | ||
} | ||
} | ||
|
||
export default class Environment extends GlimmerEnvironment { | ||
static create(options) { | ||
return new Environment(options); | ||
|
@@ -94,6 +127,7 @@ export default class Environment extends GlimmerEnvironment { | |
let definition = this.getComponentDefinition(path); | ||
|
||
if (definition) { | ||
wrapClassBindingAttribute(args); | ||
wrapClassAttribute(args); | ||
return new CurlyComponentSyntax({ args, definition, templates }); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,14 +3,21 @@ import { dasherize } from 'ember-runtime/system/string'; | |
|
||
function classHelper({ positional }) { | ||
let path = positional.at(0); | ||
let propName = positional.at(1); | ||
let truthyPropName = positional.at(1); | ||
let falsyPropName = positional.at(2); | ||
let value = path.value(); | ||
|
||
if (value === true) { | ||
return dasherize(propName.value()); | ||
if (truthyPropName) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When is this not the case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
return dasherize(truthyPropName.value()); | ||
} | ||
return null; | ||
} | ||
|
||
if (value === false) { | ||
if (falsyPropName) { | ||
return dasherize(falsyPropName.value()); | ||
} | ||
return null; | ||
} | ||
|
||
|
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.
doesn't need the helper