Skip to content

Instantly share code, notes, and snippets.

@camskene
Last active May 29, 2020 16:31
Show Gist options
  • Save camskene/f7701113ca2d7c230011ebc3d09a1c52 to your computer and use it in GitHub Desktop.
Save camskene/f7701113ca2d7c230011ebc3d09a1c52 to your computer and use it in GitHub Desktop.
Card API
import Component from '@glimmer/component';
import { capitalize } from '@ember/string';
export default class extends Component {
get cardAttributes() {
let attributes = {
'title': this.args.card.attributes.title,
'list-key-value': this.listKeyValue,
};
return Object
.entries(attributes)
.reduce((a,[k,v]) => (v ? {...a, [k]:v} : a), {});
}
get listKeyValue() {
let { listKeyValue } = this.args.card.attributes;
if (!listKeyValue) return;
let keys = Object.keys(listKeyValue);
let attribute = keys.map((key) => {
return {
key: capitalize(key),
value: listKeyValue[key],
}
});
return attribute;
}
}
import Component from '@glimmer/component';
export default class extends Component {
}
<dl>
{{#each @data as |item|}}
<dt>{{item.key}}</dt>
<dd>{{item.value}}</dd>
{{/each}}
</dl>
{{#each-in this.cardAttributes as |componentName componentData|}}
<section>
{{component (concat 'card/' componentName) data=componentData}}
</section>
{{/each-in}}
import Component from '@glimmer/component';
export default class extends Component {
}
import Controller from '@ember/controller';
export default class ApplicationController extends Controller {
car = {
attributes: {
title: 'Car',
listKeyValue: {
make: 'Honda',
model: 'Pilot',
},
},
}
dog = {
attributes: {
title: 'Dog',
listKeyValue: {
species: 'Dog',
breed: 'Border Collie',
},
},
}
}
<Card @card={{this.car}}/>
<Card @card={{this.dog}}/>
{
"version": "0.17.1",
"EmberENV": {
"FEATURES": {},
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": true,
"_APPLICATION_TEMPLATE_WRAPPER": false,
"_JQUERY_INTEGRATION": false
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"ember": "3.18.1",
"ember-template-compiler": "3.18.1",
"ember-testing": "3.18.1"
},
"addons": {
"@glimmer/component": "1.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment