Slide 1

Slide 1 text

Ember NYC Ember Components Ember Components August 2013 Thursday, August 22, 13 can you see this?

Slide 2

Slide 2 text

JOHN ALLISON @JRALLISON Thursday, August 22, 13 Picture from our company retreat last week. It was awesome, you should do it.

Slide 3

Slide 3 text

embereNos since JUNE ’12 Thursday, August 22, 13 Used ember.js in production for over a year. Ember has been moving fast (as you know), we have lots of bumps and bruises, but really liking where the framework is headed. large ember application... 41 controllers (story)

Slide 4

Slide 4 text

Component? What’s a Thursday, August 22, 13

Slide 5

Slide 5 text

Thursday, August 22, 13 don’t really know angular, but still thought it was funny

Slide 6

Slide 6 text

Reuse Reuse Reuse Reuse simplify Reuse Views Thursday, August 22, 13 taking a step back One of the recurring themes we’ve faced is how to extract templates and behavior to simplify and better reuse code. We’ve tried several approaches and most brought us....

Slide 7

Slide 7 text

PAIN PAIN Thursday, August 22, 13 ... for a variety of reasons.

Slide 8

Slide 8 text

How to reuse? Thursday, August 22, 13 taking an example... we have a “paginated list” used many places around our ember application has a variety of different uses, different columns, content, paginated or infinite scroll, etc... prior to components, what are the options for sharing view templates and behavior? all prior alternatives have great use-cases, but I’d argue that they aren’t really suited for real reuse

Slide 9

Slide 9 text

Custom handlebars helpers? Thursday, August 22, 13 pro: ? very low-level control if you need it... con: can be quite confusing to make sure you know about how to setup context, etc. con: not something you should be doing if you want reusable code to be a pattern in your codebase IMO.

Slide 10

Slide 10 text

Partials? Thursday, August 22, 13 pro: great for simplifying views by breaking up into smaller pieces con: no real way to encapsulate behavior con for reusable code: context is the parent view, no separation

Slide 11

Slide 11 text

Shared views? Thursday, August 22, 13 this is what we ended up doing when we faced this problem awhile ago. pro: can encapsulate both template and behavior con: you’re still sharing context with the parent view, which can make it hard to reuse if you aren’t careful con: if you need data for your shared view, you’ll have to manually setup any controllers or related objects

Slide 12

Slide 12 text

Shared views? (share implemention of paginated view) Thursday, August 22, 13 also has a view object, state machine, and associated controller which aren’t shown not great but it worked for us.

Slide 13

Slide 13 text

RenDER? Thursday, August 22, 13 if render had been around when we were building this, we may have used it instead. I don’t have much hand on knowledge of render, but the idea is it setups up a MVC structure like a route would. pro: encapsulated, isolated template and behavior! con: can be heavy weight if you don’t have a model or much related data con: expects a model, which can make it hard to reuse in a generic way.

Slide 14

Slide 14 text

ComponentS Introduced in 1.0 RC.6 Isolated, self-contained “Views” Implementation modeled after W3C “Custom Elements” Spec Thursday, August 22, 13

Slide 15

Slide 15 text

BUILDING components Thursday, August 22, 13 while on our retreat, we talked high level company goals but we also were able to start hacking on a refresh of our interface and update our ember skillz with all the newest stuff and write some golang...

Slide 16

Slide 16 text

BUILDING components Thursday, August 22, 13 sparkline: great candidate for components. used elsewhere in the app, not just specific to campaigns. Just needs to know about a few pieces of data needs control over template and view to properly setup and render.

Slide 17

Slide 17 text

BUILDING components Thursday, August 22, 13 ‘components/’ namespace dash is to met the “Custom Elements” spec context is limited to only data passed to the component. we can now use the component to render any type of data (rather then being tied to a campaign, etc)

Slide 18

Slide 18 text

BUILDING components Thursday, August 22, 13 just like a view! well, except: actions context

Slide 19

Slide 19 text

Block Components Thursday, August 22, 13 body of block shares outer context, not component context.

Slide 20

Slide 20 text

IS hiriing embereNos Thanks! @jrallison john@customer.io Thursday, August 22, 13