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

Firefox Marketplace Frontend

jos
May 05, 2016

Firefox Marketplace Frontend

Talk about Firefox Marketplace frontend architecture and the good parts.

jos

May 05, 2016
Tweet

More Decks by jos

Other Decks in Technology

Transcript

  1. FRONTEND 3 FIREPLACE - 2013 - jQuery, Underscore - RequireJS

    (AMD) - Nunjucks - Stylus - Makefile + Gulp
  2. USAGE INSTALLATION 4 git clone [email protected]:mozilla/marketplace-template.git npm install make install

    DEVELOP make serve make build MKT_PORT=8000 make serve MKT_COMPILED=1 make build
  3. FRAMEWORK GOALS: PERFORMANCE 5 - Everything client-side for less requests

    - RESTful APIs for everything - Always show something to the user - Cache as much as possible - Modular components and resuable code
  4. FRAMEWORK 6 EVERYTHING CLIENT-SIDE 1. Data is requested from the

    API 2. The client receives the data 3. The client renders the page with the data 4. The client stores the data in its request cache
  5. FRAMEWORK FETCHING AND RENDERING DATA - Defer Blocks 7 CACHING

    1. Request Cache - Key-value store keyed by URL 2. Model Cache - Store specific object individually
  6. PAGE BUILDING ROUTING 8 define('routes', ['core/router' ], function(router) { router.addRoutes([

    {pattern: '^/$', view_name: 'hello_world' } ]); router.api.addRoutes({ 'hello-names' : '/api/v2/hello/names/' }); // Processors to set query arguments on API requests. // router.api.addProcessor(function(endpoint) { // return {something: 'to-be-in-the-query'}; // }); });
  7. PAGE BUILDING VIEWS 9 define('views/hello_world', ['l10n', 'z'], function(l10n, z) {

    // -- MODULE LEVEL --. var gettext = l10n.gettext; z.page.on('click', 'button', function() { console.log('Put your delegated event handlers on this level.'); }); return function(builder) { // -- BUILDER LEVEL --. builder.z('title', gettext('My View Page Title')); builder.z('type', 'leaf'); builder.start('hello_world.html', { someContextVar: true }); }; });
  8. PAGE BUILDING DEFER BLOCKS 10 {% defer (url=api('hello-names')) %} I

    just loaded {{ this.name }} from the `hello -names` endpoint. {% end %}
  9. PAGE BUILDING DEFER BLOCKS - MODEL CACHE 11 {% defer

    (url=api('hello-names'), as='names', key='id') %} I just loaded {{ this.name }} from the `hello -names` endpoint. {% end %}
  10. PAGE BUILDING DEFER BLOCKS - PLACEHOLDER 12 {% defer (url=api('hello-names'))

    %} I just loaded {{ this.name }} from the `hello -names` endpoint. {% placeholder %} This is what you see while the API is working away. {% end %}
  11. PAGE BUILDING DEFER BLOCKS - EXCEPT 13 {% defer (url=api('hello-names'))

    %} I just loaded {{ this.name }} from the `hello -names` endpoint. {% except %} {% if error == 404 %} Not found {% elif error == 403 %} Not allowed {% else %} Error {% endif %} {% end %}
  12. PAGE BUILDING DEFER BLOCKS - EMPTY 14 {% defer (url=api('hello-names'))

    %} <ul> {% for result in this %} <li>I just loaded {{ result.name }}.</li> {% endfor %} </ul> {% empty %} <div class="empty">Nothing was loaded. </div> {% end %}
  13. PAGE BUILDING DEFER BLOCKS - PAGINATION 15 {% defer (url=api('hello-names'),

    paginate='ul.list') %} <ul class="list"> {% for result in this %} <li>I just loaded {{ result.name }}.</li> {% endfor %} </ul> <div class="load_more"> <button data-url="{{ api('this.meta.next_page') }}" >Load More</button> </div> {% end %}
  14. CONCLUSION PROS - Defer Blocks - Cache - Deploy 16

    CONS - Defer Blocks - Suitable for readonly website - Building Tools