-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-web.js
35 lines (32 loc) · 1.44 KB
/
build-web.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
;'use strict';
/*
* @module uniSoc
* @author plundell
* @license Apache-2.0
* @description Frontend component of uniSoc. Wraps around native WebSocket API (https://developer.mozilla.org/en-US/docs/Web/API/WebSocket)
* @extends ./unisoc-common.js
* @depends libbetter
* @exports n/a This script should be bundled and loaded in the browser directly. It make the module available
* at window.uniSoc. If you don't want that you can instead require the web-component of uniSoc ./src/web.js
*/
(function loadUniSoc(){
if(typeof window!='object' || !window)
throw new Error("ESCOPE. Could not access the 'window' object. Cannot load uniSoc.");
var exporter=require("./src/unisoc.web.js");
//Create a getter on the window which runs the exporter as soon as all dependencies are
//available OR throws a clear error if we try to access it too early
Object.defineProperty(window,'uniSoc',{enumerable:true, configurable:true
,get:()=>{
if(window.BetterLog && window.BetterEvents && window.BetterUtil){
return window.uniSoc=exporter(window);
}else{
throw new Error("E_DEPENDENCY. uniSoc depends on libbetter which should be set on the window.");
}
}
//This setter allows^ the whole thing to easily be undone/overwritten
,set:(val)=>{
Object.defineProperty(window,'uniSoc',{value:val,enumerable:true,writable:true,configurable:true});
return val;
}
})
}())