Skip to content

Instantly share code, notes, and snippets.

@OmShiv
Last active April 17, 2020 04:33
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 OmShiv/83b6f2a8ad68f9e02a57933c37084ac8 to your computer and use it in GitHub Desktop.
Save OmShiv/83b6f2a8ad68f9e02a57933c37084ac8 to your computer and use it in GitHub Desktop.
New Twiddle
import Controller from '@ember/controller';
import { action, computed, set, get, setProperties } from '@ember/object';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
init() {
super.init(...arguments);
this.set('model', {
endsAt: 'some value',
totalBudget: {
amount: 'some amount'
}
});
}
@action
someMethod(campaignGroupType) {
const endsAt = get(this, 'model.endsAt');
const amount = get(this, 'model.totalBudget.amount');
if (endsAt) {
set(this, '_tempEndsAt', endsAt);
}
if (amount) {
set(this, '_tempAmount', amount);
}
switch (campaignGroupType) {
case 1:
set(this, 'model.endsAt', '');
break;
case 2:
set(this, 'model.endsAt', this._tempEndsAt);
break;
case 3:
set(this, 'model.endsAt', this._tempEndsAt);
set(this, 'model.totalBudget.amount', this._tempAmount);
break;
default:
}
}
@action
someOtherMethod(campaignGroupType) {
const endsAt = get(this, 'model.endsAt');
const amount = get(this, 'model.totalBudget.amount');
if (endsAt) {
set(this, '_tempEndsAt', endsAt);
}
if (amount) {
set(this, '_tempAmount', amount);
}
switch (campaignGroupType) {
case 1:
endsAt = '';
break;
case 2:
endsAt = this._tempEndsAt;
break;
case 3:
endsAt = this._tempEndsAt;
amount = this._tempAmount;
break;
default:
}
}
}
<h1>Welcome to {{this.appName}}</h1>
Via PROPS:<br>
<br>
<button {{action this.someMethod 1}}>Set 1</button>
<button {{action this.someMethod 2}}>Set 2</button>
<button {{action this.someMethod 3}}>Set 3</button>
<br>
_tempEndsAt: {{this._tempEndsAt}}<br>
_tempAmount: {{this._tempAmount}}<br>
model.endsAt: {{this.model.endsAt}}<br>
model.totalBudget.amount: {{this.model.totalBudget.amount}}<br>
<br>
<br>
Via Reference:<br>
<br>
<button {{action this.someOtherMethod 1}}>Set 1</button>
<button {{action this.someOtherMethod 2}}>Set 2</button>
<button {{action this.someOtherMethod 3}}>Set 3</button><br>
_tempEndsAt: {{this._tempEndsAt}}<br>
_tempAmount: {{this._tempAmount}}<br>
model.endsAt: {{this.model.endsAt}}<br>
model.totalBudget.amount: {{this.model.totalBudget.amount}}<br>
<br>
{
"version": "0.17.0",
"EmberENV": {
"FEATURES": {},
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false,
"_APPLICATION_TEMPLATE_WRAPPER": true,
"_JQUERY_INTEGRATION": true
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.17.0",
"ember-template-compiler": "3.17.0",
"ember-testing": "3.17.0"
},
"addons": {
"@glimmer/component": "1.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment