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

Ladda JS Caching Library @ BerlinJS, 2017/04/20

Ladda JS Caching Library @ BerlinJS, 2017/04/20

Presentation about the JS caching library Ladda (https://github.com/ladda-js/ladda) at the BerlinJS Meetup (http://berlinjs.org/) by Peter Crona (https://github.com/petercrona) and Gernot Hoeflechner (https://github.com/LFDM)

Gernot Höflechner

April 20, 2017
Tweet

Transcript

  1. if (!inCache(...)) { saveInCache(...); } return fromCache(...); if (!inCache(...)) {

    saveInCache(...); } return fromCache(...); if (!inCache(...)) { saveInCache(...); } return fromCache(...); if (!inCache(...)) { saveInCache(...); } return fromCache(...); if (!inCache(...)) { saveInCache(...); } return fromCache(...); if (!inCache(...)) { saveInCache(...); } return fromCache(...); if (!inCache(...)) { saveInCache(...); } return fromCache(...); if (!inCache(...)) { saveInCache(...); } return fromCache(...); if (!inCache(...)) { saveInCache(...); } return fromCache(...); if (!inCache(...)) { saveInCache(...); } return fromCache(...); if (!inCache(...)) { saveInCache(...); } return fromCache(...); A Naive Solution
  2. if (!inCache(...)) { saveInCache(...); } return fromCache(...); if (!inCache(...)) {

    saveInCache(...); } return fromCache(...); if (!inCache(...)) { saveInCache(...); } return fromCache(...); if (!inCache(...)) { saveInCache(...); } return fromCache(...); if (!inCache(...)) { saveInCache(...); } return fromCache(...); if (!inCache(...)) { saveInCache(...); } return fromCache(...); if (!inCache(...)) { saveInCache(...); } return fromCache(...); if (!inCache(...)) { saveInCache(...); } return fromCache(...); if (!inCache(...)) { saveInCache(...); } return fromCache(...); if (!inCache(...)) { saveInCache(...); } return fromCache(...); if (!inCache(...)) { saveInCache(...); } return fromCache(...); Increases application complexity! A Naive Solution
  3. if (!inCache(...)) { saveInCache(...); } return fromCache(...); if (!inCache(...)) {

    saveInCache(...); } return fromCache(...); if (!inCache(...)) { saveInCache(...); } return fromCache(...); if (!inCache(...)) { saveInCache(...); } return fromCache(...); if (!inCache(...)) { saveInCache(...); } return fromCache(...); if (!inCache(...)) { saveInCache(...); } return fromCache(...); if (!inCache(...)) { saveInCache(...); } return fromCache(...); if (!inCache(...)) { saveInCache(...); } return fromCache(...); if (!inCache(...)) { saveInCache(...); } return fromCache(...); if (!inCache(...)) { saveInCache(...); } return fromCache(...); if (!inCache(...)) { saveInCache(...); } return fromCache(...); A Naive Solution
  4. api.user.getAll() A Naive Solution api.user.getAll() api.user.getAll() api.user.getAll() api.user.getAll() api.user.getAll() api.user.getAll()

    api.user.getAll() api.user.getAll() api.user.getAll() api.user.getAll() Tamed Application Complexity
  5. build({ user: { api: usersApi } }) Ladda Config build({

    user: { api: usersApi } }) Using Ladda
  6. Application Ladda Config API api.users.getUsers() build({ user: { api: usersApi

    } }) getAll.operation = “READ”; export function getAll() { return http.get(...); } Using Ladda
  7. api.users.getUsers() build({ user: { api: usersApi } }) Application Ladda

    Config API getAll.operation = “READ”; export function getAll() { return http.get(...); } Using Ladda
  8. Using Ladda Knows nothing about Ladda! No dependencies! Application API

    (Ladda’s Config and decorated API functions)
  9. // Component 1 api.user.getUsers() // Component 2 api.user.getUsers() only one

    request made for identical simultaneous requests! Why Ladda
  10. Why Ladda import { denormalizer } from ‘ladda-denormalizer’; build({ objective:

    { api: objectivesApi, plugins: { denormalizer: { schema: { owner: ‘user’, visibleTo: [‘user’] } } } } }, [denormalizer()]);
  11. // Backend response { title: ‘Give a talk at a

    meetup’, owner: ‘9wCWF-y’, visibleTo: [‘hWCIv*Z’, ‘VA0k1vg’] } // what client sees { title: ‘Give a talk at a meetup’, owner: { id: ‘9wCWF-y’, name: ‘Peter Crona’ }, visibleTo: [ { id: ‘hWCIv*Z’, name: ‘Paulo Catumba’ }, { id: ‘VA0k1vg’, name: ‘Gernot Höflechner } ] } import { denormalizer } from ‘ladda-denormalizer’; build({ objective: { api: objectivesApi, plugins: { denormalizer: { schema: { owner: ‘user’, visibleTo: [‘user’] } } } } }, [denormalizer()]); Why Ladda
  12. import { observable } from ‘ladda-observable’; const api = build(config,

    [observable()]); const activities$ = api.activityStream.getLatest.createObservable(); activities$.subscribe((activities) => ...); Why Ladda
  13. import { observable } from ‘ladda-observable’; const api = build(config,

    [observable()]); const activities$ = api.activityStream.getLatest.createObservable(); activities$.subscribe((activities) => ...); // Higher order component from ladda-react withData({ observe: { activities: api.activityStream.getLatest.createObservable() } })(ActivityStream) No need to manage server-side data on the client! Why Ladda
  14. - bindings for Angular 2 and Vue - optimistic updates

    - offline support/persistent cache Why Ladda
  15. 1. Client-Side API caching library 2. Naive VS Ladda 3.

    How to use (config + decorated API functions) 4. Plugins Summary
  16. Learn more and try it out: https://github.com/ladda-js/ladda - rich documentation

    - example applications - next release coming soon! Thank You!