Skip to content

Instantly share code, notes, and snippets.

@ryanto
Forked from matt-morris/controllers.application.js
Created February 22, 2019 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ryanto/879f817895f18769fda0de970d352a72 to your computer and use it in GitHub Desktop.
Save ryanto/879f817895f18769fda0de970d352a72 to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
actions: {
update(key, value) {
console.log(`updating ${key} to ${value}`);
this.model.set(`variables.${key}`, value);
}
}
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return Ember.Object.create({
"variables": {
"foo": "bar"
},
"pages": [
{
"route": "/",
"body": [
{
"type": "partial",
"name": "header"
},
{
"type": "tag",
"name": "main",
"children": [
{
"type": "tag",
"name": "p",
"attributes": {
"class": "py-4"
},
"children": [
{
"type": "text",
"value": "lorem ipsum blah blah blah"
}
]
}
]
}
]
}
]
});
}
});
<ul>
{{#each-in model.variables as |key value|}}
<label>{{key}}</label>
{{input key-up=(action "update" key value=target.value) value=value}}
{{/each-in}}
</ul>
<div>
<label>current state</label>
{{#each-in model.variables as |k v|}}
[ {{k}} - {{v}} ]
{{/each-in}}
</div>
{{outlet}}
{
"version": "0.15.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.4.3",
"ember-template-compiler": "3.4.3",
"ember-testing": "3.4.3"
},
"addons": {
"ember-data": "3.4.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment