@cobalt-engine/loader
v1.0.1
Published
Module encapsulates AJAX file loading and caching using promises.
Downloads
23
Keywords
Readme
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
). ReturnsPromise
that resolves when file has loadedloadJSON(url, reviewer)
-url
- path to file (string
).reviewer
- function that will passed toJSON.parse
when file is loaded. ReturnsPromise
that resolves when file has loaded. If file can't be loaded or parsed withreviewer
function 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.