SlideShare une entreprise Scribd logo
1  sur  31
Télécharger pour lire hors ligne
Talk	
  Directly	
  with	
  Ac#veRecord	
  	
  
using	
  Ext.Direct	
  and	
  Rack	
  Middleware	
  




           Stone	
  Gao,	
  Ekohe	
  




                     Stone	
  Gao,	
  KungfuRails	
  
                    (stones.gao@gmail.com)	
  
Outline	
  
•  Intro	
  to	
  Ext	
  Js	
  
•  The	
  Problem	
  
•  The	
  SoluDon	
  :	
  Ext.Direct	
  	
  
•  Intro	
  to	
  Rack	
  Middleware	
  
•  Ac#veDirect	
  (an	
  Experimental	
  ImplementaDon	
  
   of	
  Ext.Direct,	
  yet	
  )	
  
•  What	
  can	
  you	
  do	
  with	
  Ac#veDirect	
  (Examples)	
  
•  Q	
  &	
  A	
  
                            Stone	
  Gao,	
  KungfuRails	
  
                           (stones.gao@gmail.com)	
  
Intro	
  to	
  Ext	
  Js	
  
Ext	
  JS	
  is	
  a	
  cross-­‐browser	
  JavaScript	
  library	
  for	
  building	
  rich	
  
internet	
  applicaDons.	
  

•  igh	
  performance,	
  customizable	
  UI	
  widgets,	
  Ajax	
  
      H
• ntuiDve,	
  easy	
  to	
  use	
  API	
  
      I
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  (hTp://www.extjs.com)	
  	
  




                                                                                                                            Stone	
  Gao,	
  KungfuRails	
  
                                                                                                                           (stones.gao@gmail.com)	
  
The	
  Problem	
  




     Stone	
  Gao,	
  KungfuRails	
  
    (stones.gao@gmail.com)	
  
Ajax	
  Calls	
  
Foo.js	
  
…….	
  

Ext.Ajax.request({	
                                                                             Bar.js	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  url:	
  ("/foo?format=json"),	
  
                                                                                      ……	
                                                                                       Baz.js	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  method:	
  "POST",	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  jsonData:	
  	
  payLoad,	
                                                                                                         ……	
  
                                                                                      Ext.Ajax.request({	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  success:	
  this..success,	
  
                                                                                      	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  url:	
  (”/bar?format=json"),	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  failure:	
  this.failure,	
                                                                                                         Ext.Ajax.request({	
  
                                                                                      	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  method:	
  ”GET",	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  headers:	
  {	
  
                                                                                      	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  jsonData:	
  	
  payLoad,	
                   	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  url:	
  (”/baz?format=json"),	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  'accepts':	
  'applicaDon/json'	
     	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  success:	
  this..success,	
                  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  method:	
  "POST",	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  },	
  
                                                                                      	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  failure:	
  this.failure,	
                   	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  jsonData:	
  	
  payLoad,	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  scope	
  :	
  this	
  
                                                                                      	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  headers:	
  {	
                               	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  success:	
  this..success,	
  
	
  	
  	
  	
  	
  	
  	
  	
  });	
                                                                                                                                       	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  failure:	
  this.failure,	
  
                                                                                      	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  'accepts':	
  'applicaDon/json'	
  
                                                                                      	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  },	
                                          	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  headers:	
  {	
  
……	
                                                                                  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  scope	
  :	
  this	
                          	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  'accepts':	
  'applicaDon/json'	
  
                                                                                      	
  	
  	
  	
  	
  	
  	
  	
  });	
                                                 	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  },	
  
                                                                                                                                                                            	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  scope	
  :	
  this	
  
                                                                                      ……	
                                                                                  	
  	
  	
  	
  	
  	
  	
  	
  });	
  

                                                                                                                                                                            ……	
  




                                                                                               Stone	
  Gao,	
  KungfuRails	
  
                                                                                              (stones.gao@gmail.com)	
  
Ajax	
  Calls	
  
Foo.js	
  
…….	
  

Ext.Ajax.request({	
                                                                             Bar.js	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  url:	
  ("/foo?format=json"),	
  
                                                                                      ……	
                                                                                       Baz.js	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  method:	
  "POST",	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  jsonData:	
  	
  payLoad,	
                                                                                                         ……	
  
                                                                                      Ext.Ajax.request({	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  success:	
  this..success,	
  
                                                                                      	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  url:	
  (”/bar?format=json"),	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  failure:	
  this.failure,	
                                                                                                         Ext.Ajax.request({	
  
                                                                                      	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  method:	
  ”GET",	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  headers:	
  {	
  
                                                                                      	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  jsonData:	
  	
  payLoad,	
                   	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  url:	
  (”/baz?format=json"),	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  'accepts':	
  'applicaDon/json'	
     	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  success:	
  this..success,	
                  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  method:	
  "POST",	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  },	
  
                                                                                      	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  failure:	
  this.failure,	
                   	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  jsonData:	
  	
  payLoad,	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  scope	
  :	
  this	
  
                                                                                      	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  headers:	
  {	
                               	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  success:	
  this..success,	
  
	
  	
  	
  	
  	
  	
  	
  	
  });	
                                                                                                                                       	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  failure:	
  this.failure,	
  
                                                                                      	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  'accepts':	
  'applicaDon/json'	
  
                                                                                      	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  },	
                                          	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  headers:	
  {	
  
……	
                                                                                  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  scope	
  :	
  this	
                          	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  'accepts':	
  'applicaDon/json'	
  
                                                                                      	
  	
  	
  	
  	
  	
  	
  	
  });	
                                                 	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  },	
  
                                                                                                                                                                            	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  scope	
  :	
  this	
  
                                                                                      ……	
                                                                                  	
  	
  	
  	
  	
  	
  	
  	
  });	
  

                                                                                                                                                                            ……	
  




                                                                                               Stone	
  Gao,	
  KungfuRails	
  
                                                                                              (stones.gao@gmail.com)	
  
The	
  SoluDon	
  




    Stone	
  Gao,	
  KungfuRails	
  
   (stones.gao@gmail.com)	
  
The	
  SoluDon	
  

Ext.Direct	
  
 Ext.Direct	
  is	
  a	
  pladorm	
  and	
  language	
  agnosDc	
  technology	
  to	
  
 remote	
  server-­‐side	
  methods	
  to	
  the	
  client-­‐side.	
  Furthermore,	
  
 Ext.Direct	
  allows	
  for	
  seamless	
  communicaDon	
  between	
  the	
  
 client-­‐side	
  of	
  an	
  Ext	
  applicaDon	
  and	
  any	
  server-­‐side	
  pladorm.	
  

 (hTp://www.extjs.com/products/extjs/direct.php)	
  	
  

You	
  can	
  write	
  the	
  following	
  code	
  in	
  javascript	
  :	
  	
  
App.models.Category.foo()	
  
App.models.Category.bar()	
  
App.models.Category.create(	
  {	
  name	
  :	
  ‘ruby’	
  }	
  	
  )	
  
App.models.Category.update(	
  1,	
  {	
  name	
  :	
  ‘ruby’	
  }	
  	
  )	
  
App.models.Category.delete(1)	
  
                                          Stone	
  Gao,	
  KungfuRails	
  
                                         (stones.gao@gmail.com)	
  
Intro	
  to	
  Rack	
  Middleware	
  	
  
                                                       Middleware	
                    App	
  



                HTTP	
  Request	
  




  HTTP	
  
  Client	
                             log	
                auth	
         cache	
  
(browser)	
     HTTP	
  Response	
  




                                        Stone	
  Gao,	
  KungfuRails	
  
                                       (stones.gao@gmail.com)	
  
Intro	
  to	
  Rack	
  Middleware	
  	
  

>>	
  	
  ps	
  aux	
  |	
  grep	
  ruby	
  |	
  wc	
  –l	
  
3	
  

Rack	
  Middleware	
  is	
  Pipeline	
  for	
  HTTP	
  Req	
  Processing!	
  	
  
                                                                                                                                              Middleware	
                 App	
  


 The	
  Unix	
  Philosophy	
  :	
  	
  
                                                                                                             HTTP	
  Request	
  
 Rack	
  Middleware	
  is	
  	
  
 Chainable	
                                                                                   HTTP	
  

 and	
                                                                                         Client	
  
                                                                                             (browser)	
  
                                                                                                             HTTP	
  Response	
  
                                                                                                                                    log	
        auth	
        cache	
  



 Composable	
  like	
  Unix	
  Pipelines	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  


                                                                          Stone	
  Gao,	
  KungfuRails	
  
                                                                         (stones.gao@gmail.com)	
  
Intro	
  to	
  Rack	
  Middleware	
  	
  

Conven#on	
  :	
  app.call(env)	
  


lambda	
  {	
  |env|	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  #Rack	
  Environment	
  variables	
  	
  
	
  	
  [	
  	
  200,	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  #Status	
  Code	
  	
  
	
  	
  	
  	
  	
  {‘Content-­‐Type’	
  =>	
  ‘text/plain’},	
  	
  	
  	
  	
  	
  #Headers	
  	
  
	
  	
  	
  	
  	
  	
  [‘Hello	
  World!’]	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  #Reponse	
  Body	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
	
  	
  ]	
  
}	
  	
  




                                                                                                                Stone	
  Gao,	
  KungfuRails	
  
                                                                                                               (stones.gao@gmail.com)	
  
Ac#veDirect	
  (an	
  Experimental	
  ImplementaDon	
  of	
  Ext.Direct,	
  yet	
  )	
  
Talk	
  Directly	
  with	
  Ac#veRecord	
  using	
  Ext.Direct	
  and	
  Rack	
  Middleware	
  




                                         Stone	
  Gao,	
  KungfuRails	
  
                                        (stones.gao@gmail.com)	
  
Ac#veDirect	
  (an	
  Experimental	
  ImplementaDon	
  of	
  Ext.Direct,	
  yet	
  )	
  
 Talk	
  Directly	
  with	
  Ac#veRecord	
  using	
  Ext.Direct	
  and	
  Rack	
  Middleware	
  
                                                                                       Method	
  
                                                                                     Dispatching	
  


                                             AcDveDirect::Router	
  



  Ext.Direct	
  	
  



                                                AcDveDirect::Api	
  


           Server-­‐side	
                                                                         App	
  
         methods	
  configs	
                       Rack	
  Middleware	
  

                                           Stone	
  Gao,	
  KungfuRails	
  
                                          (stones.gao@gmail.com)	
  
Ac#veDirect	
  (an	
  Experimental	
  ImplementaDon	
  of	
  Ext.Direct,	
  yet	
  )	
  
   How	
  Ac#veDirect::Api	
  works	
  	
  

                                          App.REMOTING_API	
  =	
  {	
  
                                          	
  	
  	
  	
  "ac#ons":	
  {	
  
                                          	
  	
  	
  	
  	
  	
  	
  	
  "Category":	
  [	
  
                                          	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  {	
  
                                          	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "name":	
  "all",	
  
                                          	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "len":	
  1	
  
GET	
  /direct_api	
                      	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  },	
  
                                          	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  {	
  
                                          	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "name":	
  "update_all",	
  
                                          	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "len":	
  2	
  
                                          	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  }	
  
                                          	
  	
  	
  	
  	
  	
  	
  	
  ]	
  
                                          	
  	
  	
  	
  },	
  
                                          	
  	
  	
  	
  "namespace":	
  "App.models",	
  
                                          	
  	
  	
  	
  "url":	
  "/direct_router",	
  
                                          	
  	
  	
  	
  "type":	
  "remo#ng"	
  
                                          };	
  

                                     Stone	
  Gao,	
  KungfuRails	
  
                                    (stones.gao@gmail.com)	
  
Ac#veDirect	
  (an	
  Experimental	
  ImplementaDon	
  of	
  Ext.Direct,	
  yet	
  )	
  
How	
  Ac#veDirect::Router	
  works	
  

                               App.models.Category.all()	
  


POST	
  /direct_router	
  	
  	
  	
  	
  {"ac#on":"Category","method":"all","data":[],"type":"rpc","#d":3}	
  

                                                                                                   Ac#veDirect::Router	
  




                Category.send	
  :all	
  
                                              Stone	
  Gao,	
  KungfuRails	
  
                                             (stones.gao@gmail.com)	
  
Ac#veDirect	
  -­‐	
  ConfiguraDon	
  
•  Middleware	
  configuraDons	
  (environment.rb)	
  
	
  	
  	
  	
  	
  config.middleware.use	
  'Ac#veDirect::Router',	
  '/direct_router'	
  
	
  	
  	
  	
  	
  config.middleware.use	
  'Ac#veDirect::Api',	
  '/direct_api',	
  '/direct_router’	
  




•  Method	
  configuraDons	
  	
  
	
  	
  	
  	
  	
  	
  <script	
  type="text/javascript"	
  src=”/javascripts/ext/adapter/ext/ext-­‐base.js"></script>	
  
	
  	
  	
  	
  	
  	
  <script	
  type=“text/javascript”	
  src=”/javascripts/ext/ext-­‐all-­‐debug.js"></script>	
  
	
  	
  	
  	
  	
  	
  <script	
  type=“text/javascript”	
  src=”/direct_api"></script>	
  

	
  	
  	
  	
  	
  	
  Ext.Direct.addProvider(App.REMOTING_API);	
  




                                                        Stone	
  Gao,	
  KungfuRails	
  
                                                       (stones.gao@gmail.com)	
  
Ac#veDirect	
  -­‐	
  ConfiguraDon	
  
•  Model	
  configuraDons	
  	
  
class	
  Category	
  <	
  AcDveRecord::Base	
  
	
  	
  	
  	
  acts_as_nested_set	
  
	
  	
  	
  	
  has_many	
  :books	
  
	
  	
  	
  	
  acts_as_direct	
  	
  :root_nodes	
  =>	
  0,	
  :create_new_cat	
  =>	
  {:len	
  =>	
  1,	
  :formHandler	
  =>	
  true}	
  

	
  	
  	
  	
  def	
  root_nodes	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  ……	
  
	
  	
  	
  	
  end	
  	
  
	
  	
  	
  	
  def	
  create_new_cat(params)	
  	
                                           Custom	
  remotable	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  ……	
                                                          methods	
  
	
  	
  	
  	
  end	
  
end	
  	
  

                                                           Stone	
  Gao,	
  KungfuRails	
  
                                                          (stones.gao@gmail.com)	
  
What	
  can	
  you	
  do	
  with	
  Ac#veDirect	
  	
  	
  

             CRUD	
  Default	
  Remotable	
  Methods	
  




            Custom	
  Remotable	
  Methods	
  



                        Stone	
  Gao,	
  KungfuRails	
  
                       (stones.gao@gmail.com)	
  
What	
  can	
  you	
  do	
  with	
  Ac#veDirect	
  (examples)	
  	
  	
  


App.models.Category.create(	
  {	
  name	
  :	
  ‘ruby’	
  }	
  	
  )	
  




                                                   Stone	
  Gao,	
  KungfuRails	
  
                                                  (stones.gao@gmail.com)	
  
What	
  can	
  you	
  do	
  with	
  Ac#veDirect	
  (examples)	
  	
  	
  


App.models.Category.update(2,	
  	
  {	
  name	
  :	
  ‘ruby	
  books’	
  }	
  )	
  




                                                Stone	
  Gao,	
  KungfuRails	
  
                                               (stones.gao@gmail.com)	
  
What	
  can	
  you	
  do	
  with	
  Ac#veDirect	
  (examples)	
  	
  


App.models.Category.update_all({	
  name	
  :	
  ‘ruby	
  books’	
  },	
  	
  “	
  name	
  LIKE	
  ‘%ruby%’	
  ”	
  )	
  




                                               Stone	
  Gao,	
  KungfuRails	
  
                                              (stones.gao@gmail.com)	
  
What	
  can	
  you	
  do	
  with	
  Ac#veDirect	
  (examples)	
  	
  

App.models.Category.all()	
  




                                 Stone	
  Gao,	
  KungfuRails	
  
                                (stones.gao@gmail.com)	
  
What	
  can	
  you	
  do	
  with	
  Ac#veDirect	
  (examples)	
  	
  


App.models.Category.find(	
  2	
  )	
  




                                          Stone	
  Gao,	
  KungfuRails	
  
                                         (stones.gao@gmail.com)	
  
What	
  can	
  you	
  do	
  with	
  Ac#veDirect	
  (examples)	
  	
  


App.models.Category.find_every(	
  {	
  condi#ons	
  :	
  “name	
  LIKE	
  ‘%java%’	
  “	
  }	
  )	
  




                                             Stone	
  Gao,	
  KungfuRails	
  
                                            (stones.gao@gmail.com)	
  
What	
  can	
  you	
  do	
  with	
  Ac#veDirect	
  (examples)	
  	
  


App.models.Category.exists(	
  [“	
  name	
  LIKE	
  ?	
  “,	
  	
  ‘%java%’	
  ]	
  )	
  




                                                  Stone	
  Gao,	
  KungfuRails	
  
                                                 (stones.gao@gmail.com)	
  
What	
  can	
  you	
  do	
  with	
  Ac#veDirect	
  (examples)	
  	
  




                           Stone	
  Gao,	
  KungfuRails	
  
                          (stones.gao@gmail.com)	
  
What	
  can	
  you	
  do	
  with	
  Ac#veDirect	
  (examples)	
  	
  


App.models.Category.count()	
  




                                   Stone	
  Gao,	
  KungfuRails	
  
                                  (stones.gao@gmail.com)	
  
What	
  can	
  you	
  do	
  with	
  Ac#veDirect	
  (examples)	
  	
  


App.models.Category.delete(	
  2	
  )	
  
App.models.Category.delete_all(	
  “	
  name	
  LIKE	
  	
  ‘%java%’	
  	
  “	
  	
  )	
  




                                                 Stone	
  Gao,	
  KungfuRails	
  
                                                (stones.gao@gmail.com)	
  
Wait,	
  Where	
  is	
  My	
  Controllers	
  ?!!	
  

     For	
  Ext	
  Js	
  Applica#ons,	
  you	
  don’t	
  necessarily	
  have	
  tradi#onal	
  Controllers	
  	
  


     You	
  front	
  end	
  control	
  logics	
  is	
  the	
  Controllers	
  and	
  Ext	
  Widgets	
  is	
  the	
  Views	
  



You	
  can	
  call	
  your	
  Model	
  methods	
  directly	
  using	
  Ext.Direct	
  	
  and	
  Ac#veDirect	
  




                                                     Stone	
  Gao,	
  KungfuRails	
  
                                                    (stones.gao@gmail.com)	
  
Let’s	
  Collaborate	
  to	
  Improve	
  it	
  	
  	
  




                 hTp://github.com/stonegao/acDve-­‐direct	
  

                  (It’s	
  my	
  first	
  library	
  	
  )	
  

                       Stone	
  Gao,	
  KungfuRails	
  
                      (stones.gao@gmail.com)	
  
Stone	
  Gao,	
  KungfuRails	
  
(stones.gao@gmail.com)	
  

Contenu connexe

Similaire à Active Direct

Joose - JavaScript Meta Object System
Joose - JavaScript Meta Object SystemJoose - JavaScript Meta Object System
Joose - JavaScript Meta Object Systemmalteubl
 
Joose @jsconf
Joose @jsconfJoose @jsconf
Joose @jsconfmalteubl
 
JNI - Java & C in the same project
JNI - Java & C in the same projectJNI - Java & C in the same project
JNI - Java & C in the same projectKarol Wrótniak
 
Demoiselle Spatial Latinoware 2011
Demoiselle Spatial Latinoware 2011Demoiselle Spatial Latinoware 2011
Demoiselle Spatial Latinoware 2011Rafael Soto
 
Jackson beyond JSON: XML, CSV
Jackson beyond JSON: XML, CSVJackson beyond JSON: XML, CSV
Jackson beyond JSON: XML, CSVTatu Saloranta
 
Mongoskin - Guilin
Mongoskin - GuilinMongoskin - Guilin
Mongoskin - GuilinJackson Tian
 
Supercharging reflective libraries with InvokeDynamic
Supercharging reflective libraries with InvokeDynamicSupercharging reflective libraries with InvokeDynamic
Supercharging reflective libraries with InvokeDynamicIan Robertson
 
Opa presentation at GamesJs
Opa presentation at GamesJsOpa presentation at GamesJs
Opa presentation at GamesJsHenri Binsztok
 
Developing web-apps like it's 2013
Developing web-apps like it's 2013Developing web-apps like it's 2013
Developing web-apps like it's 2013Laurent_VB
 
Ti1220 Lecture 2: Names, Bindings, and Scopes
Ti1220 Lecture 2: Names, Bindings, and ScopesTi1220 Lecture 2: Names, Bindings, and Scopes
Ti1220 Lecture 2: Names, Bindings, and ScopesEelco Visser
 
Metaprogramming Techniques In Groovy And Grails
Metaprogramming Techniques In Groovy And GrailsMetaprogramming Techniques In Groovy And Grails
Metaprogramming Techniques In Groovy And GrailszenMonkey
 
The Future of JavaScript (Ajax Exp '07)
The Future of JavaScript (Ajax Exp '07)The Future of JavaScript (Ajax Exp '07)
The Future of JavaScript (Ajax Exp '07)jeresig
 
VJET bringing the best of Java and JavaScript together
VJET bringing the best of Java and JavaScript togetherVJET bringing the best of Java and JavaScript together
VJET bringing the best of Java and JavaScript togetherJustin Early
 
RESTful Web Services with Jersey
RESTful Web Services with JerseyRESTful Web Services with Jersey
RESTful Web Services with JerseyScott Leberknight
 
Javaone 2010
Javaone 2010Javaone 2010
Javaone 2010Hien Luu
 
Why is Java relevant? New features of Java8
Why is Java relevant? New features of Java8 Why is Java relevant? New features of Java8
Why is Java relevant? New features of Java8 xshyamx
 

Similaire à Active Direct (20)

Joose - JavaScript Meta Object System
Joose - JavaScript Meta Object SystemJoose - JavaScript Meta Object System
Joose - JavaScript Meta Object System
 
Joose @jsconf
Joose @jsconfJoose @jsconf
Joose @jsconf
 
JNI - Java & C in the same project
JNI - Java & C in the same projectJNI - Java & C in the same project
JNI - Java & C in the same project
 
dojo.Patterns
dojo.Patternsdojo.Patterns
dojo.Patterns
 
Demoiselle Spatial Latinoware 2011
Demoiselle Spatial Latinoware 2011Demoiselle Spatial Latinoware 2011
Demoiselle Spatial Latinoware 2011
 
Jackson beyond JSON: XML, CSV
Jackson beyond JSON: XML, CSVJackson beyond JSON: XML, CSV
Jackson beyond JSON: XML, CSV
 
Mongoskin - Guilin
Mongoskin - GuilinMongoskin - Guilin
Mongoskin - Guilin
 
Supercharging reflective libraries with InvokeDynamic
Supercharging reflective libraries with InvokeDynamicSupercharging reflective libraries with InvokeDynamic
Supercharging reflective libraries with InvokeDynamic
 
Opa presentation at GamesJs
Opa presentation at GamesJsOpa presentation at GamesJs
Opa presentation at GamesJs
 
Developing web-apps like it's 2013
Developing web-apps like it's 2013Developing web-apps like it's 2013
Developing web-apps like it's 2013
 
Ti1220 Lecture 2: Names, Bindings, and Scopes
Ti1220 Lecture 2: Names, Bindings, and ScopesTi1220 Lecture 2: Names, Bindings, and Scopes
Ti1220 Lecture 2: Names, Bindings, and Scopes
 
Metaprogramming Techniques In Groovy And Grails
Metaprogramming Techniques In Groovy And GrailsMetaprogramming Techniques In Groovy And Grails
Metaprogramming Techniques In Groovy And Grails
 
Json generation
Json generationJson generation
Json generation
 
The Future of JavaScript (Ajax Exp '07)
The Future of JavaScript (Ajax Exp '07)The Future of JavaScript (Ajax Exp '07)
The Future of JavaScript (Ajax Exp '07)
 
VJET bringing the best of Java and JavaScript together
VJET bringing the best of Java and JavaScript togetherVJET bringing the best of Java and JavaScript together
VJET bringing the best of Java and JavaScript together
 
RESTful Web Services with Jersey
RESTful Web Services with JerseyRESTful Web Services with Jersey
RESTful Web Services with Jersey
 
Javaone 2010
Javaone 2010Javaone 2010
Javaone 2010
 
Groovy's Builder
Groovy's BuilderGroovy's Builder
Groovy's Builder
 
Why is Java relevant? New features of Java8
Why is Java relevant? New features of Java8 Why is Java relevant? New features of Java8
Why is Java relevant? New features of Java8
 
Coding Ajax
Coding AjaxCoding Ajax
Coding Ajax
 

Plus de Daniel Lv

Javascript framework and backbone
Javascript framework and backboneJavascript framework and backbone
Javascript framework and backboneDaniel Lv
 
Intridea & open source
Intridea & open sourceIntridea & open source
Intridea & open sourceDaniel Lv
 
Getting start with titanium
Getting start with titaniumGetting start with titanium
Getting start with titaniumDaniel Lv
 
Better framework, better life
Better framework, better lifeBetter framework, better life
Better framework, better lifeDaniel Lv
 
上海的Rails社区
上海的Rails社区上海的Rails社区
上海的Rails社区Daniel Lv
 
Kungfurails2009
Kungfurails2009Kungfurails2009
Kungfurails2009Daniel Lv
 
Contributing To Rails By Plugin Gem
Contributing To Rails By Plugin GemContributing To Rails By Plugin Gem
Contributing To Rails By Plugin GemDaniel Lv
 
J Ruby Kungfu Rails
J Ruby   Kungfu RailsJ Ruby   Kungfu Rails
J Ruby Kungfu RailsDaniel Lv
 
岛根县政府的挑战
岛根县政府的挑战岛根县政府的挑战
岛根县政府的挑战Daniel Lv
 

Plus de Daniel Lv (11)

Javascript framework and backbone
Javascript framework and backboneJavascript framework and backbone
Javascript framework and backbone
 
Intridea & open source
Intridea & open sourceIntridea & open source
Intridea & open source
 
Getting start with titanium
Getting start with titaniumGetting start with titanium
Getting start with titanium
 
Better framework, better life
Better framework, better lifeBetter framework, better life
Better framework, better life
 
上海的Rails社区
上海的Rails社区上海的Rails社区
上海的Rails社区
 
Kungfurails2009
Kungfurails2009Kungfurails2009
Kungfurails2009
 
Sinatra
SinatraSinatra
Sinatra
 
Contributing To Rails By Plugin Gem
Contributing To Rails By Plugin GemContributing To Rails By Plugin Gem
Contributing To Rails By Plugin Gem
 
J Ruby Kungfu Rails
J Ruby   Kungfu RailsJ Ruby   Kungfu Rails
J Ruby Kungfu Rails
 
岛根县政府的挑战
岛根县政府的挑战岛根县政府的挑战
岛根县政府的挑战
 
Why Ruby
Why RubyWhy Ruby
Why Ruby
 

Dernier

2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Accelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessAccelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessWSO2
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Karmanjay Verma
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sectoritnewsafrica
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
Kuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialKuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialJoão Esperancinha
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxAna-Maria Mihalceanu
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsYoss Cohen
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...Karmanjay Verma
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 

Dernier (20)

2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Accelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessAccelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with Platformless
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
Kuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialKuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorial
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance Toolbox
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platforms
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 

Active Direct

  • 1. Talk  Directly  with  Ac#veRecord     using  Ext.Direct  and  Rack  Middleware   Stone  Gao,  Ekohe   Stone  Gao,  KungfuRails   (stones.gao@gmail.com)  
  • 2. Outline   •  Intro  to  Ext  Js   •  The  Problem   •  The  SoluDon  :  Ext.Direct     •  Intro  to  Rack  Middleware   •  Ac#veDirect  (an  Experimental  ImplementaDon   of  Ext.Direct,  yet  )   •  What  can  you  do  with  Ac#veDirect  (Examples)   •  Q  &  A   Stone  Gao,  KungfuRails   (stones.gao@gmail.com)  
  • 3. Intro  to  Ext  Js   Ext  JS  is  a  cross-­‐browser  JavaScript  library  for  building  rich   internet  applicaDons.   •  igh  performance,  customizable  UI  widgets,  Ajax   H • ntuiDve,  easy  to  use  API   I                                                                                                                                                (hTp://www.extjs.com)     Stone  Gao,  KungfuRails   (stones.gao@gmail.com)  
  • 4. The  Problem   Stone  Gao,  KungfuRails   (stones.gao@gmail.com)  
  • 5. Ajax  Calls   Foo.js   …….   Ext.Ajax.request({   Bar.js                      url:  ("/foo?format=json"),   ……   Baz.js                      method:  "POST",                      jsonData:    payLoad,   ……   Ext.Ajax.request({                      success:  this..success,                      url:  (”/bar?format=json"),                      failure:  this.failure,   Ext.Ajax.request({                      method:  ”GET",                      headers:  {                      jsonData:    payLoad,                      url:  (”/baz?format=json"),                          'accepts':  'applicaDon/json'                      success:  this..success,                      method:  "POST",                      },                      failure:  this.failure,                      jsonData:    payLoad,                      scope  :  this                      headers:  {                      success:  this..success,                  });                      failure:  this.failure,                          'accepts':  'applicaDon/json'                      },                      headers:  {   ……                      scope  :  this                          'accepts':  'applicaDon/json'                  });                      },                      scope  :  this   ……                  });   ……   Stone  Gao,  KungfuRails   (stones.gao@gmail.com)  
  • 6. Ajax  Calls   Foo.js   …….   Ext.Ajax.request({   Bar.js                      url:  ("/foo?format=json"),   ……   Baz.js                      method:  "POST",                      jsonData:    payLoad,   ……   Ext.Ajax.request({                      success:  this..success,                      url:  (”/bar?format=json"),                      failure:  this.failure,   Ext.Ajax.request({                      method:  ”GET",                      headers:  {                      jsonData:    payLoad,                      url:  (”/baz?format=json"),                          'accepts':  'applicaDon/json'                      success:  this..success,                      method:  "POST",                      },                      failure:  this.failure,                      jsonData:    payLoad,                      scope  :  this                      headers:  {                      success:  this..success,                  });                      failure:  this.failure,                          'accepts':  'applicaDon/json'                      },                      headers:  {   ……                      scope  :  this                          'accepts':  'applicaDon/json'                  });                      },                      scope  :  this   ……                  });   ……   Stone  Gao,  KungfuRails   (stones.gao@gmail.com)  
  • 7. The  SoluDon   Stone  Gao,  KungfuRails   (stones.gao@gmail.com)  
  • 8. The  SoluDon   Ext.Direct   Ext.Direct  is  a  pladorm  and  language  agnosDc  technology  to   remote  server-­‐side  methods  to  the  client-­‐side.  Furthermore,   Ext.Direct  allows  for  seamless  communicaDon  between  the   client-­‐side  of  an  Ext  applicaDon  and  any  server-­‐side  pladorm.   (hTp://www.extjs.com/products/extjs/direct.php)     You  can  write  the  following  code  in  javascript  :     App.models.Category.foo()   App.models.Category.bar()   App.models.Category.create(  {  name  :  ‘ruby’  }    )   App.models.Category.update(  1,  {  name  :  ‘ruby’  }    )   App.models.Category.delete(1)   Stone  Gao,  KungfuRails   (stones.gao@gmail.com)  
  • 9. Intro  to  Rack  Middleware     Middleware   App   HTTP  Request   HTTP   Client   log   auth   cache   (browser)   HTTP  Response   Stone  Gao,  KungfuRails   (stones.gao@gmail.com)  
  • 10. Intro  to  Rack  Middleware     >>    ps  aux  |  grep  ruby  |  wc  –l   3   Rack  Middleware  is  Pipeline  for  HTTP  Req  Processing!     Middleware   App   The  Unix  Philosophy  :     HTTP  Request   Rack  Middleware  is     Chainable   HTTP   and   Client   (browser)   HTTP  Response   log   auth   cache   Composable  like  Unix  Pipelines                     Stone  Gao,  KungfuRails   (stones.gao@gmail.com)  
  • 11. Intro  to  Rack  Middleware     Conven#on  :  app.call(env)   lambda  {  |env|                                                                                #Rack  Environment  variables        [    200,                                                                                                            #Status  Code              {‘Content-­‐Type’  =>  ‘text/plain’},            #Headers                [‘Hello  World!’]                                                                    #Reponse  Body                                                        ]   }     Stone  Gao,  KungfuRails   (stones.gao@gmail.com)  
  • 12. Ac#veDirect  (an  Experimental  ImplementaDon  of  Ext.Direct,  yet  )   Talk  Directly  with  Ac#veRecord  using  Ext.Direct  and  Rack  Middleware   Stone  Gao,  KungfuRails   (stones.gao@gmail.com)  
  • 13. Ac#veDirect  (an  Experimental  ImplementaDon  of  Ext.Direct,  yet  )   Talk  Directly  with  Ac#veRecord  using  Ext.Direct  and  Rack  Middleware   Method   Dispatching   AcDveDirect::Router   Ext.Direct     AcDveDirect::Api   Server-­‐side   App   methods  configs   Rack  Middleware   Stone  Gao,  KungfuRails   (stones.gao@gmail.com)  
  • 14. Ac#veDirect  (an  Experimental  ImplementaDon  of  Ext.Direct,  yet  )   How  Ac#veDirect::Api  works     App.REMOTING_API  =  {          "ac#ons":  {                  "Category":  [                          {                                  "name":  "all",                                  "len":  1   GET  /direct_api                          },                          {                                  "name":  "update_all",                                  "len":  2                          }                  ]          },          "namespace":  "App.models",          "url":  "/direct_router",          "type":  "remo#ng"   };   Stone  Gao,  KungfuRails   (stones.gao@gmail.com)  
  • 15. Ac#veDirect  (an  Experimental  ImplementaDon  of  Ext.Direct,  yet  )   How  Ac#veDirect::Router  works   App.models.Category.all()   POST  /direct_router          {"ac#on":"Category","method":"all","data":[],"type":"rpc","#d":3}   Ac#veDirect::Router   Category.send  :all   Stone  Gao,  KungfuRails   (stones.gao@gmail.com)  
  • 16. Ac#veDirect  -­‐  ConfiguraDon   •  Middleware  configuraDons  (environment.rb)            config.middleware.use  'Ac#veDirect::Router',  '/direct_router'            config.middleware.use  'Ac#veDirect::Api',  '/direct_api',  '/direct_router’   •  Method  configuraDons                <script  type="text/javascript"  src=”/javascripts/ext/adapter/ext/ext-­‐base.js"></script>              <script  type=“text/javascript”  src=”/javascripts/ext/ext-­‐all-­‐debug.js"></script>              <script  type=“text/javascript”  src=”/direct_api"></script>              Ext.Direct.addProvider(App.REMOTING_API);   Stone  Gao,  KungfuRails   (stones.gao@gmail.com)  
  • 17. Ac#veDirect  -­‐  ConfiguraDon   •  Model  configuraDons     class  Category  <  AcDveRecord::Base          acts_as_nested_set          has_many  :books          acts_as_direct    :root_nodes  =>  0,  :create_new_cat  =>  {:len  =>  1,  :formHandler  =>  true}          def  root_nodes                    ……          end            def  create_new_cat(params)     Custom  remotable                    ……   methods          end   end     Stone  Gao,  KungfuRails   (stones.gao@gmail.com)  
  • 18. What  can  you  do  with  Ac#veDirect       CRUD  Default  Remotable  Methods   Custom  Remotable  Methods   Stone  Gao,  KungfuRails   (stones.gao@gmail.com)  
  • 19. What  can  you  do  with  Ac#veDirect  (examples)       App.models.Category.create(  {  name  :  ‘ruby’  }    )   Stone  Gao,  KungfuRails   (stones.gao@gmail.com)  
  • 20. What  can  you  do  with  Ac#veDirect  (examples)       App.models.Category.update(2,    {  name  :  ‘ruby  books’  }  )   Stone  Gao,  KungfuRails   (stones.gao@gmail.com)  
  • 21. What  can  you  do  with  Ac#veDirect  (examples)     App.models.Category.update_all({  name  :  ‘ruby  books’  },    “  name  LIKE  ‘%ruby%’  ”  )   Stone  Gao,  KungfuRails   (stones.gao@gmail.com)  
  • 22. What  can  you  do  with  Ac#veDirect  (examples)     App.models.Category.all()   Stone  Gao,  KungfuRails   (stones.gao@gmail.com)  
  • 23. What  can  you  do  with  Ac#veDirect  (examples)     App.models.Category.find(  2  )   Stone  Gao,  KungfuRails   (stones.gao@gmail.com)  
  • 24. What  can  you  do  with  Ac#veDirect  (examples)     App.models.Category.find_every(  {  condi#ons  :  “name  LIKE  ‘%java%’  “  }  )   Stone  Gao,  KungfuRails   (stones.gao@gmail.com)  
  • 25. What  can  you  do  with  Ac#veDirect  (examples)     App.models.Category.exists(  [“  name  LIKE  ?  “,    ‘%java%’  ]  )   Stone  Gao,  KungfuRails   (stones.gao@gmail.com)  
  • 26. What  can  you  do  with  Ac#veDirect  (examples)     Stone  Gao,  KungfuRails   (stones.gao@gmail.com)  
  • 27. What  can  you  do  with  Ac#veDirect  (examples)     App.models.Category.count()   Stone  Gao,  KungfuRails   (stones.gao@gmail.com)  
  • 28. What  can  you  do  with  Ac#veDirect  (examples)     App.models.Category.delete(  2  )   App.models.Category.delete_all(  “  name  LIKE    ‘%java%’    “    )   Stone  Gao,  KungfuRails   (stones.gao@gmail.com)  
  • 29. Wait,  Where  is  My  Controllers  ?!!   For  Ext  Js  Applica#ons,  you  don’t  necessarily  have  tradi#onal  Controllers     You  front  end  control  logics  is  the  Controllers  and  Ext  Widgets  is  the  Views   You  can  call  your  Model  methods  directly  using  Ext.Direct    and  Ac#veDirect   Stone  Gao,  KungfuRails   (stones.gao@gmail.com)  
  • 30. Let’s  Collaborate  to  Improve  it       hTp://github.com/stonegao/acDve-­‐direct   (It’s  my  first  library    )   Stone  Gao,  KungfuRails   (stones.gao@gmail.com)  
  • 31. Stone  Gao,  KungfuRails   (stones.gao@gmail.com)