Skip to content

Instantly share code, notes, and snippets.

@jherdman
Last active August 22, 2019 18:56
Show Gist options
  • Select an option

  • Save jherdman/bc452ffbe3f718ce4d9a2c7f42a851f5 to your computer and use it in GitHub Desktop.

Select an option

Save jherdman/bc452ffbe3f718ce4d9a2c7f42a851f5 to your computer and use it in GitHub Desktop.

Revisions

  1. jherdman revised this gist Aug 22, 2019. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion controllers.application.js
    Original file line number Diff line number Diff line change
    @@ -11,12 +11,13 @@ export default Controller.extend({

    isNotReady: equal('counter', 0),

    isReady: gt('counter', 0),
    isReady: equal('counter', 1),

    actions: {
    makeReady() {
    let { counter } = this;
    this.set('counter', counter + 1);
    console.log('counter before:', counter, '; counter after:', counter + 1);
    }
    }
    });
  2. jherdman created this gist Aug 22, 2019.
    22 changes: 22 additions & 0 deletions controllers.application.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    import Controller from '@ember/controller';
    import { equal, gt } from '@ember/object/computed';

    export default Controller.extend({
    init() {
    this._super(...arguments);

    this.cars = [];
    this.set('counter', 0);
    },

    isNotReady: equal('counter', 0),

    isReady: gt('counter', 0),

    actions: {
    makeReady() {
    let { counter } = this;
    this.set('counter', counter + 1);
    }
    }
    });
    17 changes: 17 additions & 0 deletions templates.application.hbs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    {{#each cars as |car|}}
    <p>Car!</p>
    {{else}}
    <p>
    {{#if isNotReady}}
    I'm not ready
    {{else if isReady}}
    I'm ready
    {{else}}
    I'm beyond ready
    {{/if}}
    </p>
    {{/each}}

    <button {{action "makeReady"}} type="button">
    Click to make ready
    </button>
    19 changes: 19 additions & 0 deletions twiddle.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    {
    "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"
    }
    }