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

falcor-with-react

 falcor-with-react

Yosuke Kurami

April 25, 2016
Tweet

More Decks by Yosuke Kurami

Other Decks in Programming

Transcript

  1. About me • @Quramy (Yosuke Kurami) • Frontend Web Developer

    at WACUL INC. • develop SPA with Angular(1 and 2) • झຯͰTypeScript༻ͷVimϓϥΪϯ։ൃͯ͠·͢ • http://vimawesome.com/plugin/tsuquyomi 

  2. Backends For Frontends (BFF) The BFF is tightly coupled to

    a specific user experience, and will typically be maintained by the same team as the user interface. http://samnewman.io/patterns/architectural/bff/#bff
  3. What Falcor does Resources for UI
 (JSON Graph) Services BFF

    ! http://netflix.github.io/falcor/starter/what-is-falcor.html#one-model-everywhere
  4. Falcor.Model as store import {Model} from 'falcor'; import {Store} from

    '../../../lib/built'; /*** Store ***/ export const store = Store.createFromModel(new Model({ cache: { count: 0 } }));
  5. React.Component as View // Component export class App extends React.Component<{count:

    number, dispatch: (action: Action<any>) => void}, {}> { render() { const {count} = this.props; const countUp = this.countUp.bind(this); return ( <div> <p>This is simple demonstation of Falcor, React and flux.</p> <button onClick={countUp}>Click + 1</button> <span>{count}</span> </div> ); } countUp() { this.props.dispatch(countUpAction(this.props.count + 1)); } }
  6. Connect them import * as React from 'react'; import {render}

    from 'react-dom'; import {connectModel} from '../../../lib/built'; // App Container const AppContainer = connectModel(App, store, { // Component’s property < - > Path of JSON Graph count: 'count' }); /*** Bootstrap ***/ render(<AppContainer dispatch={dispatcher.dispatch.bind(dispatcher)}/>, document.getElementById('app'));
  7. ΍ͬͨ͜ͱ2 • React.ComponentΛड͚ͱͬͯComponentΛฦؔ͢਺ (=connectModel)Λ࡞੒ • ReactͷLifecycle hook + StoreͷonChangeʹͯ JSON

    Graph͔ΒstateΛੜ੒ɺҾ਺Componentͷ props΁٧ΊࠐΉ • ʮComponent͔ΒContainerΛ࡞Δʯ
 ˠ Redux΍RelayΛࢀߟʹ͍ͯ͠Δ