Skip to content

Commit b1a1baf

Browse files
authored
Merge pull request #13996 from emberjs/auto-mut-action
[Bugfix Beta] Fix for auto-mut wrapping of closure actions.
2 parents 774b303 + 05fd916 commit b1a1baf

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

packages/ember-glimmer/lib/helpers/action.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
} from 'ember-metal';
1414

1515
export const INVOKE = symbol('INVOKE');
16+
export const ACTION = symbol('ACTION');
1617

1718
/**
1819
The `{{action}}` helper provides a way to pass triggers for behavior (usually
@@ -373,5 +374,6 @@ export function createClosureAction(target, action, valuePath, actionArgs) {
373374
};
374375
}
375376

377+
closureAction[ACTION] = true;
376378
return closureAction;
377379
}

packages/ember-glimmer/lib/utils/process-args.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { CONSTANT_TAG } from 'glimmer-reference';
33
import { ARGS } from '../component';
44
import { UPDATE } from './references';
55
import { MUTABLE_CELL } from 'ember-views';
6+
import { ACTION } from '../helpers/action';
67

78
export default function processArgs(args, positionalParamsDefinition) {
89
if (!positionalParamsDefinition || positionalParamsDefinition.length === 0 || args.positional.length === 0) {
@@ -50,7 +51,9 @@ class SimpleArgs {
5051
let ref = namedArgs.get(name);
5152
let value = attrs[name];
5253

53-
if (ref[UPDATE]) {
54+
if (typeof value === 'function' && value[ACTION]) {
55+
attrs[name] = value;
56+
} else if (ref[UPDATE]) {
5457
attrs[name] = new MutableCell(ref, value);
5558
}
5659

packages/ember-glimmer/tests/integration/helpers/closure-action-test.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ moduleFor('Helpers test: closure {{action}}', class extends RenderingTest {
912912
this.assert.equal(actualValue, newValue, 'property is read');
913913
}
914914

915-
['@test action closure does not get auto-mut wrapped']() {
915+
['@test action closure does not get auto-mut wrapped'](assert) {
916916
let first = 'raging robert';
917917
let second = 'mild machty';
918918
let returnValue = 'butch brian';
@@ -928,7 +928,14 @@ moduleFor('Helpers test: closure {{action}}', class extends RenderingTest {
928928
innerComponent = this;
929929
},
930930
fireAction() {
931-
actualReturnedValue = this.attrs.submit(second);
931+
this.get('submit')(second);
932+
this.get('attrs-submit')(second);
933+
let attrsSubmitReturnValue = this.attrs['attrs-submit'](second);
934+
let submitReturnValue = this.attrs.submit(second);
935+
936+
assert.equal(attrsSubmitReturnValue, submitReturnValue, 'both attrs.foo and foo should behave the same');
937+
938+
return submitReturnValue;
932939
}
933940
});
934941

@@ -952,7 +959,7 @@ moduleFor('Helpers test: closure {{action}}', class extends RenderingTest {
952959

953960
this.registerComponent('middle-component', {
954961
ComponentClass: MiddleComponent,
955-
template: `{{inner-component submit=attrs.submit}}`
962+
template: `{{inner-component attrs-submit=attrs.submit submit=submit}}`
956963
});
957964

958965
this.registerComponent('outer-component', {
@@ -963,7 +970,7 @@ moduleFor('Helpers test: closure {{action}}', class extends RenderingTest {
963970
this.render('{{outer-component}}');
964971

965972
this.runTask(() => {
966-
innerComponent.fireAction();
973+
actualReturnedValue = innerComponent.fireAction();
967974
});
968975

969976
this.assert.equal(actualFirst, first, 'first argument is correct');

0 commit comments

Comments
 (0)