Skip to content

Splat operator #1050

@mixonic

Description

@mixonic

I've been fielding several requests for a splat operator in Ember templates. Specifically, when using Ember components. For example given:

{{! presuming myHash === { keyA: 'val', keyB: context.someProp } }}
{{my-component *myHash}}

It would de-sugar to:

{{my-component keyA="val" keyB=someProp}}

This proposal is limited in scope.

  • It does not propose a way to de-sugar params from an array, only properties from an object into the hash. I find it useful to consider the params case in designing this API though, presuming that it would use the same syntax but simply vary behavior at runtime based on the contents of the splatted variable.
  • I propose that only a single splat be allowed.

Grammer proposal

OPEN helperName param* hashSplat? hash? CLOSE

Visually, it makes sense to put the splat before any hash arguments. This would aid in the understanding that hash arguments should take precedence. For example given:

{{! presuming myHash === { keyA: 'val', keyB: context.someProp } }}
{{my-component someParam *myHash keyB="I take the crown!"}}

The hash would be { keyA: 'val', keyB: 'I take the crown!' }. This is actually runtime behavior, and could vary according to implementation, but seems a good justification for the above ordering.

It is also suggested that subexpressions would also accept a splat. For example:

{{my-component someParam=(translate *translateOptions)}}

Alternatives

It has been suggested by @wycats that we consider ...myHash, as it aligns more closely with JavaScript splatting. This seems reasonable, I'd like some more thoughts.

/cc @kpdecker @mmun @krisselden @wycats @chrislopresto

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions