* Loads a single asset and sets the returned data to the `loaded` subobject * of a given resource map * * Usage: helper.populateSingle(this.metadata.template, this.templates, 'slides') * helper.populateSingle(this.metadata.layout, this.templates, 'layout') * * @param {string} filename T
(filename, destination, key)
| 48 | * @return {Promise} |
| 49 | */ |
| 50 | function populateSingle(filename, destination, key) { |
| 51 | return loadSingle(filename) |
| 52 | .then(function (data) { |
| 53 | if (data) { |
| 54 | /** |
| 55 | * If the key points to an array in the destination map, then |
| 56 | * we should also append to an array in the `loaded` section |
| 57 | * of the map. |
| 58 | * |
| 59 | * This is useful for style resources, where `external.style` may |
| 60 | * refer to a list of resources to be loaded. |
| 61 | */ |
| 62 | if (Object.prototype.toString.call(destination[key]) === '[object Array]') { |
| 63 | destination.loaded[key] = destination.loaded[key] || []; |
| 64 | destination.loaded[key].push(data); |
| 65 | } else { |
| 66 | destination.loaded[key] = data; |
| 67 | } |
| 68 | } |
| 69 | }); |
| 70 | } |
| 71 | |
| 72 | |
| 73 | /** |
no test coverage detected