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

Adding positional parameter support to components #11028

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"express": "^4.5.0",
"github": "^0.2.3",
"glob": "~4.3.2",
"htmlbars": "0.13.12",
"htmlbars": "git://github.com/ef4/htmlbars#component-params-prebuilt",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update to 0.13.14, just released upstream PR.

"qunit-extras": "^1.3.0",
"qunitjs": "^1.16.0",
"route-recognizer": "0.1.5",
Expand Down
3 changes: 2 additions & 1 deletion packages/ember-htmlbars/lib/hooks/component.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ComponentNodeManager from "ember-htmlbars/node-managers/component-node-manager";

export default function componentHook(renderNode, env, scope, tagName, attrs, template, visitor) {
export default function componentHook(renderNode, env, scope, tagName, params, attrs, template, visitor) {
var state = renderNode.state;

// Determine if this is an initial render or a re-render
Expand All @@ -14,6 +14,7 @@ export default function componentHook(renderNode, env, scope, tagName, attrs, te

var manager = ComponentNodeManager.create(renderNode, env, {
tagName,
params,
attrs,
parentView,
template,
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-htmlbars/lib/keywords/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ export default {
return;
}

env.hooks.component(morph, env, scope, componentPath, hash, template, visitor);
env.hooks.component(morph, env, scope, componentPath, params, hash, template, visitor);
}
};
2 changes: 1 addition & 1 deletion packages/ember-htmlbars/lib/keywords/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default {
},

render(morph, env, scope, params, hash, template, inverse, visitor) {
env.hooks.component(morph, env, scope, morph.state.componentName, hash, template, visitor);
env.hooks.component(morph, env, scope, morph.state.componentName, params, hash, template, visitor);
},

rerender(...args) {
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-htmlbars/lib/keywords/textarea.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
*/

export default function textarea(morph, env, scope, originalParams, hash, template, inverse, visitor) {
env.hooks.component(morph, env, scope, '-text-area', hash, template, visitor);
env.hooks.component(morph, env, scope, '-text-area', originalParams, hash, template, visitor);
return true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default ComponentNodeManager;

ComponentNodeManager.create = function(renderNode, env, options) {
let { tagName,
params,
attrs,
parentView,
parentScope,
Expand Down Expand Up @@ -89,6 +90,13 @@ ComponentNodeManager.create = function(renderNode, env, options) {
}

renderNode.emberView = component;

if (component.positionalParams) {
let pp = component.positionalParams;
for (let i=0; i<pp.length; i++) {
attrs[pp[i]] = params[i];
}
}
}

var results = buildComponentTemplate({ layout: layout, component: component }, attrs, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,43 @@ if (Ember.FEATURES.isEnabled('ember-views-component-block-info')) {
equal(jQuery('#qunit-fixture').text(), 'In block No Block Param!');
});
}

QUnit.test('static positional parameters', function() {
registry.register('template:components/sample-component', compile('{{attrs.name}}{{attrs.age}}'));
registry.register('component:sample-component', Component.extend({
positionalParams: ['name', 'age']
}));

view = EmberView.extend({
layout: compile('{{sample-component "Quint" 4}}'),
container: container
}).create();

runAppend(view);

equal(jQuery('#qunit-fixture').text(), 'Quint4');
});

QUnit.test('dynamic positional parameters', function() {
registry.register('template:components/sample-component', compile('{{attrs.name}}{{attrs.age}}'));
registry.register('component:sample-component', Component.extend({
positionalParams: ['name', 'age']
}));

view = EmberView.extend({
layout: compile('{{sample-component myName myAge}}'),
container: container,
context: {
myName: 'Quint',
myAge: 4
}
}).create();

runAppend(view);
equal(jQuery('#qunit-fixture').text(), 'Quint4');
run(function() {
Ember.set(view.context, 'myName', 'Edward');
Ember.set(view.context, 'myAe', '5');
});

});
2 changes: 1 addition & 1 deletion packages/ember-routing-htmlbars/lib/keywords/link-to.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ export default {

attrs.escaped = !morph.parseTextAsHTML;

env.hooks.component(morph, env, scope, '-link-to', attrs, template, visitor);
env.hooks.component(morph, env, scope, '-link-to', params, attrs, template, visitor);
},

rerender(morph, env, scope, params, hash, template, inverse, visitor) {
Expand Down