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

Angular, Rails, Require.js working in Harmony

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on. →
sporto
July 25, 2013

Angular, Rails, Require.js working in Harmony

sporto

July 25, 2013

Transcript

15 slides
  1. Page Our  app   Small core (libs + app code)

    Lots of code Precompiled  using  the  assets   pipeline   Loaded  on  demand  using   require.js  
  2. Angular  +  Require   <script> $(function () { requirejs([‘path/to/component’], function(main)

    { var $ele = $('#<%= view_id %>'); angular.bootstrap($ele, [‘APP’]); }); }); </script>
  3. Components  approach  1   FAIL!  Angular  tries  to  bootstrap  everything

      and  cannot  find  the  code   Component A Sub component B Bootstrap A Bootstrap B
  4. Components  approach  2   requirejs([‘path/to/componentA’, path/to/componentB], function(main) { var $ele

    = $('#<%= view_id %>'); angular.bootstrap($ele, [‘APP’]); }); FAIL!  This  code  just  knows  too  much   Component A Sub component B Bootstrap A + B
  5. Our  components  approach   Component A Sub component B Bootstrap

    Temp storage in rails Tell  what  you  need   Tell  what  you  need   Ask  what  to  use  
  6. Our  component  defines  what  it  needs   <%    required_js

     <<  ’/assets/…/form/main'    required_angular_modules  <<  'trading.gb_recycle_buys'    required_angular_modules  <<  'core.currencies'      view_id  =  new_view_id   %>   Component B Temp storage in rails Tell  what  you  need  
  7. Our  components  approach   <%= render ‘gb_recycle_buys/form/main' %> <%= render

    ‘events/list', eventable: transaction %> <%= render ‘shared/angular_bootstrap', view_id: view_id %> Add  a   component,   may  have  sub   components   Another   component   Bootstrap   everything  
  8. Bootstrap  everything   requirejs( <%= required_js.to_json.html_safe %>, function() { var

    $ele = $('#<%= view_id %>'); angular.bootstrap($ele, <%= required_angular_modules.uniq.to_json.html_safe %>); });

More Decks by sporto

Other Decks in Programming