1.0.1 • Published 8 years ago
@cobalt-engine/loader v1.0.1
Loader
Module encapsulates AJAX file loading and caching using promises.
Cobalt uses Bluebird promise library. You can find documentation for it on this page.
Use this module for loading of all JSON files in you presentation.
Install
Loader is a part of core functionality so you don't need to install it.
API
Methods:
load(url)-url- path to file (string). ReturnsPromisethat resolves when file has loadedloadJSON(url, reviewer)-url- path to file (string).reviewer- function that will passed toJSON.parsewhen file is loaded. ReturnsPromisethat resolves when file has loaded. If file can't be loaded or parsed withreviewerfunction promise fill be fulfilled with empty object and warning will be logged to console:"File can't be loaded or parsed: `url`"
Example
Controller code:
var loader = require('loader');
module.exports = function(scope) {
loader.loadJSON('i18n/en/common.json').then(function(result) {
console.log(result);
});
}As a result object stored in file i18n/en/common.json will be logged to console.