Skip to content

Instantly share code, notes, and snippets.

@luxzeitlos
Last active December 15, 2020 17:38
Show Gist options
  • Save luxzeitlos/dbefe8c56b91ba42ef1c5412026d25b1 to your computer and use it in GitHub Desktop.
Save luxzeitlos/dbefe8c56b91ba42ef1c5412026d25b1 to your computer and use it in GitHub Desktop.
New Twiddle
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
export default class extends Component {
get value() {
if(!this.args.value) {
return '';
}
if(Array.isArray(this.args.value) && this.args.value && this.args.value[0] === 'm') {
return 'm';
}
return this.args.value;
}
@action
check(event) {
if(event.target.value === 'm') {
this.args.update(['m']);
} else {
this.args.update(event.target.value);
}
}
@action
clear() {
this.args.update(null);
}
}
import Controller from '@ember/controller';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
}
import { helper } from '@ember/component/helper';
export default helper(function eq(params/*, hash*/) {
return params[0] == params[1];
});
<MyComponent @value={{this.value}} @update={{fn (mut this.value)}} />
<input type="radio" id="foo" value="m" checked={{eq this.value "m"}} {{on "click" this.check}}>M
<input type="radio" id="bar" value="f" checked={{eq this.value "f"}} {{on "click" this.check}}>F
<input type="radio" id="bar" value="d" checked={{eq this.value "d"}} {{on "click" this.check}}>D
<button {{on "click" this.clear}}>clear</button>
{
"version": "0.17.1",
"EmberENV": {
"FEATURES": {},
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false,
"_APPLICATION_TEMPLATE_WRAPPER": true,
"_JQUERY_INTEGRATION": true
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js",
"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