Skip to content

Instantly share code, notes, and snippets.

@fivetanley
Created October 12, 2017 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fivetanley/30d762dd413e83a1c84c7bbe208784fa to your computer and use it in GitHub Desktop.
Save fivetanley/30d762dd413e83a1c84c7bbe208784fa to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
import { task, timeout } from 'ember-concurrency';
const steps = [
{
type: 'static',
message: 'i am totally a human!'
},
{
type: 'select',
message: 'what will you do with your life',
options: [
{
value: 'pizza',
message: 'eat pizza'
},
{
value: 'log_off',
message: 'go outside'
}
]
},
{
type: 'static',
message: 'no way! that is so interesting'
}
];
export default Ember.Component.extend({
init() {
this._super(...arguments);
this.get('converse').perform();
},
converse: task(function *() {
this.set('renderedItems', []);
for (let step of steps) {
this.get('renderedItems').pushObject(step);
if (step.type !== 'static') {
yield new Ember.RSVP.Promise((resolve) => {
this.resolve = resolve;
});
this.set('fakeMessage', true);
yield timeout(1000);
this.set('fakeMessage', false);
}
}
}),
actions: {
submit() {
alert('congrats!!');
},
selectOption(item, option, resolve) {
// idk do stuff here
this.resolve();
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
{{decision-tree}}
{{yield}}
<ul>
{{#each renderedItems as |item|}}
<li>{{item.type}} - {{item.message}}
{{#if (eq item.type 'select')}}
<ul>
{{#each item.options as |option|}}
<li>{{option.message}} <button {{action "selectOption" item option}}>select</button></li>
{{/each}}
</ul>
{{/if}}
</li>
{{/each}}
{{#if fakeMessage}}
loading lmao...
{{/if}}
{{#if (and (not converse.isRunning) converse.lastSuccessful)}}
<button {{action "submit"}}>Looks good</button>
<button {{action (perform converse)}}>reset!!</button>
{{/if}}
</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": {
"ember-data": "2.12.1",
"ember-concurrency": "0.8.10",
"ember-truth-helpers": "1.3.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment