Skip to content

Commit 1abc8b3

Browse files
committed
Kill get global hack in favour of define plugin. Resolves pusher#168
1 parent c817954 commit 1abc8b3

File tree

9 files changed

+15
-8
lines changed

9 files changed

+15
-8
lines changed

src/core/base64.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const global = Function("return this")();
2-
31
export default function encode (s : any) : string {
42
return btoa(utob(s));
53
}

src/core/events/dispatcher.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import CallbackRegistry from './callback_registry';
22
import Callback from './callback';
3-
const global = Function("return this")();
43

54
/** Manages callback bindings and event emitting.
65
*

src/core/logger.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const Logger = {
1010
},
1111
warn(...args : any[]) {
1212
var message = safeJSONStringify.apply(this, arguments);
13-
const global = Function("return this")();
1413
if (global.console) {
1514
if (global.console.warn) {
1615
global.console.warn(message);

src/core/pusher.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export default class Pusher {
3939
}
4040

4141
static log(message : any) {
42-
const global = Function("return this")();
4342
if (Pusher.logToConsole && global.console && global.console.log) {
4443
global.console.log(message);
4544
}

src/core/utils/collections.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import base64encode from '../base64';
22
import Util from '../util';
3-
const global = Function("return this")();
43

54
/** Merges multiple objects into the target argument.
65
*

src/d.ts/global/global.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare const global : any;

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
},
1010
"files": [
1111
"src/core/pusher.ts",
12+
"src/d.ts/global/global.d.ts",
1213
"src/d.ts/faye-websocket/faye-websocket.d.ts",
1314
"src/d.ts/xmlhttprequest/xmlhttprequest.d.ts",
1415
"src/d.ts/window/websocket.d.ts",

webpack/config.web.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ var config = objectAssign(require('./config.shared'),{
2121
},
2222
resolve: {
2323
modulesDirectories: ['src/', 'src/runtimes/web', 'src/runtimes']
24-
}
24+
},
25+
plugins: [
26+
new webpack.DefinePlugin({
27+
global: "window"
28+
})
29+
]
2530
});
2631

2732
module.exports = config;

webpack/config.worker.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var path = require("path");
22
var NormalModuleReplacementPlugin = require('webpack').NormalModuleReplacementPlugin;
33
var version = require('../package').version;
44
var objectAssign = require('object-assign-deep');
5+
var webpack = require('webpack');
56

67
/*
78
Upon importing the 'runtime' module, this worker build is made to look at
@@ -20,7 +21,12 @@ var config = objectAssign(require('./config.shared'),{
2021
},
2122
resolve: {
2223
modulesDirectories: ['src/', 'src/runtimes/worker', 'src/runtimes']
23-
}
24+
},
25+
plugins: [
26+
new webpack.DefinePlugin({
27+
global: "self"
28+
})
29+
]
2430
});
2531

2632
/*

0 commit comments

Comments
 (0)