imagine for a moment trentmwillis lazy loading engines
play

Imagine for a moment @trentmwillis Lazy Loading Engines: Anything - PowerPoint PPT Presentation

Imagine for a moment @trentmwillis Lazy Loading Engines: Anything But Lazy Engines allow multiple logical applications to be composed together into a single application from the users perspective. - Engine RFC Lazy Loading Engines.


  1. Imagine for a moment …

  2. @trentmwillis

  3. Lazy Loading Engines: Anything But Lazy

  4. Engines allow multiple logical applications to be composed together into a single application from the user’s perspective. - Engine RFC

  5. Lazy Loading Engines.

  6. Lazy Loading.

  7. Lazy Loading. It’s hard .

  8. Lazy Loading. It’s hard. But, Ember makes it easy .

  9. Problem 1: Serializing URLs

  10. How do we construct a URL to a lazily loaded route?

  11. {{#link-to “blog”}} Blog {{/link-to}}

  12. How to construct a URL Router + Model + Query Params + Route + Controller ——————— URL

  13. How to construct a URL Router + Model + Query Params + Route + Controller ——————— URL

  14. Problem 1: Serializing URLs

  15. Problem 1: Serializing URLs ————————————— Model Serialization w/o Routes Query Params w/o Controllers

  16. Model Serialization w/o Routes

  17. Router.map(function() { this.route('post', { path: ‘/post/ :post_id ’ }); });

  18. Route.extend({ serialize(model) { return { post_id: model.id }; } });

  19. Route Serializer RFC emberjs/rfcs#120

  20. [Replace] the existing Route#serialize method with an equivalent method on the options hash passed into this.route within Router#map.

  21. Route.extend({ serialize(model) { return { post_id: model.id }; } });

  22. function serialize(model) { return { post_id: model.id }; }

  23. function serialize(model) { return { post_id: model.id }; } Router.map(function() { this.route('post', { path: ‘/post/ :post_id ’, serialize }); });

  24. Query Params w/o Controllers

  25. Default Query Param Values

  26. Controller.extend({ queryParams: [‘lang’, ‘locale’], lang: ‘en’ });

  27. Controller.extend({ queryParams: [‘lang’, ‘locale’], lang: ‘en’ }); serialize({ });

  28. Controller.extend({ queryParams: [‘lang’, ‘locale’], lang: ‘en’ }); serialize({ lang: ‘en’, locale: ‘uk’ });

  29. Controller.extend({ queryParams: [‘lang’, ‘locale’], lang: ‘en’ }); serialize({ lang: ‘en’, locale: ‘uk’ }); => ?locale=uk

  30. Controller.extend({ queryParams: [‘lang’, ‘locale’], lang: ‘en’ }); serialize({ lang: ‘en’, locale: ‘uk’ }); => ?locale=uk &lang=en

  31. With lazy Engines, default query params are part of the URL

  32. Problem 2: Link Scoping

  33. {{link-to “blog”}}

  34. Where does {{link-to “blog”}} go in an Engine?

  35. {{link-to “blog”}}

  36. {{link-to “mountPoint.blog”}}

  37. To ensure isolation (and loose- coupling), links are scoped to an Engine’s mount point.

  38. How do you link outside the scope of an Engine?

  39. Engine Linking RFC emberjs/rfcs#122

  40. {{link-to-external “home”}} this.transitionToExternal(‘home’);

  41. export default Engine.extend({ dependencies: { externalRoutes: [ 'home', 'settings' ] } });

  42. Ember.Application.extend({ engines: { myEngine: { dependencies: { externalRoutes: { home: 'home.index', settings: 'user.settings' } } } } });

  43. With {{ link-to-external}} you are specifying what you want to go to. It is the consumer’s responsibility to tell you where that is.

  44. Engine : Hey App, I want to go to “settings”. Where is that?

  45. Engine : Hey App, I want to go to “settings”. Where is that? Host : “settings” is located at “user.settings.index”.

  46. Engine : Hey App, I want to go to “settings”. Where is that? Host : “settings” is located at “user.settings.index”. Engine : Thanks!

  47. Problem 3: Loading Assets

  48. Problem 3: Loading Assets ———————————— What do we load? How do we load it?

  49. What do we load?

  50. Asset Manifest RFC emberjs/rfcs#153

  51. The Asset Manifest is a JSON specification to describe assets and bundles of assets that can be loaded into an Ember application asynchronously at runtime.

  52. interface Asset { type: String; uri: String; }

  53. type BundleName = string; interface Bundle { assets: Array<Asset>; dependencies?: Array<BundleName>; }

  54. interface AssetManifest { bundles: Map<BundleName, Bundle>; }

  55. Transforms (e.g., fingerprinting) Compositional Loading Extensibility Transferability

  56. How do we load it?

  57. Asset Loader RFC emberjs/rfcs#158

  58. The Asset Loader service is an Ember Service that is responsible for loading assets specified in an Asset Manifest.

  59. The API for loading these assets is Promise-based for integration with Router.js.

  60. interface AssetLoader { pushManifest(manifest: AssetManifest); };

  61. interface AssetLoader { pushManifest(manifest: AssetManifest); loadAsset(asset: Asset): AssetPromise; };

  62. interface AssetLoader { pushManifest(manifest: AssetManifest); loadAsset(asset: Asset): AssetPromise; loadBundle(bundle: BundleName): BundlePromise; };

  63. interface AssetLoader { pushManifest(manifest: AssetManifest); loadAsset(asset: Asset): AssetPromise; loadBundle(bundle: BundleName): BundlePromise; defineLoader(type: String, loader: (uri: String) => Promise<T, U>); };

  64. interface AssetLoader { pushManifest(manifest: AssetManifest); loadAsset(asset: Asset): AssetPromise; loadBundle(bundle: BundleName): BundlePromise; defineLoader(type: String, loader: (uri: String) => Promise<T, U>); };

  65. Asset Manifest + Asset Loader —————————————- Ember Asset Loading Strategy

  66. ember-asset-loader

  67. Ember Engines

  68. Ember Engines: A community-driven solution to lazy loading.

  69. ember-engines.com github.com/ember-engines

  70. Lazy Loading Engines: Anything But Lazy

Recommend


More recommend