Skip to content

Instantly share code, notes, and snippets.

@beginor
Forked from green3g/dojo.js
Last active February 18, 2017 09:23
Show Gist options
  • Select an option

  • Save beginor/7dbe633ef26e98fe0ba70bcb1d191b8c to your computer and use it in GitHub Desktop.

Select an option

Save beginor/7dbe633ef26e98fe0ba70bcb1d191b8c to your computer and use it in GitHub Desktop.

Revisions

  1. beginor renamed this gist Feb 17, 2017. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. beginor revised this gist Feb 17, 2017. 1 changed file with 31 additions and 20 deletions.
    51 changes: 31 additions & 20 deletions dojo.js
    Original file line number Diff line number Diff line change
    @@ -1,23 +1,34 @@
    exports = {
    fetch: function(load, fetch) {
    console.log('load', load);
    let module = load.name.split('!')[0];
    return new Promise(function(resolve) {
    //use dojo's require and then register the module
    window.require([module], function(mod) {
    System.register(module, [], function(exp, idObj) {
    var result = {
    setters: [],
    execute: function() {
    //Make the name 'default' here as there is only one export per module so it is technically the default.
    //Import using a default import statement - eg: import Map from 'esri/Map'
    //It's possible this may only compile using 'system' module type in some IDEs using the official typings file though.
    exp("default", mod);
    }
    };
    return result;
    });
    exports.fetch = function(load) {
    var name = load.name;
    return new Promise(function(resolve) {
    var dojoName = convertToDojoModule(name);
    window.require([dojoName], function(mod) {
    SystemJS.register(dojoName, [], function (exp, idObj) {
    return {
    setters: [],
    execute: function() {
    exp("default", mod);
    }
    };
    });
    resolve('');
    });
    }
    });
    };

    exports.instantiate = function (load) {
    var name = load.name.split('!')[0];
    var dojoName = convertToDojoModule(name);
    return new Promise(function (resolve) {
    // Since module is loaded by fetch, just require it again,
    // dojo require does not load the module again.
    window.require([dojoName], function (module) {
    resolve(module);
    });
    });
    };

    function convertToDojoModule(module) {
    // we just replace SystemJS.baseURL with '';
    return module.replace(SystemJS.baseURL, '');
    }
  3. @green3g green3g revised this gist Aug 30, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion dojo.js
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ exports = {
    return new Promise(function(resolve) {
    //use dojo's require and then register the module
    window.require([module], function(mod) {
    System.register(names[i], [], function(exp, idObj) {
    System.register(module, [], function(exp, idObj) {
    var result = {
    setters: [],
    execute: function() {
  4. @green3g green3g created this gist Aug 30, 2016.
    23 changes: 23 additions & 0 deletions dojo.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    exports = {
    fetch: function(load, fetch) {
    console.log('load', load);
    let module = load.name.split('!')[0];
    return new Promise(function(resolve) {
    //use dojo's require and then register the module
    window.require([module], function(mod) {
    System.register(names[i], [], function(exp, idObj) {
    var result = {
    setters: [],
    execute: function() {
    //Make the name 'default' here as there is only one export per module so it is technically the default.
    //Import using a default import statement - eg: import Map from 'esri/Map'
    //It's possible this may only compile using 'system' module type in some IDEs using the official typings file though.
    exp("default", mod);
    }
    };
    return result;
    });
    });
    });
    }
    };