SlideShare uma empresa Scribd logo
1 de 11
Dependency Injection (DI)
           Model View ViewModel (MVVM)
                        AMD Build Scripts
               Unit Testing AMD Modules

4/1/2013                                    1
     Break Js into independent modules
        Single Responsibility Principle (SRP)
        Each Js file is a Module
        Modules loaded Asynchronously, only as
           needed
     Control and limit the Global scope
        Each module has its own scope inside its
         own function
        Module’s only access to the outside world is
         through its Dependencies


4/1/2013                                                2
     How to bootstrap an AMD page
        Main module file roots all module paths*
        Require will figure out how to sequence
           dependencies
     How to reference one module from another
        Use the path relative to the main Js module*
        Don’t use .js extension
     Aliasing modules via config
        Place for libs to get named
        Alias eases integration concerns for versioned
           libs*

4/1/2013                                                  3
     require()
        require(moduleName, callback(module));*
        this dynamically loads a module
     define()
        define(dependencyList, callback(dependencies));
        this defines a module
        dependencyList is an array of paths of other
         dependent modules
        Callback receives dependency references as
         parameters in the same order defined in the list*
        From callback(), return an object or function or
         nothing – this is the module “API” or Interface*
        Module’s body function is only executed once


4/1/2013                                                     4
     Dependencies are injected into Module’s
      function as parameters
        Same order they were listed
           define(dependencyList, callback(dependencies));


     dependencyList is just an Array of string
        Each dependency in list will be loaded, but
         doesn’t necessarily need to be
         used/referenced
        Paths are relative to main Js file referenced
         by the Html

4/1/2013                                                     5
     Js-Private
        Variables & Functions inside a Module’s function
         body that are not part of the returned interface*
        Feel free to name things whatever! It won’t
         overwrite the Global scope*
     Js-Public/Interface
        Variables & Functions that are part of the
           Module callback’s returned structure*
     Module’s return type can be:
        Object – static instance shared by all*
        Function – constructor or other functionality*
        Nothing – module has no Public API*


4/1/2013                                                     6
 Familiar Mocking concept
 Stub out a module’s dependencies*
 Jasmine Unit Testing Framework is
  demonstrated*




4/1/2013                              7
     Module is a “ViewModel” that is bound to the UI with
      Knockout*
     Properties of the ViewModel have 2 way binding to
      elements on the page
        ViewModel properties correspond to View’d UI constructs*
        Use a Knockout binding handler to do processing at bind-
           time*
     Page events are bound to ViewModel functions
        ViewModel functions correspond to UI actions or events*
     Subelements can be bound, just like a User Control
        ViewModel can be composed with other ViewModels*
        Using Knockout’s template binding or with binding to re-
           use View code and specify a binding context*



4/1/2013                                                            8
 r.js, a part of Require.js, uses NodeJs to
  run as a command-line-app
 Input file: JSON commands for compiler*
 Builds demonstrated:
        Build a whole site’s Html and Css
        Build all site Js into one combined Js
        Build all site Js into one combined and minified
         Js
        Droid build – defines a variable as part of the
         build

4/1/2013                                                    9
     SmartJs
        https://github.com/hughanderson4/smartjs
     RequireJs
        http://requirejs.org/
     RequireJs optimizer (r.js)
        http://requirejs.org/docs/optimization.html
     jQuery Mobile
        http://jquerymobile.com/
     Jasmine
        http://pivotal.github.com/jasmine/


4/1/2013                                               10
Conclusion: AMD is awesome




4/1/2013                         11

Mais conteúdo relacionado

Mais procurados

CommonJS Everywhere (Wakanday 2011)
CommonJS Everywhere (Wakanday 2011)CommonJS Everywhere (Wakanday 2011)
CommonJS Everywhere (Wakanday 2011)cadorn
 
Introduction to require js
Introduction to require jsIntroduction to require js
Introduction to require jsAhmed Elharouny
 
Require JS
Require JSRequire JS
Require JSImaginea
 
AngularJS - Architecture decisions in a large project 
AngularJS - Architecture decisionsin a large project AngularJS - Architecture decisionsin a large project 
AngularJS - Architecture decisions in a large project Elad Hirsch
 
Javascript ui for rest services
Javascript ui for rest servicesJavascript ui for rest services
Javascript ui for rest servicesIoan Eugen Stan
 
uRequire@greecejs: An introduction to http://uRequire.org
uRequire@greecejs: An introduction to http://uRequire.orguRequire@greecejs: An introduction to http://uRequire.org
uRequire@greecejs: An introduction to http://uRequire.orgAgelos Pikoulas
 
Workshop 2: JavaScript Design Patterns
Workshop 2: JavaScript Design PatternsWorkshop 2: JavaScript Design Patterns
Workshop 2: JavaScript Design PatternsVisual Engineering
 
Angularjs architecture
Angularjs architectureAngularjs architecture
Angularjs architectureMichael He
 
Design & Development of Web Applications using SpringMVC
Design & Development of Web Applications using SpringMVC Design & Development of Web Applications using SpringMVC
Design & Development of Web Applications using SpringMVC Naresh Chintalcheru
 
Modern Web Application Development Workflow - EclipseCon Europe 2014
Modern Web Application Development Workflow - EclipseCon Europe 2014Modern Web Application Development Workflow - EclipseCon Europe 2014
Modern Web Application Development Workflow - EclipseCon Europe 2014Stéphane Bégaudeau
 
Karlsruher Entwicklertag 2013 - Webanwendungen mit AngularJS
Karlsruher Entwicklertag 2013 - Webanwendungen mit AngularJSKarlsruher Entwicklertag 2013 - Webanwendungen mit AngularJS
Karlsruher Entwicklertag 2013 - Webanwendungen mit AngularJSPhilipp Burgmer
 
Using RequireJS for Modular JavaScript Code
Using RequireJS for Modular JavaScript CodeUsing RequireJS for Modular JavaScript Code
Using RequireJS for Modular JavaScript CodeThomas Lundström
 
AngularJS with RequireJS
AngularJS with RequireJSAngularJS with RequireJS
AngularJS with RequireJSJohannes Weber
 
Integrating Browserify with Sprockets
Integrating Browserify with SprocketsIntegrating Browserify with Sprockets
Integrating Browserify with SprocketsSpike Brehm
 
Spring framework 3.2 > 4.0 — themes and trends
Spring framework 3.2 > 4.0 — themes and trendsSpring framework 3.2 > 4.0 — themes and trends
Spring framework 3.2 > 4.0 — themes and trendsArawn Park
 
Workshop Intro: FrontEnd General Overview
Workshop Intro: FrontEnd General OverviewWorkshop Intro: FrontEnd General Overview
Workshop Intro: FrontEnd General OverviewVisual Engineering
 
Jsp (java server page)
Jsp (java server page)Jsp (java server page)
Jsp (java server page)Chitrank Dixit
 

Mais procurados (20)

CommonJS Everywhere (Wakanday 2011)
CommonJS Everywhere (Wakanday 2011)CommonJS Everywhere (Wakanday 2011)
CommonJS Everywhere (Wakanday 2011)
 
Require js
Require jsRequire js
Require js
 
Browserify
BrowserifyBrowserify
Browserify
 
Introduction to require js
Introduction to require jsIntroduction to require js
Introduction to require js
 
Require JS
Require JSRequire JS
Require JS
 
AngularJS - Architecture decisions in a large project 
AngularJS - Architecture decisionsin a large project AngularJS - Architecture decisionsin a large project 
AngularJS - Architecture decisions in a large project 
 
Javascript ui for rest services
Javascript ui for rest servicesJavascript ui for rest services
Javascript ui for rest services
 
uRequire@greecejs: An introduction to http://uRequire.org
uRequire@greecejs: An introduction to http://uRequire.orguRequire@greecejs: An introduction to http://uRequire.org
uRequire@greecejs: An introduction to http://uRequire.org
 
Workshop 2: JavaScript Design Patterns
Workshop 2: JavaScript Design PatternsWorkshop 2: JavaScript Design Patterns
Workshop 2: JavaScript Design Patterns
 
Angularjs architecture
Angularjs architectureAngularjs architecture
Angularjs architecture
 
Design & Development of Web Applications using SpringMVC
Design & Development of Web Applications using SpringMVC Design & Development of Web Applications using SpringMVC
Design & Development of Web Applications using SpringMVC
 
Modern Web Application Development Workflow - EclipseCon Europe 2014
Modern Web Application Development Workflow - EclipseCon Europe 2014Modern Web Application Development Workflow - EclipseCon Europe 2014
Modern Web Application Development Workflow - EclipseCon Europe 2014
 
Karlsruher Entwicklertag 2013 - Webanwendungen mit AngularJS
Karlsruher Entwicklertag 2013 - Webanwendungen mit AngularJSKarlsruher Entwicklertag 2013 - Webanwendungen mit AngularJS
Karlsruher Entwicklertag 2013 - Webanwendungen mit AngularJS
 
Using RequireJS for Modular JavaScript Code
Using RequireJS for Modular JavaScript CodeUsing RequireJS for Modular JavaScript Code
Using RequireJS for Modular JavaScript Code
 
AngularJS with RequireJS
AngularJS with RequireJSAngularJS with RequireJS
AngularJS with RequireJS
 
Integrating Browserify with Sprockets
Integrating Browserify with SprocketsIntegrating Browserify with Sprockets
Integrating Browserify with Sprockets
 
Spring framework 3.2 > 4.0 — themes and trends
Spring framework 3.2 > 4.0 — themes and trendsSpring framework 3.2 > 4.0 — themes and trends
Spring framework 3.2 > 4.0 — themes and trends
 
Workshop Intro: FrontEnd General Overview
Workshop Intro: FrontEnd General OverviewWorkshop Intro: FrontEnd General Overview
Workshop Intro: FrontEnd General Overview
 
Jsp (java server page)
Jsp (java server page)Jsp (java server page)
Jsp (java server page)
 
Zend framework 02 - mvc
Zend framework 02 - mvcZend framework 02 - mvc
Zend framework 02 - mvc
 

Semelhante a Asynchronous Module Definition (AMD) used for Dependency Injection (DI) and MVVM

Modules all the way down: OSGi and the Java Platform Module System
Modules all the way down: OSGi and the Java Platform Module SystemModules all the way down: OSGi and the Java Platform Module System
Modules all the way down: OSGi and the Java Platform Module SystemTim Ellison
 
Spring core module
Spring core moduleSpring core module
Spring core moduleRaj Tomar
 
As7 jbug j_boss_modules_yang yong
As7 jbug j_boss_modules_yang yongAs7 jbug j_boss_modules_yang yong
As7 jbug j_boss_modules_yang yongjbossug
 
Java 9 Module System
Java 9 Module SystemJava 9 Module System
Java 9 Module SystemHasan Ünal
 
Backbone beyond jQuery
Backbone beyond jQueryBackbone beyond jQuery
Backbone beyond jQueryAdam Krebs
 
Spring Architecture | Advanced Java
Spring Architecture | Advanced JavaSpring Architecture | Advanced Java
Spring Architecture | Advanced JavaVISHAL DONGA
 
Scalable JavaScript Application Architecture 2012
Scalable JavaScript Application Architecture 2012Scalable JavaScript Application Architecture 2012
Scalable JavaScript Application Architecture 2012Nicholas Zakas
 
Hints and Tips for Modularizing Existing Enterprise Applications with OSGi - ...
Hints and Tips for Modularizing Existing Enterprise Applications with OSGi - ...Hints and Tips for Modularizing Existing Enterprise Applications with OSGi - ...
Hints and Tips for Modularizing Existing Enterprise Applications with OSGi - ...mfrancis
 
Hints and Tips for Modularizing Existing Enterprise Applications (OSGi Commun...
Hints and Tips for Modularizing Existing Enterprise Applications (OSGi Commun...Hints and Tips for Modularizing Existing Enterprise Applications (OSGi Commun...
Hints and Tips for Modularizing Existing Enterprise Applications (OSGi Commun...Graham Charters
 
Java modulesystem
Java modulesystemJava modulesystem
Java modulesystemMarc Kassis
 
Introduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoCIntroduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoCFunnelll
 
OSGi in Action Chapter 1 and 2
OSGi in Action Chapter 1 and 2OSGi in Action Chapter 1 and 2
OSGi in Action Chapter 1 and 2pjhInovex
 
스프링 프레임워크
스프링 프레임워크스프링 프레임워크
스프링 프레임워크Yoonki Chang
 

Semelhante a Asynchronous Module Definition (AMD) used for Dependency Injection (DI) and MVVM (20)

Modules all the way down: OSGi and the Java Platform Module System
Modules all the way down: OSGi and the Java Platform Module SystemModules all the way down: OSGi and the Java Platform Module System
Modules all the way down: OSGi and the Java Platform Module System
 
Spring core module
Spring core moduleSpring core module
Spring core module
 
As7 jbug j_boss_modules_yang yong
As7 jbug j_boss_modules_yang yongAs7 jbug j_boss_modules_yang yong
As7 jbug j_boss_modules_yang yong
 
Require.JS
Require.JSRequire.JS
Require.JS
 
Java 9 Module System
Java 9 Module SystemJava 9 Module System
Java 9 Module System
 
Backbone beyond jQuery
Backbone beyond jQueryBackbone beyond jQuery
Backbone beyond jQuery
 
Spring Architecture | Advanced Java
Spring Architecture | Advanced JavaSpring Architecture | Advanced Java
Spring Architecture | Advanced Java
 
JavaScript Module Loaders
JavaScript Module LoadersJavaScript Module Loaders
JavaScript Module Loaders
 
Scalable JavaScript Application Architecture 2012
Scalable JavaScript Application Architecture 2012Scalable JavaScript Application Architecture 2012
Scalable JavaScript Application Architecture 2012
 
Hints and Tips for Modularizing Existing Enterprise Applications with OSGi - ...
Hints and Tips for Modularizing Existing Enterprise Applications with OSGi - ...Hints and Tips for Modularizing Existing Enterprise Applications with OSGi - ...
Hints and Tips for Modularizing Existing Enterprise Applications with OSGi - ...
 
Java modularization
Java modularizationJava modularization
Java modularization
 
Java8 - Under the hood
Java8 - Under the hoodJava8 - Under the hood
Java8 - Under the hood
 
NodeJs Modules1.pdf
NodeJs Modules1.pdfNodeJs Modules1.pdf
NodeJs Modules1.pdf
 
Hints and Tips for Modularizing Existing Enterprise Applications (OSGi Commun...
Hints and Tips for Modularizing Existing Enterprise Applications (OSGi Commun...Hints and Tips for Modularizing Existing Enterprise Applications (OSGi Commun...
Hints and Tips for Modularizing Existing Enterprise Applications (OSGi Commun...
 
Java modulesystem
Java modulesystemJava modulesystem
Java modulesystem
 
Introduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoCIntroduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoC
 
OSGi in Action Chapter 1 and 2
OSGi in Action Chapter 1 and 2OSGi in Action Chapter 1 and 2
OSGi in Action Chapter 1 and 2
 
Java9
Java9Java9
Java9
 
스프링 프레임워크
스프링 프레임워크스프링 프레임워크
스프링 프레임워크
 
Spring notes
Spring notesSpring notes
Spring notes
 

Último

Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 

Último (20)

Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 

Asynchronous Module Definition (AMD) used for Dependency Injection (DI) and MVVM

  • 1. Dependency Injection (DI) Model View ViewModel (MVVM) AMD Build Scripts Unit Testing AMD Modules 4/1/2013 1
  • 2. Break Js into independent modules  Single Responsibility Principle (SRP)  Each Js file is a Module  Modules loaded Asynchronously, only as needed  Control and limit the Global scope  Each module has its own scope inside its own function  Module’s only access to the outside world is through its Dependencies 4/1/2013 2
  • 3. How to bootstrap an AMD page  Main module file roots all module paths*  Require will figure out how to sequence dependencies  How to reference one module from another  Use the path relative to the main Js module*  Don’t use .js extension  Aliasing modules via config  Place for libs to get named  Alias eases integration concerns for versioned libs* 4/1/2013 3
  • 4. require()  require(moduleName, callback(module));*  this dynamically loads a module  define()  define(dependencyList, callback(dependencies));  this defines a module  dependencyList is an array of paths of other dependent modules  Callback receives dependency references as parameters in the same order defined in the list*  From callback(), return an object or function or nothing – this is the module “API” or Interface*  Module’s body function is only executed once 4/1/2013 4
  • 5. Dependencies are injected into Module’s function as parameters  Same order they were listed define(dependencyList, callback(dependencies));  dependencyList is just an Array of string  Each dependency in list will be loaded, but doesn’t necessarily need to be used/referenced  Paths are relative to main Js file referenced by the Html 4/1/2013 5
  • 6. Js-Private  Variables & Functions inside a Module’s function body that are not part of the returned interface*  Feel free to name things whatever! It won’t overwrite the Global scope*  Js-Public/Interface  Variables & Functions that are part of the Module callback’s returned structure*  Module’s return type can be:  Object – static instance shared by all*  Function – constructor or other functionality*  Nothing – module has no Public API* 4/1/2013 6
  • 7.  Familiar Mocking concept  Stub out a module’s dependencies*  Jasmine Unit Testing Framework is demonstrated* 4/1/2013 7
  • 8. Module is a “ViewModel” that is bound to the UI with Knockout*  Properties of the ViewModel have 2 way binding to elements on the page  ViewModel properties correspond to View’d UI constructs*  Use a Knockout binding handler to do processing at bind- time*  Page events are bound to ViewModel functions  ViewModel functions correspond to UI actions or events*  Subelements can be bound, just like a User Control  ViewModel can be composed with other ViewModels*  Using Knockout’s template binding or with binding to re- use View code and specify a binding context* 4/1/2013 8
  • 9.  r.js, a part of Require.js, uses NodeJs to run as a command-line-app  Input file: JSON commands for compiler*  Builds demonstrated:  Build a whole site’s Html and Css  Build all site Js into one combined Js  Build all site Js into one combined and minified Js  Droid build – defines a variable as part of the build 4/1/2013 9
  • 10. SmartJs  https://github.com/hughanderson4/smartjs  RequireJs  http://requirejs.org/  RequireJs optimizer (r.js)  http://requirejs.org/docs/optimization.html  jQuery Mobile  http://jquerymobile.com/  Jasmine  http://pivotal.github.com/jasmine/ 4/1/2013 10
  • 11. Conclusion: AMD is awesome 4/1/2013 11