Slide 1

Slide 1 text

Angular,  Rails  and  Require.js   working  in  Harmony   Sebas:an  Porto  

Slide 2

Slide 2 text

Page Our  app   Small core (libs + app code) Lots of code Precompiled  using  the  assets   pipeline   Loaded  on  demand  using   require.js  

Slide 3

Slide 3 text

Angular  sweet  path   Load all application code Automatic bootstrap

Slide 4

Slide 4 text

Angular  +  Require   Load application code using require.js Manual bootstrap

Slide 5

Slide 5 text

Angular  +  Require   $(function () { requirejs([‘path/to/component’], function(main) { var $ele = $('#<%= view_id %>'); angular.bootstrap($ele, [‘APP’]); }); });

Slide 6

Slide 6 text

Components   Component  A   Component  B  

Slide 7

Slide 7 text

Components   Component  B   Component  C  

Slide 8

Slide 8 text

Components   Component A Component B Own  angular   code   Own  angular   code  

Slide 9

Slide 9 text

Components  approach  1   FAIL!  Angular  tries  to  bootstrap  everything   and  cannot  find  the  code   Component A Sub component B Bootstrap A Bootstrap B

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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  

Slide 12

Slide 12 text

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  

Slide 13

Slide 13 text

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  

Slide 14

Slide 14 text

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 %>); });

Slide 15

Slide 15 text

Feedback,  ques:ons