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

Lessons learnt building a mobile web app

Emma
November 29, 2012

Lessons learnt building a mobile web app

non mvc-framework architecture, layers of test and use of promises to build a robust app fully tested

Emma

November 29, 2012
Tweet

More Decks by Emma

Other Decks in Programming

Transcript

  1. jQuery mobile <div data-role="page"> <div data-role="content"> <ul data-role="listview"> </ul> </div>

    </div> $.mobile.showPageLoadingMsg(); $.mobile.hidePageLoadingMsg(); $.mobile.changePage('pageId'); Markup Javascript API
  2. +-----------+ | | +---------------------+ +------------+ | | | CONTROLLER |

    | | | | |---------------------| | | | | | | | | | UI |<------------+ | | | | | | | +--------------> SERVER | | | | | | | | | | +--------+ | | | | | | | +-------+-------------+ | | | +-----------+ | | | | | | | | +------------+ +-------+ | | | | | +--------v---------+ +-------v-------------+ +----------+----------+ | HELPER | | DOMAIN | | SERVICE | |------------------| |---------------------| |---------------------| | | | | | | | | | +--------> | | | | <--------+ | | | | | | | +------------------+ +---------------------+ +---------------------+ Diagram
  3. Controller  Attached to UI  Communicates with Domain 

    Has usually only one method public: init  Can use helpers for building markup Handlebars.js, domo.js  Can use helpers for encapsulating phonegap api Ie: camera api
  4. Domain  Logic of our app  Several public testable

    methods  Can have state  Will delegate to services for async calls to server  Will work with promises
  5. Service  Several public testable methods  1 to 1

    to server endpoint  Will work with promises
  6. Promises provide a well-defined interface for interacting with an object

    that represents the result of an action that is performed asynchronously,and may or may not be finished at any given point in time. Proposals  Promise/A  Promise/B  Promise/D http://wiki.commonjs.org/wiki/Promises Implementations  Jquery (Deferred)  Q  Promise.js  ...
  7. step1(function (value1) { step2(value1, function(value2) { step3(value2, function(value3) { step4(value3,

    function(value4) { // Do something with value4 }); }); }); }); return step1(initialVal).then(step2).then(step3).then(step4); Pyramid of Doom Promises
  8. +-----------+ | | +---------------------+ +------------+ | | | CONTROLLER |

    | | | | |---------------------| | | | | | | | | | UI |<------------+ | | | | | | | +--------------> SERVER | | | | | | | | | | +--------+ | | | | | | | +-------+-------------+ | | | +-----------+ | | | | | | | | +------------+ +-------+ | | | | | +--------v---------+ +-------v-------------+ +----------+----------+ | HELPER | | DOMAIN | | SERVICE | |------------------| |---------------------| |---------------------| | | | | | | | | | +--------> | | | | <--------+ | | | | | | | +------------------+ +---------------------+ +---------------------+ Diagram
  9. Debugging  It's almost not needed  But suddenly something

    works wrong in a device  Weinre to the rescue! Which I learnt here, by the way, thanks!
  10. Technical conclusions  Promises are cool, but might be hard

    to test in your stack  An pure MVC framework is not needed to have your code under control  Try to use only one stack (sometimes it is not possible)
  11. Conclusions  A mobile app can be fully tested...in browser

     Enough for testing what the app does  Don't feel safe, devices (can) behave different  Does not tell you if you're building the right thing