Last active
August 3, 2017 22:41
-
-
Save shawnren/17e01d557ac28cd0d70b0d248e359301 to your computer and use it in GitHub Desktop.
Calculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
init() { | |
this._super(...arguments); | |
this.set('displayValue', 0); | |
this.set('calcValueCurrent', 0); | |
this.set('calcValueNew', 0); | |
this.set('calcAction', null); | |
}, | |
actions: { | |
press(value) { | |
// INPUT NUMBERS | |
if (typeof value == 'number') { | |
this.set('calcValueNew', value); | |
this.set('displayValue', value); | |
} | |
// INPUT EVERYTHING ELSE | |
else if (typeof value === 'string') { | |
// AC (clear) | |
if (value === 'AC') { | |
this.set('displayValue', 0); | |
this.set('calcValueCurrent', 0); | |
this.set('calcValueNew', 0); | |
} | |
if (value === '+' || value === '–' || value === '×' || value === '÷') { | |
// Add | |
if (value === '+') { | |
let calcValueCurrent = this.get('calcValueCurrent'); | |
let calcValueNew = this.get('calcValueNew'); | |
let sum = calcValueCurrent + calcValueNew; | |
this.set('calcValueCurrent', sum); | |
} | |
// Update output display | |
let calcValueCurrent = this.get('calcValueCurrent', value); | |
this.set('displayValue', ''); | |
setTimeout(() => { | |
this.set('displayValue', calcValueCurrent); | |
}, 100); | |
} | |
} | |
console.log('current: ' + this.get('calcValueCurrent')); | |
console.log('new: ' + this.get('calcValueNew')); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Calculator' | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Model from "ember-data/model"; | |
import attr from "ember-data/attr"; | |
import { belongsTo, hasMany } from "ember-data/relationships"; | |
export default Model.extend({ | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Model from "ember-data/model"; | |
import attr from "ember-data/attr"; | |
import { belongsTo, hasMany } from "ember-data/relationships"; | |
export default Model.extend({ | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
margin: 12px 16px; | |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
font-size: 12pt; | |
} | |
.calc { | |
outline: 1px solid black; | |
width: 278px; | |
} | |
.output { | |
background-color: black; | |
color: white; | |
font-size: 60px; | |
text-align: right; | |
width: 250px; | |
height: 100px; | |
margin: 3px; | |
padding: 0px 10px; | |
} | |
.button { | |
outline: 1px solid grey; | |
display: inline-block; | |
width: 60px; | |
height: 50px; | |
margin: 3px; | |
text-align: center; | |
cursor: pointer; | |
font-size: 25px; | |
} | |
.button-double { | |
width: 130px; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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