@cobalt-engine/loader

Module encapsulates AJAX file loading and caching using promises.

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
@cobalt-engine/loader
Minified + gzip package size for @cobalt-engine/loader in KB

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). Returns Promise that resolves when file has loaded

  • loadJSON(url, reviewer) - url - path to file (string). reviewer - function that will passed to JSON.parse when file is loaded. Returns Promise that resolves when file has loaded. If file can't be loaded or parsed with reviewer 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.

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.