Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions packages/ember-glimmer/lib/component-managers/curly.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { assert, deprecate } from '@ember/debug';
import { _instrumentStart } from '@ember/instrumentation';
import { assign } from '@ember/polyfills';
import { dasherize } from '@ember/string';
import { DEBUG } from '@glimmer/env';
import {
ComponentCapabilities,
Expand Down Expand Up @@ -39,9 +38,9 @@ import { Factory as TemplateFactory, OwnedTemplate } from '../template';
import {
AttributeBinding,
ClassNameBinding,
ColonClassNameBindingReference,
IsVisibleBinding,
referenceForKey,
SimpleClassNameBindingReference,
} from '../utils/bindings';
import ComponentStateBucket, { Component } from '../utils/curly-component-state-bucket';
import { processComponentArgs } from '../utils/process-args';
Expand Down Expand Up @@ -330,11 +329,8 @@ export default class CurlyComponentManager
IsVisibleBinding.install(element, component, operations);
}

if (classRef && classRef.value()) {
const ref =
classRef.value() === true
? new ColonClassNameBindingReference(classRef, dasherize(classRef['_propertyKey']), null)
: classRef;
if (classRef) {
const ref = new SimpleClassNameBindingReference(classRef, classRef['_propertyKey']);
operations.setAttribute('class', ref, false, null);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/ember-glimmer/lib/utils/bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export const ClassNameBinding = {
},
};

class SimpleClassNameBindingReference extends CachedReference<Option<string>> {
export class SimpleClassNameBindingReference extends CachedReference<Option<string>> {
public tag: Tag;
private dasherizedPath: Option<string>;

Expand All @@ -220,7 +220,7 @@ class SimpleClassNameBindingReference extends CachedReference<Option<string>> {
}
}

export class ColonClassNameBindingReference extends CachedReference<Option<string>> {
class ColonClassNameBindingReference extends CachedReference<Option<string>> {
public tag: Tag;

constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,70 @@ moduleFor(
});
}

['@test should update class using inline if, initially false, no alternate']() {
this.registerComponent('foo-bar', { template: 'hello' });

this.render('{{foo-bar class=(if predicate "thing") }}', {
predicate: false,
});

this.assertComponentElement(this.firstChild, {
tagName: 'div',
attrs: { class: 'ember-view' },
content: 'hello',
});

this.runTask(() => set(this.context, 'predicate', true));
this.runTask(() => this.rerender());

this.assertComponentElement(this.firstChild, {
tagName: 'div',
attrs: { class: classes('ember-view thing') },
content: 'hello',
});

this.runTask(() => set(this.context, 'predicate', false));
this.runTask(() => this.rerender());

this.assertComponentElement(this.firstChild, {
tagName: 'div',
attrs: { class: 'ember-view' },
content: 'hello',
});
}

['@test should update class using inline if, initially true, no alternate']() {
this.registerComponent('foo-bar', { template: 'hello' });

this.render('{{foo-bar class=(if predicate "thing") }}', {
predicate: true,
});

this.assertComponentElement(this.firstChild, {
tagName: 'div',
attrs: { class: classes('ember-view thing') },
content: 'hello',
});

this.runTask(() => set(this.context, 'predicate', false));
this.runTask(() => this.rerender());

this.assertComponentElement(this.firstChild, {
tagName: 'div',
attrs: { class: 'ember-view' },
content: 'hello',
});

this.runTask(() => set(this.context, 'predicate', true));
this.runTask(() => this.rerender());

this.assertComponentElement(this.firstChild, {
tagName: 'div',
attrs: { class: classes('ember-view thing') },
content: 'hello',
});
}

['@test should apply classes of the dasherized property name when bound property specified is true']() {
this.registerComponent('foo-bar', { template: 'hello' });

Expand Down