123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- "use strict"
-
- var REGISTRATION_KEY = '@@any-promise/REGISTRATION',
-
- registered = null
- module.exports = function(root, loadImplementation){
- return function register(implementation, opts){
- implementation = implementation || null
- opts = opts || {}
-
- var registerGlobal = opts.global !== false;
-
- if(registered === null && registerGlobal){
- registered = root[REGISTRATION_KEY] || null
- }
- if(registered !== null
- && implementation !== null
- && registered.implementation !== implementation){
-
- throw new Error('any-promise already defined as "'+registered.implementation+
- '". You can only register an implementation before the first '+
- ' call to require("any-promise") and an implementation cannot be changed')
- }
- if(registered === null){
-
- if(implementation !== null && typeof opts.Promise !== 'undefined'){
- registered = {
- Promise: opts.Promise,
- implementation: implementation
- }
- } else {
-
- registered = loadImplementation(implementation)
- }
- if(registerGlobal){
-
- root[REGISTRATION_KEY] = registered
- }
- }
- return registered
- }
- }
|