@cobalt-engine/loader

    1.0.1 • Public • Published

    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.

    Keywords

    none

    Install

    npm i @cobalt-engine/loader

    DownloadsWeekly Downloads

    48

    Version

    1.0.1

    License

    ISC

    Unpacked Size

    3.57 kB

    Total Files

    6

    Last publish

    Collaborators

    • oleg322
    • v.kobyletskiy
    • anna-shavurska
    • vasylshylov