Slide 1

Slide 1 text

Relay Meguro.es #3

Slide 2

Slide 2 text

@hokaccha

Slide 3

Slide 3 text

Relay

Slide 4

Slide 4 text

React

Slide 5

Slide 5 text

GraphQL

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

GraphQL

Slide 8

Slide 8 text

GraphQLͱ͸ • Facebook͕։ൃͨ͠ΫΤϦݴޠ • ΫϥΠΞϯτ/αʔόʔؒͷ΍ΓऔΓʹ࢖ΘΕΔ • REST΍RPCͱൺֱ͞ΕΔ

Slide 9

Slide 9 text

http://example.com/products/1 { "id": 1, "name": "foo", "description": "..." "image": { "uri": "http://...", "width": 120, "height": 120 } }

Slide 10

Slide 10 text

http://example.com/graphql { "product" : { "id": 1, "name": "foo", "description": "..." "image": { "uri": "http://...", "width": 120, "height": 120 } } } { product(id: 1) { id, name, description, image(size: 120) { uri, width, height } } } 3FRVFTU 3FTQPOTF

Slide 11

Slide 11 text

ଓ͖͸WebͰ http://graphql.org/

Slide 12

Slide 12 text

Relay

Slide 13

Slide 13 text

A JavaScript framework for building data-driven React Applications

Slide 14

Slide 14 text

ैདྷͷख๏ 1. Πϕϯτ͕τϦΨʔ͞ΕΔ 2. αʔόʔʹϦΫΤετ͢Δ 3. ϨεϙϯεΛݩʹViewΛ࠶ߏங͢Δ

Slide 15

Slide 15 text

$el.find('.select').on('selectProduct', id => { fetch(`/products/${id}`).then(product => { $('.name').text(product.name); $('.description').text(product.description); }); });

Slide 16

Slide 16 text

ReactΛ࢖ͬͨ৔߹ 1. Πϕϯτ͕τϦΨʔ͞ΕΔ 2. αʔόʔʹϦΫΤετ͢Δ 3. ϨεϙϯεͷσʔλΛݩʹstateΛߋ৽͢Δ • ࣗಈͰView͕ߋ৽͞ΕΔ

Slide 17

Slide 17 text

class AppComponent extends React.Component { handleSelect(id) { fetch(`/products/{id}`).then(product => { // update state }); } render() { return ( let { name, description } = this.props.app.product;
this.handleSelect(id)} />

{name}

{description}
); } } ໋ྩత એݴత

Slide 18

Slide 18 text

RelayΛ࢖ͬͨ৔߹ 1. Πϕϯτ͕τϦΨʔ͞ΕΔ 2. ϦΫΤετΛͭ͘ΔͨΊͷ஋Λߋ৽͢Δ • ࣗಈͰϦΫΤετΛૹΔ • ϨεϙϯεͷσʔλΛݩʹstateΛࣗಈͰߋ৽ • View͕ࣗಈతʹߋ৽͞ΕΔ

Slide 19

Slide 19 text

class AppComponent extends React.Component { handleSelect(id) { this.props.relay.setVariables({ id }); } render() { let { name, description } = this.props.app.product; return ( // Reactͷྫͱಉ༷ ); } } const AppContainer = Relay.createContainer(AppComponent, { initialVariables: { id: 1 }, fragments: { app: () => Relay.QL` fragment on App { product(id: $id) { name, description } } `, }, }); એݴత

Slide 20

Slide 20 text

ଞʹ΋ɾɾɾ • ΫΤϦͷߏ଄Խ • ΫΤϦͷ੩తܕνΣοΫ • σʔλͷߋ৽ • ϩʔσΟϯάͷ੍ޚ • Ωϟογϡ • ϖʔδωʔγϣϯ • ͳͲͳͲ੝Γͩ͘͞Μ

Slide 21

Slide 21 text

RelayͷͭΒ͍ͱ͜Ζ

Slide 22

Slide 22 text

• GraphQL/Reactͷ஌͕ࣝલఏ • babelΛ࢖ͬͨϏϧυ؀ڥඞਢ • React΄ͲγϯϓϧͰ͸ͳ͍ • ͪΐͬͱࢼ͚ͩ͢Ͱ΋ෑډߴ͍ • ݱ࣌఺Ͱ͸ࢿྉ΍ࢀߟΞϓϦ͕ઈ๬తʹগͳ͍

Slide 23

Slide 23 text

fin.