Skip to content

Commit

Permalink
[DOC canary] Documents positional parameters in components.
Browse files Browse the repository at this point in the history
(cherry picked from commit b953d30)
  • Loading branch information
mollerhoj authored and rwjblue committed Aug 24, 2015
1 parent c13b7dd commit 3fc451b
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions packages/ember-views/lib/views/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,58 @@ var Component = View.extend(TargetActionSupport, {
@property hasBlockParams
@returns Boolean
*/

/**
Enables components to take a list of parameters as arguments
For example a component that takes two parameters with the names
`name` and `age`:
```javascript
let MyComponent = Ember.Component.extend;
MyComponent.reopenClass({
positionalParams: ['name', 'age']
});
```
It can then be invoked like this:
```hbs
{{my-component "John" 38}}
```
The parameters can be refered to just like named parameters:
```hbs
Name: {{attrs.name}}, Age: {{attrs.age}}.
```
Using a string instead of an array allows for an arbitrary number of
parameters:
```javascript
let MyComponent = Ember.Component.extend;
MyComponent.reopenClass({
positionalParams: 'names'
});
```
It can then be invoked like this:
```hbs
{{my-component "John" "Michael" "Scott"}}
```
The parameters can then be refered to by enumerating over the list:
```hbs
{{#each attrs.names as |name|}}{{name}}{{/each}}
```
@static
@public
@property positionalParams
*/
});

Component.reopenClass({
Expand Down

0 comments on commit 3fc451b

Please sign in to comment.