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

From Backbone to React

From Backbone to React

Ludovico Fischer

May 12, 2015
Tweet

Other Decks in Programming

Transcript

  1. Who knows Backbone? Backbone: hidden popularity Manual binding (events to

    arbitrary functions) Update the interface back (how?)
  2. Backbone structure Models/collections enforce URL structure not flexible Mainly event

    declaration Backbone.Vew.extend({ events: { ’click #package-in-progress’: ’_submit’, ’click #package-complete’: ’_schedule’, ’click #print-labels’: ’_printLabels’ }, render: function() { /* All bets are off */ } });
  3. Signal Global event bus Backbone.on(’deliveries:searchstart’, function displayLoadin }); collection.on(’reset’, Backbone.trigger(’deliveries:searchen

    Inconvenients Everything can happen (similar to angular $scope) Difficult to find what emits the signal and what captures it (grep) Naming clashes It is global
  4. Reusing Backbone models A Backbone model just fetches data in

    a very inflexible way fetch want to set state and not force Forced url pattern Force update pattern listen for reset event The killer argument Bad domain decomposition Why a single model for all sections?
  5. Our app A few expert users Sidebar, main, alert, sidebar

    alert Communicates through global objects Event bus (Backbone) Singleton collection Fresh data always, always-on connection (no mobile)
  6. How to refactor Put state on top (the right top)

    <SidebarForm searchHandler={search}/> <button onClick={props.search}/> xhr.onLoad = function() { React.render( <ResultsView deliveries={deliveries}/>); }; Put external template inside render (!!) Use libraries https://github.com/christianalfoni/formsy-react https://github.com/rackt/react-router
  7. Do you need Flux? Suspicious Global stores look like Backbone

    models But you always have some kind of ’global’ database Ask instead of receive Top component passes the data: why not ask for the data yourself? Why not ask?
  8. The power of convention Props always come from the component

    that is just above Type checking helps
  9. The power of React Psychological advantage : inline template Technical

    advantage: change state or props, the view changes automatically