Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | 2x 2x 5x 2x 2x 5x 2x 2x | import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
/**
Provides Ember route for portfolio view.
@module PortfolioRoute
@extends Ember.Route
*/
export default class PortfolioRoute extends Route {
@service store;
/**
Fetches `PortfolioEntryRecords` from the data store.
@method model
@returns {Promise} Resolves to an array of `PortfolioEntryRecords`
*/
model() {
return this.store.findAll('portfolio-entry');
}
/**
Promise-aware Ember route lifecycle hook that initiates portfolio image
caching (for quick loading) after `PortfolioEntryRecords` are loaded
from the data store.
@method afterModel
@returns {Promise} Resolves to an array of loaded portfolio images
*/
afterModel(model) {
return this.preloadImages(model);
}
/**
Preloads portfolio images.
@method preloadImages
@returns {Promise} Resolves to an array of loaded portfolio images
*/
preloadImages(portfolioEntries) {
const imageUrls = portfolioEntries.map((entry) => entry.image);
const imageRequests = [];
imageUrls.forEach((imageUrl) => {
imageRequests.push(fetch(imageUrl));
});
return Promise.allSettled(imageRequests);
}
/**
Assigns `model` to controller as `portfolioEntries`
@method setupController
@param {Ember.Controller} controller
@param {ArrayProxy} model Resolved portfolio entries collection
*/
setupController(controller, model) {
Object.assign(controller, {
portfolioEntries: model,
});
}
}
|