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

[BUGFIX beta] Ensure closure actions are wrapped in a run loop. #12519

Merged
merged 1 commit into from
Oct 24, 2015
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
16 changes: 8 additions & 8 deletions packages/ember-routing-htmlbars/lib/keywords/closure-action.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { symbol } from 'ember-metal/utils';
import { get } from 'ember-metal/property_get';
import { labelForSubexpr } from 'ember-htmlbars/hooks/subexpr';
import EmberError from 'ember-metal/error';
import run from 'ember-metal/run_loop';

export const INVOKE = symbol('INVOKE');
export const ACTION = symbol('ACTION');
Expand Down Expand Up @@ -70,25 +71,24 @@ function createClosureAction(target, action, valuePath, actionArguments) {
var closureAction;

if (actionArguments.length > 0) {
closureAction = function() {
closureAction = function(...passedArguments) {
var args = actionArguments;
if (arguments.length > 0) {
var passedArguments = Array.prototype.slice.apply(arguments);
if (passedArguments.length > 0) {
args = actionArguments.concat(passedArguments);
}
if (valuePath && args.length > 0) {
args[0] = get(args[0], valuePath);
}
return action.apply(target, args);

return run.join(target, action, ...args);
};
} else {
closureAction = function() {
var args = arguments;
closureAction = function(...args) {
if (valuePath && args.length > 0) {
args = Array.prototype.slice.apply(args);
args[0] = get(args[0], valuePath);
}
return action.apply(target, args);

return run.join(target, action, ...args);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,3 +524,27 @@ QUnit.test('action closure does not get auto-mut wrapped', function(assert) {
innerComponent.fireAction();
});
});

QUnit.test('action should be called within a run loop', function(assert) {
assert.expect(1);

innerComponent = EmberComponent.extend({
fireAction() {
this.attrs.submit();
}
}).create();

outerComponent = EmberComponent.extend({
layout: compile(`{{view innerComponent submit=(action 'submit')}}`),
innerComponent,
actions: {
submit(newValue) {
assert.ok(run.currentRunLoop, 'action is called within a run loop');
}
}
}).create();

runAppend(outerComponent);

innerComponent.fireAction();
});