SlideShare a Scribd company logo
1 of 51
Download to read offline
New Component
Patterns in Ember 1.10+
or, You Really Can Take it With You
I’m Matthew
@mixonic - madhatted.com
201 Created
Ember.js experts and JavaScript superheroes in NYC
Out with the old,

in with the new.
1 // app/index/controller.js
2 import Ember from "ember";
3
4 export Ember.Controller.extend({
5 session: Ember.inject.service();
6 });
1 // app/services/session.js
2 import Ember from "ember";
3
4 export Ember.Object.extend({
5 isAuthenticated: false,
6 login: function() {
7 // ...
8 }
9 });
Services in 1.10!
HTMLBars dep! debug file!
1 <script src="/jquery.js"></script>
2 <script src="/handlebars-v2.0.0.js"></script>
3 <script src=“/1.9.1/ember.js”></script>
1 <script src="/jquery.js"></script>
2 <script src=“/1.10.0/ember-template-compiler.js”></script>
3 <script src=“/1.10.0/ember.debug.js”></script>
1.9
1.10
HTMLBars!
Love me!
New APIs mean new
development patterns.
Out with the scopes,

in with the variables.
I
Context switching deprecated in 1.9
1 {{! this context is the controller }}
2 {{#each model}}
3 {{name}} {{! this context is each person }}
4 {{/each}}
1 {{! this context is the controller }}
2 {{#each person in model}}
3 {{person.name}} {{! this context is still the controller }}
4 {{/each}}
http://emberjs.com/blog/2014/12/08/ember-1-9-0-released.html
Context switching deprecated in 1.9
http://emberjs.com/blog/2014/12/08/ember-1-9-0-released.html
1 {{#if config.pro}}
2 <div class="travis-lint">
3 <p>Travis Lint for clean .yml files
4 <a {{bind-attr href="lintUrl"}}>lint.travis-ci.org/{{repo.slug}}</a>
5 </p>
6 </div>
7 {{/if}}
8
9 <table id="requests" class="list">
10 <thead>
11 <tr>
12 <th>Request</th>
13 <th>Commit</th>
14 <th>Build</th>
15 <th>Commit message</th>
16 <th>Type</th>
17 <th>Message</th>
18 </tr>
19 </thead>
20
21 <tbody>
22 {{#each controller itemController="request"}}
23 <tr {{bind-attr class="requestClass"}}>
24 <td class="request-id">
25 <span class="status"></span>
26 {{id}}
27 </td>
28 <td>{{githubCommitLink repo.slug commit.sha}}</td>
29 <td>
30 {{#if build}}
31 {{#link-to "build" build}}#{{build.number}}{{/link-to}}
32 {{else}}
33 -
34 {{/if}}
35 </td>
36 <td class="commit-message">{{{formatMessage commit.message short="true" repoBinding=build.repo}}}</td>
37 <td>{{type}}</td>
38 <td>{{message}}</td>
39 </tr>
40 {{/each}}
41 </tbody>
42 </table>
Context switching deprecated in 1.9
http://emberjs.com/blog/2014/12/08/ember-1-9-0-released.html
1 {{#if config.pro}}
2 <div class="travis-lint">
3 <p>Travis Lint for clean .yml files
4 <a {{bind-attr href="lintUrl"}}>lint.travis-ci.org/{{repo.slug}}</a>
5 </p>
6 </div>
7 {{/if}}
8
9 <table id="requests" class="list">
10 <thead>
11 <tr>
12 <th>Request</th>
13 <th>Commit</th>
14 <th>Build</th>
15 <th>Commit message</th>
16 <th>Type</th>
17 <th>Message</th>
18 </tr>
19 </thead>
20
21 <tbody>
22 {{#each controller itemController="request"}}
23 <tr {{bind-attr class="requestClass"}}>
24 <td class="request-id">
25 <span class="status"></span>
26 {{id}}
27 </td>
28 <td>{{githubCommitLink repo.slug commit.sha}}</td>
29 <td>
30 {{#if build}}
31 {{#link-to "build" build}}#{{build.number}}{{/link-to}}
32 {{else}}
33 -
34 {{/if}}
35 </td>
36 <td class="commit-message">{{{formatMessage commit.message short="true" repoBinding=build.repo}}}</td>
37 <td>{{type}}</td>
38 <td>{{message}}</td>
39 </tr>
40 {{/each}}
41 </tbody>
42 </table>
New scope
1 <ul id="queues">
2 <li class="queue">
3 <h4>Queue ({{controller.length}})</h4>
4 <ul>
5 {{#if controller.length}}
6 {{#each job in controller}}
7 {{#view Travis.QueueItemView jobBinding="job"}}
8 {{#if job.repo.slug}}
9 {{#link-to "job" job.repo job}}
10 <span class="slug" {{bind-attr title="job.slug"}}>
11 {{job.repo.slug}}
12 </span>
13 #{{job.number}}
14 {{/link-to}}
15 {{/if}}
16 {{/view}}
17 {{/each}}
18 {{else}}
19 There are no jobs
20 {{/if}}
21 </ul>
22 </li>
23 </ul>
Context switching deprecated in 1.9
http://emberjs.com/blog/2014/12/08/ember-1-9-0-released.html
Possible new scope?!
Passing variables is easier
to reason about than
changing scope.
Ember 1.10 introduces
“block params”
1 {{! this context is the controller }}
2 {{#each person in model}}
3 {{person.name}} {{! this context is still the controller }}
4 {{/each}}
Block params introduced in 1.10
http://emberjs.com/blog/2014/12/08/ember-1-9-0-released.html
1 {{! this context is the controller }}
2 {{#each model as |person|}}
3 {{person.name}} {{! this context is still the controller }}
4 {{/each}}
http://emberjs.com/blog/2014/12/08/ember-1-9-0-released.html
1 {{#x-menu}}
2 {{x-item selected=selected item=item}}
3 {{/x-menu}}
Block params introduced in 1.10
1 <div class="x-menu">
2 {{yield}}
3 </div>
http://emberjs.com/blog/2014/12/08/ember-1-9-0-released.html
1 {{#x-menu as |selected|}}
2 {{x-item selected=selected item=item}}
3 {{/x-menu}}
Block params introduced in 1.10
1 <div class="x-menu">
2 {{yield selected}}
3 </div>
http://emberjs.com/blog/2014/12/08/ember-1-9-0-released.html
1 {{#x-menu as |selected item|}}
2 {{x-item selected=selected item=item}}
3 {{/x-menu}}
Block params introduced in 1.10
1 <div class="x-menu">
2 {{yield selected item}}
3 </div>
1 <div class="x-menu">
2 {{#each items as |item|}}
3 {{yield selected item}}
4 {{/each}}
5 </div>
http://emberjs.com/blog/2014/12/08/ember-1-9-0-released.html
1 {{#x-menu as |selected item|}}
2 {{x-item selected=selected item=item}}
3 {{/x-menu}}
Block params introduced in 1.10
Out with the controllers,

in with the components.
II
Out with the views,

in with the components.
II
Controllers Views
Receive actions Handle events
Provide template scope Describe elements
1 export default Ember.Component.extend({
2 actions: {
3 save: function(model){
4 model.save();
5 }
6 }
7 });
1 <button {{action "save" model}}>Save</button>
Controllers Views
Receive actions Handle events
Provide template scope Describe elements
1 export default Ember.Component.extend({
2 color: 'red'
3 });
1 <div>{{color}}</div>
Controllers Views
Receive actions Handle events
Provide template scope Describe elements
1 export default Ember.Component.extend({
2 click: function(){
3 this.sendAction('save');
4 }
5 });
Controllers Views
Receive actions Handle events
Provide template scope Describe elements
1 export default Ember.Component.extend({
2 tagName: 'li',
3 classNames: ['red']
4 });
Controllers deprecated when 2.0 comes out
“Many people have noticed that
controllers in Ember look a lot like
components, but with an arbitrary division
of responsibilities. We agree!”
- Tomkatz, 2.0 RFC
https://github.com/emberjs/rfcs/pull/15
For new users, a single
concept is easier to learn.
“But I need mega-hackz!”
III
I CAN HAZ
MEGA

HACKZ
Components don’t yet
handle every use-case
We’re working on it!
Here are some ideas
Not finished, polished, or maybe even ever going to happen.
On Ember components that use the new tag
syntax, data-binding will be one-way. The mut
helper will wrap values that the receiver can
modify.
<x-input value={{mut name}}></x-input>
1 export default Ember.Component.extend({!
2 tagName: 'input',!
3 change: function(){!
4 this.attrs.name.set(this.$().val());!
5 }!
6 });!
bind-action, or maybe action, will wrap the
action it references in a closure, and pass it as
a function. You can call it directly.
{{x-input model=model submit=(bind-action "save")}}
1 export default Ember.Component.extend({
2 change: function(){
3 this.attrs.submit(model);
4 }
5 });
ref would allow you to point an action at a
specific component in your current template.
1 {{video-player ref="vp"}}
2
3 <button on-click={{ref 'vp' 'play'}}>
set would allow you to easily map an
event to a value setter.
<x-input on-change={{set model.name}}></x-input>
scoped helpers allow a component to yield
references to components or helpers.
1 // app/components/form-for.js
2
3 import Ember from "ember";
4 import FormForInput from "./helpers/input";
5
6 var makeViewHelper = Ember.HTMLBars.makeViewHelper;
7
8 export default Ember.Component.extend({
9 formHelpers: {
10 input: makeViewHelper(FormForInput)
11 }
12 });
1 {{! app/templates/components/form-for.hbs }}
2
3 {{yield formHelpers}}
1 {{! app/templates/post/new.hbs }}
2
3 {{#form-for as |f|}}
4 {{f.input label="Title" value=model.title}}
5 {{/form-for}}
Let’s cowboy code
some prototypes
bit.ly/cowboy-code
BEWARE
An experiment with
mut and bind-action
bit.ly/cowboy-1
Using today’s tools
bit.ly/cowboy-2 block params
bit.ly/cowboy-3 bind-action
bit.ly/cowboy-4 more bind-action
bit.ly/cowboy-5 pass bind-action as block param
bit.ly/cowboy-6 yield with each
bit.ly/cowboy-7 mut
Start using block params
today, and you will quickly
want some of these tools.
Don’t let it stop you!
Thanks!
Questions?

More Related Content

What's hot

Workshop 3: JavaScript build tools
Workshop 3: JavaScript build toolsWorkshop 3: JavaScript build tools
Workshop 3: JavaScript build toolsVisual Engineering
 
Developing Modern Java Web Applications with Java EE 7 and AngularJS
Developing Modern Java Web Applications with Java EE 7 and AngularJSDeveloping Modern Java Web Applications with Java EE 7 and AngularJS
Developing Modern Java Web Applications with Java EE 7 and AngularJSShekhar Gulati
 
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...Katy Slemon
 
The road to Ember.js 2.0
The road to Ember.js 2.0The road to Ember.js 2.0
The road to Ember.js 2.0Codemotion
 
ASP.NET Routing & MVC
ASP.NET Routing & MVCASP.NET Routing & MVC
ASP.NET Routing & MVCEmad Alashi
 
The Complementarity of React and Web Components
The Complementarity of React and Web ComponentsThe Complementarity of React and Web Components
The Complementarity of React and Web ComponentsAndrew Rota
 
Reactive Thinking in Java with RxJava2
Reactive Thinking in Java with RxJava2Reactive Thinking in Java with RxJava2
Reactive Thinking in Java with RxJava2Yakov Fain
 
Spring Boot & WebSocket
Spring Boot & WebSocketSpring Boot & WebSocket
Spring Boot & WebSocketMing-Ying Wu
 
AngularJS Unit Test
AngularJS Unit TestAngularJS Unit Test
AngularJS Unit TestChiew Carol
 
Workshop 27: Isomorphic web apps with ReactJS
Workshop 27: Isomorphic web apps with ReactJSWorkshop 27: Isomorphic web apps with ReactJS
Workshop 27: Isomorphic web apps with ReactJSVisual Engineering
 
Workshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte IIWorkshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte IIVisual Engineering
 
Flutter State Management Using GetX.pdf
Flutter State Management Using GetX.pdfFlutter State Management Using GetX.pdf
Flutter State Management Using GetX.pdfKaty Slemon
 
Workshop 14: AngularJS Parte III
Workshop 14: AngularJS Parte IIIWorkshop 14: AngularJS Parte III
Workshop 14: AngularJS Parte IIIVisual Engineering
 
Web sockets in Angular
Web sockets in AngularWeb sockets in Angular
Web sockets in AngularYakov Fain
 
Life in a Queue - Using Message Queue with django
Life in a Queue - Using Message Queue with djangoLife in a Queue - Using Message Queue with django
Life in a Queue - Using Message Queue with djangoTareque Hossain
 
How to Build ToDo App with Vue 3 + TypeScript
How to Build ToDo App with Vue 3 + TypeScriptHow to Build ToDo App with Vue 3 + TypeScript
How to Build ToDo App with Vue 3 + TypeScriptKaty Slemon
 
Single Page Applications with AngularJS 2.0
Single Page Applications with AngularJS 2.0 Single Page Applications with AngularJS 2.0
Single Page Applications with AngularJS 2.0 Sumanth Chinthagunta
 
Grand Rapids PHP Meetup: Behavioral Driven Development with Behat
Grand Rapids PHP Meetup: Behavioral Driven Development with BehatGrand Rapids PHP Meetup: Behavioral Driven Development with Behat
Grand Rapids PHP Meetup: Behavioral Driven Development with BehatRyan Weaver
 

What's hot (20)

Workshop 3: JavaScript build tools
Workshop 3: JavaScript build toolsWorkshop 3: JavaScript build tools
Workshop 3: JavaScript build tools
 
Developing Modern Java Web Applications with Java EE 7 and AngularJS
Developing Modern Java Web Applications with Java EE 7 and AngularJSDeveloping Modern Java Web Applications with Java EE 7 and AngularJS
Developing Modern Java Web Applications with Java EE 7 and AngularJS
 
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
 
The road to Ember.js 2.0
The road to Ember.js 2.0The road to Ember.js 2.0
The road to Ember.js 2.0
 
ASP.NET Routing & MVC
ASP.NET Routing & MVCASP.NET Routing & MVC
ASP.NET Routing & MVC
 
The Complementarity of React and Web Components
The Complementarity of React and Web ComponentsThe Complementarity of React and Web Components
The Complementarity of React and Web Components
 
Reactive Thinking in Java with RxJava2
Reactive Thinking in Java with RxJava2Reactive Thinking in Java with RxJava2
Reactive Thinking in Java with RxJava2
 
Spring Boot & WebSocket
Spring Boot & WebSocketSpring Boot & WebSocket
Spring Boot & WebSocket
 
AngularJS Unit Test
AngularJS Unit TestAngularJS Unit Test
AngularJS Unit Test
 
Workshop 27: Isomorphic web apps with ReactJS
Workshop 27: Isomorphic web apps with ReactJSWorkshop 27: Isomorphic web apps with ReactJS
Workshop 27: Isomorphic web apps with ReactJS
 
Workshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte IIWorkshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte II
 
Flutter State Management Using GetX.pdf
Flutter State Management Using GetX.pdfFlutter State Management Using GetX.pdf
Flutter State Management Using GetX.pdf
 
Workshop 14: AngularJS Parte III
Workshop 14: AngularJS Parte IIIWorkshop 14: AngularJS Parte III
Workshop 14: AngularJS Parte III
 
Web sockets in Angular
Web sockets in AngularWeb sockets in Angular
Web sockets in Angular
 
Life in a Queue - Using Message Queue with django
Life in a Queue - Using Message Queue with djangoLife in a Queue - Using Message Queue with django
Life in a Queue - Using Message Queue with django
 
React
React React
React
 
Angularjs
AngularjsAngularjs
Angularjs
 
How to Build ToDo App with Vue 3 + TypeScript
How to Build ToDo App with Vue 3 + TypeScriptHow to Build ToDo App with Vue 3 + TypeScript
How to Build ToDo App with Vue 3 + TypeScript
 
Single Page Applications with AngularJS 2.0
Single Page Applications with AngularJS 2.0 Single Page Applications with AngularJS 2.0
Single Page Applications with AngularJS 2.0
 
Grand Rapids PHP Meetup: Behavioral Driven Development with Behat
Grand Rapids PHP Meetup: Behavioral Driven Development with BehatGrand Rapids PHP Meetup: Behavioral Driven Development with Behat
Grand Rapids PHP Meetup: Behavioral Driven Development with Behat
 

Similar to New Component Patterns in Ember.js

Fun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksFun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksMongoDB
 
Analysis of bugs in Orchard CMS
Analysis of bugs in Orchard CMSAnalysis of bugs in Orchard CMS
Analysis of bugs in Orchard CMSPVS-Studio
 
Intro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran MizrahiIntro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran MizrahiRan Mizrahi
 
Interoperable Component Patterns
Interoperable Component PatternsInteroperable Component Patterns
Interoperable Component PatternsMatthew Beale
 
using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'sAntônio Roberto Silva
 
PVS-Studio vs Chromium. 3-rd Check
PVS-Studio vs Chromium. 3-rd CheckPVS-Studio vs Chromium. 3-rd Check
PVS-Studio vs Chromium. 3-rd CheckAndrey Karpov
 
WINDOWS ADMINISTRATION AND WORKING WITH OBJECTS : PowerShell ISE
WINDOWS ADMINISTRATION AND WORKING WITH OBJECTS : PowerShell ISEWINDOWS ADMINISTRATION AND WORKING WITH OBJECTS : PowerShell ISE
WINDOWS ADMINISTRATION AND WORKING WITH OBJECTS : PowerShell ISEHitesh Mohapatra
 
RESTful API In Node Js using Express
RESTful API In Node Js using Express RESTful API In Node Js using Express
RESTful API In Node Js using Express Jeetendra singh
 
Divide and Conquer – Microservices with Node.js
Divide and Conquer – Microservices with Node.jsDivide and Conquer – Microservices with Node.js
Divide and Conquer – Microservices with Node.jsSebastian Springer
 
Meteor.js Workshop by Dopravo
Meteor.js Workshop by DopravoMeteor.js Workshop by Dopravo
Meteor.js Workshop by DopravoArabNet ME
 
An intro to Docker, Terraform, and Amazon ECS
An intro to Docker, Terraform, and Amazon ECSAn intro to Docker, Terraform, and Amazon ECS
An intro to Docker, Terraform, and Amazon ECSYevgeniy Brikman
 

Similar to New Component Patterns in Ember.js (20)

Fun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksFun Teaching MongoDB New Tricks
Fun Teaching MongoDB New Tricks
 
Analysis of bugs in Orchard CMS
Analysis of bugs in Orchard CMSAnalysis of bugs in Orchard CMS
Analysis of bugs in Orchard CMS
 
Intro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran MizrahiIntro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran Mizrahi
 
Angular 2.0 - What to expect
Angular 2.0 - What to expectAngular 2.0 - What to expect
Angular 2.0 - What to expect
 
Interoperable Component Patterns
Interoperable Component PatternsInteroperable Component Patterns
Interoperable Component Patterns
 
using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API's
 
PVS-Studio vs Chromium. 3-rd Check
PVS-Studio vs Chromium. 3-rd CheckPVS-Studio vs Chromium. 3-rd Check
PVS-Studio vs Chromium. 3-rd Check
 
Intro to Rails 4
Intro to Rails 4Intro to Rails 4
Intro to Rails 4
 
WINDOWS ADMINISTRATION AND WORKING WITH OBJECTS : PowerShell ISE
WINDOWS ADMINISTRATION AND WORKING WITH OBJECTS : PowerShell ISEWINDOWS ADMINISTRATION AND WORKING WITH OBJECTS : PowerShell ISE
WINDOWS ADMINISTRATION AND WORKING WITH OBJECTS : PowerShell ISE
 
RESTful API In Node Js using Express
RESTful API In Node Js using Express RESTful API In Node Js using Express
RESTful API In Node Js using Express
 
ajax_pdf
ajax_pdfajax_pdf
ajax_pdf
 
ajax_pdf
ajax_pdfajax_pdf
ajax_pdf
 
React js
React jsReact js
React js
 
Play!ng with scala
Play!ng with scalaPlay!ng with scala
Play!ng with scala
 
Divide and Conquer – Microservices with Node.js
Divide and Conquer – Microservices with Node.jsDivide and Conquer – Microservices with Node.js
Divide and Conquer – Microservices with Node.js
 
Library Project
Library ProjectLibrary Project
Library Project
 
Celery
CeleryCelery
Celery
 
Meteor.js Workshop by Dopravo
Meteor.js Workshop by DopravoMeteor.js Workshop by Dopravo
Meteor.js Workshop by Dopravo
 
An intro to Docker, Terraform, and Amazon ECS
An intro to Docker, Terraform, and Amazon ECSAn intro to Docker, Terraform, and Amazon ECS
An intro to Docker, Terraform, and Amazon ECS
 
AD102 - Break out of the Box
AD102 - Break out of the BoxAD102 - Break out of the Box
AD102 - Break out of the Box
 

More from Matthew Beale

Ember.js Module Loading
Ember.js Module LoadingEmber.js Module Loading
Ember.js Module LoadingMatthew Beale
 
LA Ember.js Meetup, Jan 2017
LA Ember.js Meetup, Jan 2017LA Ember.js Meetup, Jan 2017
LA Ember.js Meetup, Jan 2017Matthew Beale
 
Ember Community 2016 - Be the Bark
Ember Community 2016 - Be the BarkEmber Community 2016 - Be the Bark
Ember Community 2016 - Be the BarkMatthew Beale
 
The Hidden Power of HTMLBars (or, Scope in Ember.js Templates)
The Hidden Power of HTMLBars (or, Scope in Ember.js Templates)The Hidden Power of HTMLBars (or, Scope in Ember.js Templates)
The Hidden Power of HTMLBars (or, Scope in Ember.js Templates)Matthew Beale
 
Aligning Ember.js with Web Standards
Aligning Ember.js with Web StandardsAligning Ember.js with Web Standards
Aligning Ember.js with Web StandardsMatthew Beale
 
Scalable vector ember
Scalable vector emberScalable vector ember
Scalable vector emberMatthew Beale
 
Testing Ember Apps: Managing Dependency
Testing Ember Apps: Managing DependencyTesting Ember Apps: Managing Dependency
Testing Ember Apps: Managing DependencyMatthew Beale
 
Parse Apps with Ember.js
Parse Apps with Ember.jsParse Apps with Ember.js
Parse Apps with Ember.jsMatthew Beale
 
Snappy Means Happy: Performance in Ember Apps
Snappy Means Happy: Performance in Ember AppsSnappy Means Happy: Performance in Ember Apps
Snappy Means Happy: Performance in Ember AppsMatthew Beale
 
Client-side Auth with Ember.js
Client-side Auth with Ember.jsClient-side Auth with Ember.js
Client-side Auth with Ember.jsMatthew Beale
 
Containers & Dependency in Ember.js
Containers & Dependency in Ember.jsContainers & Dependency in Ember.js
Containers & Dependency in Ember.jsMatthew Beale
 
Complex Architectures in Ember
Complex Architectures in EmberComplex Architectures in Ember
Complex Architectures in EmberMatthew Beale
 
Ember and containers
Ember and containersEmber and containers
Ember and containersMatthew Beale
 

More from Matthew Beale (14)

Ember.js Module Loading
Ember.js Module LoadingEmber.js Module Loading
Ember.js Module Loading
 
LA Ember.js Meetup, Jan 2017
LA Ember.js Meetup, Jan 2017LA Ember.js Meetup, Jan 2017
LA Ember.js Meetup, Jan 2017
 
Ember Community 2016 - Be the Bark
Ember Community 2016 - Be the BarkEmber Community 2016 - Be the Bark
Ember Community 2016 - Be the Bark
 
Attribute actions
Attribute actionsAttribute actions
Attribute actions
 
The Hidden Power of HTMLBars (or, Scope in Ember.js Templates)
The Hidden Power of HTMLBars (or, Scope in Ember.js Templates)The Hidden Power of HTMLBars (or, Scope in Ember.js Templates)
The Hidden Power of HTMLBars (or, Scope in Ember.js Templates)
 
Aligning Ember.js with Web Standards
Aligning Ember.js with Web StandardsAligning Ember.js with Web Standards
Aligning Ember.js with Web Standards
 
Scalable vector ember
Scalable vector emberScalable vector ember
Scalable vector ember
 
Testing Ember Apps: Managing Dependency
Testing Ember Apps: Managing DependencyTesting Ember Apps: Managing Dependency
Testing Ember Apps: Managing Dependency
 
Parse Apps with Ember.js
Parse Apps with Ember.jsParse Apps with Ember.js
Parse Apps with Ember.js
 
Snappy Means Happy: Performance in Ember Apps
Snappy Means Happy: Performance in Ember AppsSnappy Means Happy: Performance in Ember Apps
Snappy Means Happy: Performance in Ember Apps
 
Client-side Auth with Ember.js
Client-side Auth with Ember.jsClient-side Auth with Ember.js
Client-side Auth with Ember.js
 
Containers & Dependency in Ember.js
Containers & Dependency in Ember.jsContainers & Dependency in Ember.js
Containers & Dependency in Ember.js
 
Complex Architectures in Ember
Complex Architectures in EmberComplex Architectures in Ember
Complex Architectures in Ember
 
Ember and containers
Ember and containersEmber and containers
Ember and containers
 

Recently uploaded

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 

Recently uploaded (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

New Component Patterns in Ember.js

  • 1. New Component Patterns in Ember 1.10+ or, You Really Can Take it With You
  • 2. I’m Matthew @mixonic - madhatted.com
  • 3. 201 Created Ember.js experts and JavaScript superheroes in NYC
  • 4. Out with the old,
 in with the new.
  • 5. 1 // app/index/controller.js 2 import Ember from "ember"; 3 4 export Ember.Controller.extend({ 5 session: Ember.inject.service(); 6 }); 1 // app/services/session.js 2 import Ember from "ember"; 3 4 export Ember.Object.extend({ 5 isAuthenticated: false, 6 login: function() { 7 // ... 8 } 9 }); Services in 1.10!
  • 6. HTMLBars dep! debug file! 1 <script src="/jquery.js"></script> 2 <script src="/handlebars-v2.0.0.js"></script> 3 <script src=“/1.9.1/ember.js”></script> 1 <script src="/jquery.js"></script> 2 <script src=“/1.10.0/ember-template-compiler.js”></script> 3 <script src=“/1.10.0/ember.debug.js”></script> 1.9 1.10
  • 8. New APIs mean new development patterns.
  • 9. Out with the scopes,
 in with the variables. I
  • 10. Context switching deprecated in 1.9 1 {{! this context is the controller }} 2 {{#each model}} 3 {{name}} {{! this context is each person }} 4 {{/each}} 1 {{! this context is the controller }} 2 {{#each person in model}} 3 {{person.name}} {{! this context is still the controller }} 4 {{/each}} http://emberjs.com/blog/2014/12/08/ember-1-9-0-released.html
  • 11. Context switching deprecated in 1.9 http://emberjs.com/blog/2014/12/08/ember-1-9-0-released.html 1 {{#if config.pro}} 2 <div class="travis-lint"> 3 <p>Travis Lint for clean .yml files 4 <a {{bind-attr href="lintUrl"}}>lint.travis-ci.org/{{repo.slug}}</a> 5 </p> 6 </div> 7 {{/if}} 8 9 <table id="requests" class="list"> 10 <thead> 11 <tr> 12 <th>Request</th> 13 <th>Commit</th> 14 <th>Build</th> 15 <th>Commit message</th> 16 <th>Type</th> 17 <th>Message</th> 18 </tr> 19 </thead> 20 21 <tbody> 22 {{#each controller itemController="request"}} 23 <tr {{bind-attr class="requestClass"}}> 24 <td class="request-id"> 25 <span class="status"></span> 26 {{id}} 27 </td> 28 <td>{{githubCommitLink repo.slug commit.sha}}</td> 29 <td> 30 {{#if build}} 31 {{#link-to "build" build}}#{{build.number}}{{/link-to}} 32 {{else}} 33 - 34 {{/if}} 35 </td> 36 <td class="commit-message">{{{formatMessage commit.message short="true" repoBinding=build.repo}}}</td> 37 <td>{{type}}</td> 38 <td>{{message}}</td> 39 </tr> 40 {{/each}} 41 </tbody> 42 </table>
  • 12. Context switching deprecated in 1.9 http://emberjs.com/blog/2014/12/08/ember-1-9-0-released.html 1 {{#if config.pro}} 2 <div class="travis-lint"> 3 <p>Travis Lint for clean .yml files 4 <a {{bind-attr href="lintUrl"}}>lint.travis-ci.org/{{repo.slug}}</a> 5 </p> 6 </div> 7 {{/if}} 8 9 <table id="requests" class="list"> 10 <thead> 11 <tr> 12 <th>Request</th> 13 <th>Commit</th> 14 <th>Build</th> 15 <th>Commit message</th> 16 <th>Type</th> 17 <th>Message</th> 18 </tr> 19 </thead> 20 21 <tbody> 22 {{#each controller itemController="request"}} 23 <tr {{bind-attr class="requestClass"}}> 24 <td class="request-id"> 25 <span class="status"></span> 26 {{id}} 27 </td> 28 <td>{{githubCommitLink repo.slug commit.sha}}</td> 29 <td> 30 {{#if build}} 31 {{#link-to "build" build}}#{{build.number}}{{/link-to}} 32 {{else}} 33 - 34 {{/if}} 35 </td> 36 <td class="commit-message">{{{formatMessage commit.message short="true" repoBinding=build.repo}}}</td> 37 <td>{{type}}</td> 38 <td>{{message}}</td> 39 </tr> 40 {{/each}} 41 </tbody> 42 </table> New scope
  • 13. 1 <ul id="queues"> 2 <li class="queue"> 3 <h4>Queue ({{controller.length}})</h4> 4 <ul> 5 {{#if controller.length}} 6 {{#each job in controller}} 7 {{#view Travis.QueueItemView jobBinding="job"}} 8 {{#if job.repo.slug}} 9 {{#link-to "job" job.repo job}} 10 <span class="slug" {{bind-attr title="job.slug"}}> 11 {{job.repo.slug}} 12 </span> 13 #{{job.number}} 14 {{/link-to}} 15 {{/if}} 16 {{/view}} 17 {{/each}} 18 {{else}} 19 There are no jobs 20 {{/if}} 21 </ul> 22 </li> 23 </ul> Context switching deprecated in 1.9 http://emberjs.com/blog/2014/12/08/ember-1-9-0-released.html Possible new scope?!
  • 14. Passing variables is easier to reason about than changing scope.
  • 16. 1 {{! this context is the controller }} 2 {{#each person in model}} 3 {{person.name}} {{! this context is still the controller }} 4 {{/each}} Block params introduced in 1.10 http://emberjs.com/blog/2014/12/08/ember-1-9-0-released.html 1 {{! this context is the controller }} 2 {{#each model as |person|}} 3 {{person.name}} {{! this context is still the controller }} 4 {{/each}}
  • 17. http://emberjs.com/blog/2014/12/08/ember-1-9-0-released.html 1 {{#x-menu}} 2 {{x-item selected=selected item=item}} 3 {{/x-menu}} Block params introduced in 1.10 1 <div class="x-menu"> 2 {{yield}} 3 </div>
  • 18. http://emberjs.com/blog/2014/12/08/ember-1-9-0-released.html 1 {{#x-menu as |selected|}} 2 {{x-item selected=selected item=item}} 3 {{/x-menu}} Block params introduced in 1.10 1 <div class="x-menu"> 2 {{yield selected}} 3 </div>
  • 19. http://emberjs.com/blog/2014/12/08/ember-1-9-0-released.html 1 {{#x-menu as |selected item|}} 2 {{x-item selected=selected item=item}} 3 {{/x-menu}} Block params introduced in 1.10 1 <div class="x-menu"> 2 {{yield selected item}} 3 </div>
  • 20. 1 <div class="x-menu"> 2 {{#each items as |item|}} 3 {{yield selected item}} 4 {{/each}} 5 </div> http://emberjs.com/blog/2014/12/08/ember-1-9-0-released.html 1 {{#x-menu as |selected item|}} 2 {{x-item selected=selected item=item}} 3 {{/x-menu}} Block params introduced in 1.10
  • 21. Out with the controllers,
 in with the components. II
  • 22. Out with the views,
 in with the components. II
  • 23.
  • 24. Controllers Views Receive actions Handle events Provide template scope Describe elements 1 export default Ember.Component.extend({ 2 actions: { 3 save: function(model){ 4 model.save(); 5 } 6 } 7 }); 1 <button {{action "save" model}}>Save</button>
  • 25. Controllers Views Receive actions Handle events Provide template scope Describe elements 1 export default Ember.Component.extend({ 2 color: 'red' 3 }); 1 <div>{{color}}</div>
  • 26. Controllers Views Receive actions Handle events Provide template scope Describe elements 1 export default Ember.Component.extend({ 2 click: function(){ 3 this.sendAction('save'); 4 } 5 });
  • 27. Controllers Views Receive actions Handle events Provide template scope Describe elements 1 export default Ember.Component.extend({ 2 tagName: 'li', 3 classNames: ['red'] 4 });
  • 28. Controllers deprecated when 2.0 comes out “Many people have noticed that controllers in Ember look a lot like components, but with an arbitrary division of responsibilities. We agree!” - Tomkatz, 2.0 RFC https://github.com/emberjs/rfcs/pull/15
  • 29. For new users, a single concept is easier to learn.
  • 30. “But I need mega-hackz!” III
  • 34. Here are some ideas Not finished, polished, or maybe even ever going to happen.
  • 35. On Ember components that use the new tag syntax, data-binding will be one-way. The mut helper will wrap values that the receiver can modify. <x-input value={{mut name}}></x-input> 1 export default Ember.Component.extend({! 2 tagName: 'input',! 3 change: function(){! 4 this.attrs.name.set(this.$().val());! 5 }! 6 });!
  • 36. bind-action, or maybe action, will wrap the action it references in a closure, and pass it as a function. You can call it directly. {{x-input model=model submit=(bind-action "save")}} 1 export default Ember.Component.extend({ 2 change: function(){ 3 this.attrs.submit(model); 4 } 5 });
  • 37. ref would allow you to point an action at a specific component in your current template. 1 {{video-player ref="vp"}} 2 3 <button on-click={{ref 'vp' 'play'}}>
  • 38. set would allow you to easily map an event to a value setter. <x-input on-change={{set model.name}}></x-input>
  • 39. scoped helpers allow a component to yield references to components or helpers. 1 // app/components/form-for.js 2 3 import Ember from "ember"; 4 import FormForInput from "./helpers/input"; 5 6 var makeViewHelper = Ember.HTMLBars.makeViewHelper; 7 8 export default Ember.Component.extend({ 9 formHelpers: { 10 input: makeViewHelper(FormForInput) 11 } 12 }); 1 {{! app/templates/components/form-for.hbs }} 2 3 {{yield formHelpers}} 1 {{! app/templates/post/new.hbs }} 2 3 {{#form-for as |f|}} 4 {{f.input label="Title" value=model.title}} 5 {{/form-for}}
  • 42. An experiment with mut and bind-action
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 49. bit.ly/cowboy-2 block params bit.ly/cowboy-3 bind-action bit.ly/cowboy-4 more bind-action bit.ly/cowboy-5 pass bind-action as block param bit.ly/cowboy-6 yield with each bit.ly/cowboy-7 mut
  • 50. Start using block params today, and you will quickly want some of these tools. Don’t let it stop you!