Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ember canary(v6.0.0-beta.1) scenario #645

Merged
merged 3 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions test-app/app/components/calculating-device.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<div class="calculator">
<div class="screen">
{{this.result}}
<div class="expression">
{{this.expression}}
</div>
</div>
<div class="keyboard">
<div class="numbers">
<button type="button" onclick={{fn this.keyPress "1"}}>1</button>
<button type="button" onclick={{fn this.keyPress "2"}}>2</button>
<button type="button" onclick={{fn this.keyPress "3"}}>3</button>
<button type="button" onclick={{fn this.keyPress "4"}}>4</button>
<button type="button" onclick={{fn this.keyPress "5"}}>5</button>
<button type="button" onclick={{fn this.keyPress "6"}}>6</button>
<button type="button" onclick={{fn this.keyPress "7"}}>7</button>
<button type="button" onclick={{fn this.keyPress "8"}}>8</button>
<button type="button" onclick={{fn this.keyPress "9"}}>9</button>
<button type="button" onclick={{fn this.keyPress "0"}}>0</button>
</div>
<div class="operators">
<button type="button" onclick={{fn this.keyPress "+"}}>+</button>
<button type="button" onclick={{fn this.keyPress "-"}}>-</button>
<button type="button" onclick={{fn this.keyPress "="}}>=</button>
</div>
</div>
</div>
53 changes: 26 additions & 27 deletions test-app/app/components/calculating-device.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Component from '@ember/component';
import { action } from '@ember/object';
import { computed as c } from '@ember/object';

export default Component.extend({
Expand All @@ -11,33 +12,31 @@ export default Component.extend({
},
}),

actions: {
keyPress(key) {
let result = this.result;
let stack = this.stack;
let op = this.op;
keyPress: action(function (key) {
let result = this.result;
let stack = this.stack;
let op = this.op;

switch (key) {
case '+':
case '-':
case '=':
stack.push(parseInt(op + result));
this.set('result', '');
break;
default:
this.set('result', result + key.toString());
break;
}
switch (key) {
case '+':
case '-':
case '=':
stack.push(parseInt(op + result));
this.set('result', '');
break;
default:
this.set('result', result + key.toString());
break;
}

switch (key) {
case '-':
this.set('op', '-');
break;
case '=':
result = stack.reduce((result, value) => result + value, 0);
this.set('result', result.toString());
break;
}
},
},
switch (key) {
case '-':
this.set('op', '-');
break;
case '=':
result = stack.reduce((result, value) => result + value, 0);
this.set('result', result.toString());
break;
}
}),
});
75 changes: 37 additions & 38 deletions test-app/app/controllers/calculator.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { later } from '@ember/runloop';
import Controller from '@ember/controller';
import { computed as c } from '@ember/object';
import { action } from '@ember/object';

export default Controller.extend({
init() {
Expand All @@ -20,46 +21,44 @@ export default Controller.extend({
},
}),

actions: {
keyPress(key, asyncOp) {
let exec = () => {
let result = this.expression;
let stack = this.stack;
let op = this.op;
keyPress: action(function (key, asyncOp) {
let exec = () => {
let result = this.expression;
let stack = this.stack;
let op = this.op;

switch (key) {
case '+':
case '-':
case '=':
stack.push(parseInt(op + result));
this.set('result', result);
this.set('expression', '');
break;
default:
this.set('expression', result + key.toString());
break;
}
switch (key) {
case '+':
case '-':
case '=':
stack.push(parseInt(op + result));
this.set('result', result);
this.set('expression', '');
break;
default:
this.set('expression', result + key.toString());
break;
}

switch (key) {
case '-':
this.set('op', '-');
break;
case '=':
result = stack.reduce((result, value) => result + value, 0);
this.set('expression', result.toString());
break;
}
};
switch (key) {
case '-':
this.set('op', '-');
break;
case '=':
result = stack.reduce((result, value) => result + value, 0);
this.set('expression', result.toString());
break;
}
};

if (asyncOp) {
this.set('loading', true);
later(() => {
this.set('loading', false);
exec();
}, 50);
} else {
if (asyncOp) {
this.set('loading', true);
later(() => {
this.set('loading', false);
exec();
}
},
},
}, 50);
} else {
exec();
}
}),
});
33 changes: 18 additions & 15 deletions test-app/app/templates/calculator.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,25 @@
</div>
<div class="keyboard">
<div class="numbers">
<button type="button" {{action "keyPress" "1"}}>1</button>
<button type="button" {{action "keyPress" "2"}}>2</button>
<button type="button" {{action "keyPress" "3"}}>3</button>
<button type="button" {{action "keyPress" "4"}}>4</button>
<button type="button" {{action "keyPress" "5"}}>5</button>
<button type="button" {{action "keyPress" "6"}}>6</button>
<button type="button" {{action "keyPress" "7"}}>7</button>
<button type="button" {{action "keyPress" "8"}}>8</button>
<button type="button" {{action "keyPress" "9"}}>9</button>
<button type="button" {{action "keyPress" "0"}}>0</button>
<button type="button" onclick={{fn this.keyPress "1"}}>1</button>
<button type="button" onclick={{fn this.keyPress "2"}}>2</button>
<button type="button" onclick={{fn this.keyPress "3"}}>3</button>
<button type="button" onclick={{fn this.keyPress "4"}}>4</button>
<button type="button" onclick={{fn this.keyPress "5"}}>5</button>
<button type="button" onclick={{fn this.keyPress "6"}}>6</button>
<button type="button" onclick={{fn this.keyPress "7"}}>7</button>
<button type="button" onclick={{fn this.keyPress "8"}}>8</button>
<button type="button" onclick={{fn this.keyPress "9"}}>9</button>
<button type="button" onclick={{fn this.keyPress "0"}}>0</button>
</div>
<div class="operators">
<button type="button" {{action "keyPress" "+"}}>+</button>
<button type="button" {{action "keyPress" "-"}}>-</button>
<button type="button" {{action "keyPress" "="}}>=</button>
<button type="button" {{action "keyPress" "=" true}}>async=</button>
<button type="button" onclick={{fn this.keyPress "+"}}>+</button>
<button type="button" onclick={{fn this.keyPress "-"}}>-</button>
<button type="button" onclick={{fn this.keyPress "="}}>=</button>
<button
type="button"
onclick={{fn this.keyPress "=" true}}
>async=</button>
</div>
</div>
</div>
</div>
Empty file.
27 changes: 0 additions & 27 deletions test-app/app/templates/components/calculating-device.hbs

This file was deleted.

5 changes: 1 addition & 4 deletions test-app/config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ module.exports = function (environment) {
rootURL: '/',
locationType: 'auto',
EmberENV: {
EXTEND_PROTOTYPES: false,
FEATURES: {
// Here you can enable experimental features on an ember canary build
// e.g. EMBER_NATIVE_DECORATOR_SUPPORT: true
},
EXTEND_PROTOTYPES: {
// Prevent Ember Data from overriding Date.parse.
Date: false,
},
},

APP: {
Expand Down
Loading