Skip to content

Commit

Permalink
Make attr.actionFn work
Browse files Browse the repository at this point in the history
  • Loading branch information
chadhietala committed Sep 29, 2016
1 parent cdd1087 commit 0a94359
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions packages/ember-glimmer/lib/helpers/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from 'ember-metal';

export const INVOKE = symbol('INVOKE');
export const ACTION = symbol('ACTION');

/**
The `{{action}}` helper provides a way to pass triggers for behavior (usually
Expand Down Expand Up @@ -341,6 +342,7 @@ export function createClosureAction(target, action, valuePath, actionArgs) {

if (actionArgLength > 0) {
closureAction = function(...passedArguments) {

let args = new Array(actionArgLength + passedArguments.length);

for (let i = 0; i < actionArgLength; i++) {
Expand Down Expand Up @@ -373,5 +375,6 @@ export function createClosureAction(target, action, valuePath, actionArgs) {
};
}

closureAction[ACTION] = true;
return closureAction;
}
5 changes: 4 additions & 1 deletion packages/ember-glimmer/lib/utils/process-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { CONSTANT_TAG } from 'glimmer-reference';
import { ARGS } from '../component';
import { UPDATE } from './references';
import { MUTABLE_CELL } from 'ember-views';
import { ACTION } from '../helpers/action';

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

if (ref[UPDATE]) {
if (typeof value === 'function' && value[ACTION]) {
attrs[name] = value;
} else if (ref[UPDATE]) {
attrs[name] = new MutableCell(ref, value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ moduleFor('Helpers test: closure {{action}}', class extends RenderingTest {
this.render('{{outer-component}}');

this.runTask(() => {
innerComponent.fireAction();
actualReturnedValue = innerComponent.fireAction();
});

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

0 comments on commit 0a94359

Please sign in to comment.