Thanks Alex, this looks sweet!!
So, let’s say I have a setup like this:
<!doctype html>
<html>
<body>
<script type="text/x-handlebars" data-template-name="components/ember-accordion">
{{#each listOfAccordionPaneObjects}}
{{yield}}
{{/each}}
</script>
<script type="text/x-handlebars" data-template-name="components/ember-accordion-header">
{{yield}}
</script>
<script type="text/x-handlebars" data-template-name="index">
from outside the component: {{test}}
{{#ember-accordion |model, test|}}
<!-- question 1 --> {{model.firstName}}<br />
<!-- question 2 --> {{test}}
{{#ember-accordion-header |model, test|}}
<!-- question 3 --> {{model.firstName}}<br />
<!-- question 4 --> {{test}}
{{#ember-accordion-dismiss-button}}
<!-- question 5 --> {{model.firstName}}<br />
<!-- question 6 --> {{test}}
{{/ember-accordion-dismiss-button}}
{{/ember-accordion-header}}
{{/ember-accordion}}
</script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.2.1/handlebars.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/ember.js/1.2.0/ember.debug.js"></script>
<script>
var Person = Ember.Object.extend({
firstName: '',
lastName: ''
}),
App = Ember.Application.create(),
people = [],
i = 0;
App.EmberAccordionComponent = Ember.Component.extend();
App.EmberAccordionHeaderComponent = Ember.Component.extend();
for(i; i < 10; i++) {
people.push(Person.create({
firstName: 'first ' + i.toString(),
lastName: 'last ' + i.toString()
}));
}
App.IndexRoute = Ember.Route.extend({
model: function() {
return people;
}
});
App.IndexController = Ember.Controller.extend({
init: function() {
this._super();
this.set('test', 'TEST WORKED!');
}
});
</script>
</body>
</html>
Would these be the values output?
question 1: 'first n'
question 2: 'TEST WORKED!'
question 3: 'first n'
question 4: 'TEST WORKED!'
question 5: ''
question 6: ''
If so, I think this is an extremely elegant solution to the problem and should cover pretty much any use case around scope and nested components, from the handlebars perspective.
The second other part that would be really useful is being able to access these values from the component objects themselves, ie:
App.EmberAccordionComponent.model === [{ firstName: 'first 1', lastName: 'last 1' } ... ]
App.EmberAccordionComponent.test === 'TEST WORKED!'
I haven’t looked at the code in ember that glues the templates to the component javascript classes, so I’m not sure how something like that would work at all.
And lastly, if the block scope was in effect as in the above, and I set:
App.EmberAccordionHeaderComponent.expanded === true
I could then read it from:
App.EmberAccordionComponent.expanded and it would === true there too.
Thanks again Alex, this is really looking fantastic.