Component Development
Join the new EmberJS group
I'm sharing the "ideal" way to do this
Ember gives you freedom to break from this
Good thing/Bad thing (react)
Pragmatism on Legacy Code
That said when you can, start with good practices
Provide Isolation
Reuse
Simplify Markup
Testable
Single Responsibility Principle
even if you don't forsee it
keep data up high
Ember is optimized for fast rendering when data changes
Use computed properties to massage data for display
Use lifecycle rules to take actions based on bound attribute updates
They are essentailly callbacks
Data Down Actions Down?
Return promises to handle async results
The action helper provides rich features
calls sendMessage on the component's action hash
{{action "sendMessage" myMessage}}
calls sendMessage passed in through attrs
{{action sendMessage myMessage}}
Action arguments don't need to be provided at bottom. You can tag on args as you pass the action down
Parent-Component
{{child-component sendMessage=(action sendMessage "info")}}
Parent Component
//sendMessage("info", "hello!") called on parent
this.get('sendMessage')("hello!");
a child component may not know what the parent wants.
The action helper can take what it needs from an argument.
<input value={{currentValue}}
oninput={{action (mut currentValue) value="target.value"}}>
a component can yield data through its template.
{{title}}
{{yield (hash body=(component editStyle postData=postData) author=author submit=submit)}}
yielded data is used within the scope of the block
{{#blog-post editStyle="markdown" as |post|}}
<p class="author">by {{post.author}}</p>
{{post.body editStyle="compact"}}
<button {{action post.submit}}>Submit</button>
{{/blog-post}}