Skip to content

Instantly share code, notes, and snippets.

@stefanpenner
Last active August 29, 2015 14:17
Show Gist options
  • Save stefanpenner/86812ac262414232285c to your computer and use it in GitHub Desktop.
Save stefanpenner/86812ac262414232285c to your computer and use it in GitHub Desktop.
<my-form as |input button|>
{{! input and button isn't the whole component, rather a special object the represents only the yielded !}}
<input.text> Hello World</text.input>
<button.save>Save me!</save.button>
</my-form>
<h1> OMG, Hello world!!! </h1>
{{yield formInputs buttons}}
// This is not complete, its kinda shitty.
export default Component.extend({
// ability to inject a factory on an instance
MyLocalComponent: Ember.injectFactory('component:my-local-input'),
MyButton: Ember.injectFactory('component:my-button-input'),
inputs() {
// createWith is a way to curry attributes for later creation.
// this allows us to defer creation until the view layer actually needs to,
// and has all information
return {
input: this.MyLocalComponent.createWith({
form: this,
})
};
},
buttons() {
return {
save: this.MyButton.createWith({ form: this })
};
}
});
@thoov
Copy link

thoov commented Mar 13, 2015

Just thinking out loud:

<table as |t|>
  {{#each header in headers}}
    <t.header name=header.name>    
      {{#each column in columns}}
         <t.column>{{column.name}}</t.column> 
      {{/each}}
    </t.header>
  {{/each}}
</table>

@ming-codes
Copy link

Here's some ideas on using this with charting:

<bar-chart as |bars, x-axis, y-axis, legend|>
  {{#each series as |data|}}
    <bars data />
  {{/each}}

  <x-axis>
    <text>{{tick}}</text>
    <line x1="" y1="" x2="" y2=""></line>
  </x-axis>

  <y-axis>
    <text>{{tick}}</text>
    <line x1="" y1="" x2="" y2=""></line>
  </y-axis>

  <g transform="translate(100, 100)">
    {{#each series as |data|}}
      <legend data />
    {{/each}}
  </g>
</bar-chart>

The problem with as |bars, x-axis, y-axis, legend| is that they're order dependent. If destructuring is available, that would solve this problem (among many others 😄 ).

@stefanpenner
Copy link
Author

@Lightblade's example, but with destructuring (and a component.js). Although destructuring is another concept and syntax, it does enable us to mitigate the position based refactoring hazard of the |. It does though, increase the scope and complexity. As with destructuring you almost certainly need renaming as { foo as bar }.

bar-chart.hbs

{{yield chartHelpers}}

bar-chart.js

export default Ember.Component.extend({
  chartHelpers() {
    return {
      bars: this.Bars.createWith({ chart: this }),
      'x-axis': this.XAxis.createWith({ chart: this }),
      'y-axis': this.YAxis.createWith({ chart: this }),
      legend: this.Legend.createWith({ chart: this })
    }
  }
});
<bar-chart as { bars, x-axis, y-axis, legend } >
  {{#each series as |data|}}
    <bars data />
  {{/each}}

  <x-axis>
    <text>{{tick}}</text>
    <line x1="" y1="" x2="" y2=""></line>
  </x-axis>

  <y-axis>
    <text>{{tick}}</text>
    <line x1="" y1="" x2="" y2=""></line>
  </y-axis>

  <g transform="translate(100, 100)">
    {{#each series as |data|}}
      <legend data />
    {{/each}}
  </g>
</bar-chart>

@tikotzky
Copy link

tikotzky commented Apr 2, 2015

@stefanpenner is <bar-chart as { bars, x-axis, y-axis, legend } > style destructing valid syntax today?

@stefanpenner
Copy link
Author

<bar-chart as |graph| >
  {{#each series as |data|}}
    <graph.bars data />
  {{/each}}

  <graph.x-axis>
    <text>{{tick}}</text>
    <line x1="" y1="" x2="" y2=""></line>
  </graph.x-axis>

  <graph.y-axis>
    <text>{{tick}}</text>
    <line x1="" y1="" x2="" y2=""></line>
  </graph.y-axis>

  <g transform="translate(100, 100)">
    {{#each series as |data|}}
      <graph.legend data />
    {{/each}}
  </g>
</bar-chart>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment