-
-
Save stefanpenner/86812ac262414232285c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 }) | |
}; | |
} | |
}); |
Here's some ideas on using this with charting:
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 😄 ).
@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
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 })
}
}
});
@stefanpenner is <bar-chart as { bars, x-axis, y-axis, legend } >
style destructing valid syntax today?
<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
Just thinking out loud: