justinhelmer
7/11/2017 - 5:51 PM

example of _thirdPartyScripts with idempotency

example of _thirdPartyScripts with idempotency

define([
  'config',
  'scriptjs',
  'bluebird'
], function (config, $script, Promise) {
  'use strict';
  
  let ThirdPartyScripts = {
    _promise: null
  };
  
  ThirdPartyScripts.load = () => {
    if (!ThirdPartyScripts._promise) {
      ThirdPartyScripts._promise = new Promise((resolve, reject) => {
        $script(scripts, 'bundle');
        $script.ready('bundle', resolve, reject);
      });
    }

    return ThirdPartyScripts._promise;
  };
  
  return ThirdPartyScripts;
});