Skip to content

Instantly share code, notes, and snippets.

@piotrpalek
Last active November 22, 2018 15:08
Show Gist options
  • Save piotrpalek/4da0308e741adbfd50229a73ba6ec464 to your computer and use it in GitHub Desktop.
Save piotrpalek/4da0308e741adbfd50229a73ba6ec464 to your computer and use it in GitHub Desktop.
rekruExample
import Ember from 'ember';
export default Ember.Component.extend({
value: '',
collectedValues: [],
actions: {
keyUp(event) {
this.set('value', event.target.value);
// if enter
if(event.keyCode === 13) {
this.get('collectedValues').pushObject(event.target.value);
this.set('value', '');
}
},
clear() {
this.set('collectedValues', []);
}
}
});
import Ember from 'ember';
export default Ember.Component.extend({
headCount: null,
eyeCount: null,
legCount: null,
canBreathFire: false,
canFreeze: false,
canPetrify: false,
level: 1,
victories: [],
isDragon: Ember.computed('canBreathFire', function() {
return this.get('canBreathFire') && this.get('headCount') > 1;
}),
isFake: Ember.computed('canBreathFire', 'canFreeze', 'canPetrify', function() {
const hasDeadlyPower = this.get('canBreathFire') || this.get('canFreeze') || this.get('canPetrify');
return !hasDeadlyPower;
}),
xp: Ember.computed('[email protected]', function() {
let xp = this.get('victories').reduce(function(totalXP, victory) {
return totalXP + victory.get('xp');
}, 0);
if (xp > 10) {
this.set('level', 2);
}
})
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('collector');
});
export default Router;
<header>
{{link-to "Back" "application"}}
<hr>
</header>
<div>
{{outlet}}
</div>
{{collector-input}}
<br><br>
{{collector-input}}
<input type="text" onkeyup={{action "keyUp"}} value={{value}} />
<button onclick={{action "clear"}}>Clear</button>
<br><br>
collected values:<br>
<ul>
{{#each collectedValues as |value|}}
<li>{{value}}</li>
{{/each}}
</ul>
<ul>
<li>{{link-to "Collector Input" "collector"}}</li>
<li>{{link-to "CPs" "computeds"}}</li>
</ul>
{
"version": "0.12.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.12.0",
"ember-template-compiler": "2.12.0",
"ember-testing": "2.12.0"
},
"addons": {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment