Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Contextual Components

Contextual Components

Contextual components presentation from Boston Ember.js.

Video at https://youtu.be/Au3rHHuEZNI?t=1h6m42s

Eric Kelly

June 09, 2016
Tweet

More Decks by Eric Kelly

Other Decks in Programming

Transcript

  1. Important Stuff • {{yield}} • Using component block parameters •

    {{hash}} helper • {{component}} helper • closure actions & dot syntax
  2. Yielding Values let post = { title: 'Contextual Components', body:

    'Sometimes you want contextual components.', author: 'Tim' } {!-- app/templates/components/blog-post.hbs}} <div class="blog-post"> {{yield post.title post.body post.author}} </div> {{#blog-post post=post as |title body author|}} <h2>{{title}}</h2> <p class="blog-post__author">by {{author}}</p> <p class="blog-post__body">{{body}}</p> {{/blog-post}}
  3. Blog Post Preview // app/components/blog-post.js export default Ember.Component.extend({ preview: Ember.computed('post.body',

    function() { return this.get('post.body').substring(0, 18); }) }); {!-- app/templates/components/blog-post.hbs}} <div class="blog-post"> {{yield post.title post.body post.author preview}} </div> {{#blog-post post=post as |title body author preview|}} <h2>{{title}}</h2> <p class="blog-post__author">by {{author}}</p> <p class=“blog-post__preview”>{{preview}}…</p> {{/blog-post}}
  4. {{hash}} Helper {{#blog-post post=(hash title="Some Title" body="Post body" author="Eric") as

    |title body author| }} <h2>{{title}}</h2> <p class="blog-post__author">by {{author}}</p> <p class="blog-post__body">{{body}}</p> {{/blog-post}}
  5. {{hash}} Helper {{! app/templates/components/blog-post.hbs}} <div class="blog-post"> {{yield (hash title=post.title body=

    post.body author=post.author preview=preview ) }} </div> {{#blog-post post=post as |p|}} <h2>{{p.title}}</h2> <p class="blog-post__author">by {{p.author}}</p> <p class="blog-post__preview">{{p.preview}}...</p> {{/blog-post}}