Skip to content

Instantly share code, notes, and snippets.

@farisj
Created April 30, 2017 18:50
Show Gist options
  • Save farisj/12ca19ecb67bcc6b83ebd8d1368cb66a to your computer and use it in GitHub Desktop.
Save farisj/12ca19ecb67bcc6b83ebd8d1368cb66a to your computer and use it in GitHub Desktop.
Dangerous oneWays
import Ember from 'ember';
const { computed, set } = Ember;
export default Ember.Component.extend({
todo: null,
title: computed.oneWay('todo.title'),
body: computed.oneWay('todo.body'),
actions: {
updateBody(){
set(this, 'body', 'jk, do this thing. haha! youre stuck doing this thing instead');
}
}
});
import Ember from 'ember';
const { set } = Ember;
export default Ember.Controller.extend({
todos: null,
selectedTodo: null,
actions: {
pageTodo(todo) {
set(this, 'selectedTodo', todo);
}
}
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return [
{ title: 'Todo A', body: 'Do Thing A'},
{ title: 'Todo B', body: 'Do Thing B'},
{ title: 'Todo C', body: 'Do Thing C'},
]
},
setupController(controller, model) {
controller.setProperties({
todos: model
})
}
});
.todos {
margin: 75px;
text-align: center;
}
.selected-todo {
border: 1px solid black;
padding: 25px;
height: 150px;
}
.todo__content {
padding-bottom: 25px;
}
<div class="todos">
<div class="selected-todo">
{{#if selectedTodo}}
{{todo-display todo=selectedTodo}}
{{else}}
<div>Please View A Todo.</div>
{{/if}}
</div>
<br>
<div>
{{#each todos as |todo|}}
<button {{action "pageTodo" todo}}>
View {{todo.title}}
</button>
{{/each}}
</div>
</div>
<div class="todo">
<div class="todo__content">
<h3>{{title}}</h3>
<div>{{body}}</div>
</div>
<button {{action "updateBody"}}> Update body </button>
</div>
{
"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": {
"ember-data": "2.12.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment