1 of 79

in 60 minutes

An ambitious timeframe for an ambitious framework

1

This presentation is unaffiliated with the Ember project. Ember is a trademark of Tilde Inc.

2 of 79

CC0 1.0 Universal

https://creativecommons.org/publicdomain/zero/1.0/

Released by Jen Weber under CC0 1.0 Universal, except for restrictions placed on logos/branding of Ember by Tilde.io and logos of other organizations

2

3 of 79

Objective - remember 10%

What can it do?

What are all these files?

How are they connected?

Where does MY code go?

https://tinyurl.com/emberin60

3

4 of 79

Helpful knowledge

4

> command line

5 of 79

What is Ember?

EmberJS is a free, open source framework.

It helps you build your web applications quickly and guides you towards writing scalable, maintainable code.

https://emberjs.com/

5

6 of 79

History

2007 - SproutCore

2011 - EmberJS beta

2015 - Release of 2.0

2018 - Release of 3.0

6

7 of 79

Who uses Ember?

7

8 of 79

What is Ember not?

Ember is not a back end/API/database

Ember is not like WordPress

Ember is not controlled by any one company

Ember is not wildly different than some things you may already do/know

8

9 of 79

It’s all just JavaScript

let someEmberThing = {

name: "Douglas Adams",

isTheBest: function() {

return true

}

}

9

10 of 79

Separation of Concerns

What the user sees

User interactions

Routing (urls)

Fetching/changing data

Query parameters

Managing shared state

Styling

Local data caching

Testing

Build Steps

Third party libraries

Dev tools

10

11 of 79

Separation of Concerns

What the user sees Template

User interactions Component

Routing (urls) Routes & Router

Fetching/changing data Ember Data

Query parameters Controller

Managing shared state Service

Styling CSS/LESS/SASS

Local data caching Ember Data Store

Testing Tests

Build Steps Ember CLI

Third party libraries Ember Addons

Dev tools Ember Inspector

11

12 of 79

Configuration over convention

12

13 of 79

Convention over configuration

13

14 of 79

Let’s build something!

14

15 of 79

Getting Started

npm install -g ember-cli

ember -version

ember new app-name

cd app-name

ember serve

15

16 of 79

Introducing the Ember CLI

A command line tool that helps you:

  • create your app file structure
  • generate new files
  • install dependencies
  • build and serve your app
  • run tests
  • deploy
  • upgrade app versions

16

17 of 79

Contents of your average app directory

adapters/

components/

controllers/

helpers/

models/

routes/

serializers/

templates/

17

18 of 79

Contents of your average app directory

adapters / conference.js

components / single-conf.js

controllers / conference.js

helpers / format-conf-date.js

models / conference.js

routes / conferences.js

serializers / conference.js

templates / conferences.hbs

18

19 of 79

Learning Curves

19

How much you need to teach yourself

Time/App Maturity

20 of 79

adapters/

components/

controllers/

helpers/

models/

routes/

serializers/

templates/

services/

20

Adapters

&

Serializers

(Ember Data)

21 of 79

Adapter - the home of request URLs

ember g adapter application

21

22 of 79

Adapter - the home of request URLs

// app/adapters/application.js

import DS from 'ember-data';

export default DS.JSONAPIAdapter.extend({

});

22

23 of 79

Adapter - the home of request URLs

// app/adapters/application.js

import DS from 'ember-data';

export default DS.JSONAPIAdapter.extend({

host: 'http://my-back-end-server.com'

});

23

24 of 79

Serializer - formatting requests/responses

{

hero_id: 5,

first_name: “Super”,

last_name: “Woman”

};

{

id: 5,

firstName: “Super”,

lastName: “Woman”

};

24

Back End

Front End

25 of 79

Types of Adapters/Serializers

JSONAPI

REST

JSON

Community: ActiveRecord, GraphQL, Django, and more

25

*Can be configured to work with almost any kind of back end architecture

26 of 79

But wait…. :C

26

27 of 79

You don’t have to use Ember Data

27

28 of 79

adapters/

components/

controllers/

helpers/

models/

routes/

serializers/

templates/

services/

28

Models

(Ember Data)

29 of 79

Think about your database….

29

id

name

location

534

Boston Code Camp

Greater Boston, MA

535

EmberConf

Portland, OR

30 of 79

Models - what the data looks like

ember g model conference

30

31 of 79

Model - what the data looks like

import DS from 'ember-data';

export default DS.Model.extend({

name: DS.attr('string'),

date: DS.attr('date'),

attendees: DS.attr('number'),

registrationOpen: DS.attr('boolean'),

someArrayOrNestedObject: DS.attr(),

});

31

32 of 79

A sneak peek...

let bcc = {

name: "Boston Code Camp",

registrationOpen: false

}

this.store.createRecord('conference', bcc).save()

32

// POST to http://my-back-end.com/api/conferences

33 of 79

adapters/

components/

controllers/

helpers/

models/

routes/

serializers/

templates/

services/

33

Routes

34 of 79

Routing - what the user sees in the url

“Don’t break the internet”

34

35 of 79

Route - a place to GET & share records

ember g route conferences

35

36 of 79

2 files get created...

36

HBS

templates/routes/conferences.hbs

a handlebars template where html markup goes and data is passed

JS

routes/conferences.js

a javascript file where data is loaded

37 of 79

Route JS - a place to GET data

import Route from '@ember/routing/route';

export default Route.extend({

model() {

return this.store.findAll('conference')

}

});

GET request to http://your-app/api/conferences

37

// GET to http://my-back-end.com/api/conferences

38 of 79

Routes Template- a place to share data

{{!-- templates/conferences.hbs --}}

<h1>Conferences Route</h1>

{{conferences-list conferences=model}}

38

39 of 79

39

http://my-ember-app.com/route-name

route-name

component-name

component-name

component-name

component-name

40 of 79

Route

Component

Component

Component

Component

40

HBS

JS

HBS

JS

HBS

JS

HBS

JS

HBS

JS

41 of 79

Routes Template- a place to share data

{{navbar-top}}

{{conferences-list conferences=model}}

{{footer-info}}

41

*Only one of these components has access to the model!

42 of 79

adapters/

components/

controllers/

helpers/

models/

routes/

serializers/

templates/

services/

42

Components

43 of 79

Component - interface & interaction

ember g component conferences-list

43

44 of 79

2 files get created...

44

HBS

templates/components/conferences-list.hbs

a handlebars template where html markup goes and data is passed or displayed to the user

JS

components/conferences-list.js

a javascript file that handles user interactions

45 of 79

45

http://my-ember-app.com/conferences

Conferences Route

conferences-list component

  • Boston Code Camp
  • EmberConf
  • EmberCamp London

46 of 79

Static html markup

<ul>

<li>Boston Code Camp</li>

<li>EmberConf</li>

<li>EmberCamp London</li>

</ul>

46

47 of 79

Component Template - display

{{!-- conferences-list.hbs --}}

<ul>

</ul>

47

{{#each conferences as |conference|}}

<li>{{conference.name}}</li>

{{/each}}

48 of 79

Component HBS and JS are linked

48

HBS

JS

Anything passed into the template is available in the JS

Anything defined in the JS is available in the template

49 of 79

Component HBS + JS

<h3>{{heading}}</h3>

<button class={{btnClass}}>

Submit

</button>

49

export default Component.extend({

heading: "Request Sloths",

btnClass: "sloth-btn"

});

50 of 79

Component JS - interaction

jQuery

50

Ember actions

&

events

51 of 79

Introducing the actions helper

<button {{action "slothsPlz" "thanks"}}>

Submit

</button>

51

52 of 79

Receiving action data

import Component from '@ember/component';

export default Component.extend({

actions: {

slothsPlz(message) {

console.log(message)

}

}

});

52

53 of 79

Core Concept:

Passing Data

53

54 of 79

Passing variables

{{con-card conference=conference}}

{{con-favorite conference=conference}}

{{con-form conference=conference}}

54

55 of 79

Passing actions

{{con-card doIt=(action ‘slothsPlz’)}}

{{con-favorite slothsPlz=slothsPlz}}

{{con-form slothsPlz=slothsPlz}}

55

56 of 79

Core Concept:

Computed Properties

56

57 of 79

Automatically updating variables

57

Jen

JW

Weber

First Name:

Last Name:

58 of 79

Component JS

initials: Ember.Computed('firstName', 'lastName', function() {

let firstName = this.get('firstName')

let lastName = this.get('lastName')

return firstName[0] + lastName[0]

})

58

59 of 79

Component template

<div class=”nav”>{{initials}}</div>

{{input value=firstName}}

{{input value=lastName}}

59

60 of 79

adapters/

components/

controllers/

helpers/

models/

routes/

serializers/

templates/

services/

60

Services

61 of 79

Service - JS for shared state/functions

61

some-service.js

component

controller

route

another service

62 of 79

Addons & dependencies

62

63 of 79

Plan A: Ember Observer

https://emberobserver.com/

63

64 of 79

Installing an Ember addon

ember install liquid-fire

64

65 of 79

Plan B: npm using ember-browserify

npm install --save-dev ember-browserify

npm install some-npm-package

65

66 of 79

Tests

66

67 of 79

Testing

ember g acceptance test submitting-a-form

ember test --server or visit http://localhost:4200/tests

67

68 of 79

Learning Resources

68

69 of 79

EmberJS Super Rentals Tutorial

https://guides.emberjs.com

69

70 of 79

The Guides

https://emberjs.com/api/

70

71 of 79

The API Docs

https://guides.emberjs.com

71

72 of 79

Ember CLI Docs

https://ember-cli.com/

72

73 of 79

Community

https://emberjs.com/community

73

https://ember-community-slackin.herokuapp.com/

https://www.meetup.com/Boston-Ember-js

...and more! https://discuss.emberjs.com/, IRC, StackOverflow

74 of 79

(A sample of) Community Tutorials

74

75 of 79

News

EmberJS Times https://the-emberjs-times.ongoodbits.com/

Ember Weekly

http://www.emberweekly.com/

Ember Weekend Podcast

https://emberweekend.com/episodes

75

76 of 79

One small request...

https://tinyurl.com/emberbcc

76

77 of 79

Raffle Time!

77

78 of 79

Special thanks...

Boston Code Camp

Braden Lawrence

Aaron Sikes (aka courajs)

Ricardo Mendes (aka locks)

EmberJS Learning team & contributors

78

79 of 79

Presented by:

Jen Weber

Twitter: @jwwweber

GitHub: jenweber

Ember Slack: jenweber

Email: weberj10@gmail.com

79

https://biobright.com/careers