Skip to content

Commit 29409dc

Browse files
author
Wellington Mafra
committed
Removed unused let/const and adapted some logics to ES6
1 parent 861e94f commit 29409dc

File tree

6 files changed

+65
-69
lines changed

6 files changed

+65
-69
lines changed

index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
import signalr from './src';
2-
export default signalr;
1+
export signalr from './src';

src/ajax.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
export default function(options, data) {
2-
var request = new XMLHttpRequest();
3-
request.onreadystatechange = (e) => {
1+
export default (options) => {
2+
const request = new XMLHttpRequest();
3+
request.onreadystatechange = () => {
44
if (request.readyState !== 4) {
55
return;
66
}
77

8-
if (request.status === 200 && !request._hasError) {
9-
options.success && options.success(JSON.parse(request.responseText));
10-
} else {
11-
options.error && options.error(request, request._response);
8+
if (request.status === 200 && !request._hasError && options.success) {
9+
options.success(JSON.parse(request.responseText));
10+
} else if (options.error) {
11+
options.error(request, request._response);
1212
}
1313
};
1414

@@ -17,10 +17,8 @@ export default function(options, data) {
1717

1818
request.send(options.data.data && `data=${options.data.data}`);
1919

20-
// request.abort("__Negotiate Aborted__");
21-
2220
return {
23-
abort: function(reason) {
21+
abort: (reason) => {
2422
return request.abort(reason);
2523
}
2624
};

src/bridge.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
//Arrange new state
2-
let oldDocument = window.document;
3-
let oldReadyState = window.document && window.document.readyState;
4-
let oldUserAgent = window.navigator.userAgent;
2+
const oldDocument = window.document;
3+
const oldReadyState = window.document && window.document.readyState;
4+
55
window.document = {
66
readyState: 'complete'
77
};
88
window.addEventListener = () => {};
9-
window.navigator.userAgent = "react-native";
9+
window.navigator.userAgent = 'react-native';
1010

1111
//Act
1212
window.jQuery = require('./signalr-jquery-polyfill.js');
1313
require('ms-signalr-client');
1414

1515
//Restore old state
16-
let hubConnection = window.jQuery.hubConnection;
16+
const hubConnection = window.jQuery.hubConnection;
1717
window.jQuery = undefined;
1818
window.document = oldDocument;
1919

@@ -22,19 +22,19 @@ if (oldReadyState) {
2222
}
2323

2424
module.exports = {
25-
hubConnection: (serverUrl, logger) => {
25+
hubConnection: (serverUrl) => {
2626
const protocol = serverUrl.split('//')[0];
2727
const host = serverUrl.split('//')[1];
2828
window.location = {
29-
protocol: protocol,
30-
host: host
29+
protocol,
30+
host
3131
};
3232
window.document = {
33-
createElement: function() {
33+
createElement: () => {
3434
return {
35-
protocol: protocol,
36-
host: host
37-
}
35+
protocol,
36+
host
37+
};
3838
}
3939
};
4040
return hubConnection(serverUrl);

src/index.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,39 @@
11
let signalRHubConnectionFunc;
2-
let oldLogger = window.console.debug;
32

43
if (!window.addEventListener) {
54
window.addEventListener = window.addEventListener = () => {};
65
}
7-
window.navigator.userAgent = "react-native";
6+
window.navigator.userAgent = 'react-native';
87
window.jQuery = require('./signalr-jquery-polyfill.js');
9-
10-
module.exports = {
8+
9+
module.exports = {
1110
setLogger: (logger) => {
1211
if (window.console && window.console.debug) {
1312
window.console.debug("OVERWRITING CONSOLE.DEBUG in react-native-signalr");
14-
} else {
15-
if (!window.console) {
13+
} else if (!window.console) {
1614
window.console = {};
1715
}
1816
}
1917
window.console.debug = logger;
2018
},
2119
hubConnection: (serverUrl, options) => {
22-
window.document = window.document || {
23-
readyState: 'complete'
24-
};
20+
window.document = window.document || { readyState: 'complete' };
2521
if (!signalRHubConnectionFunc) {
2622
require('ms-signalr-client');
2723
signalRHubConnectionFunc = window.jQuery.hubConnection;
2824
}
2925
const protocol = serverUrl.split('//')[0];
3026
const host = serverUrl.split('//')[1];
3127
window.location = {
32-
protocol: protocol,
33-
host: host
28+
protocol,
29+
host
3430
};
3531
window.document = {
36-
createElement: function() {
32+
createElement: () => {
3733
return {
38-
protocol: protocol,
39-
host: host
40-
}
34+
protocol,
35+
host
36+
};
4137
}
4238
};
4339

src/jquery-function.js

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,44 @@
1-
export default function(subject) {
2-
let events = subject.events || {};
1+
export default (subject) => {
2+
const events = subject.events || {};
33

4-
if (subject && subject === subject.window)
4+
if (subject && subject === subject.window) {
55
return {
66
0: subject,
77
load: (handler) => subject.addEventListener('load', handler, false),
88
bind: (event, handler) => subject.addEventListener(event, handler, false),
99
unbind: (event, handler) => subject.removeEventListener(event, handler, false)
10-
}
10+
};
11+
}
1112

1213
return {
1314
0: subject,
14-
1515
unbind(event, handler) {
1616
let handlers = events[event] || [];
1717

1818
if (handler) {
19-
let idx = handlers.indexOf(handler);
20-
if (idx !== -1) handlers.splice(idx, 1)
21-
} else handlers = []
19+
const idx = handlers.indexOf(handler);
20+
if (idx !== -1) {
21+
handlers.splice(idx, 1);
22+
}
23+
} else {
24+
handlers = [];
25+
}
2226

23-
events[event] = handlers
27+
events[event] = handlers;
2428
subject.events = events;
25-
2629
},
2730
bind(event, handler) {
28-
let current = events[event] || [];
31+
const current = events[event] || [];
2932
events[event] = current.concat(handler)
3033
subject.events = events;
3134
},
3235
triggerHandler(event, args) {
33-
let handlers = events[event] || [];
36+
const handlers = events[event] || [];
3437
handlers.forEach(fn => {
35-
if(args === undefined) {
36-
args = {
37-
type: event
38-
};
38+
if (args === undefined) {
39+
args = { type: event };
3940
}
40-
if(!Array.isArray(args)) {
41+
if (!Array.isArray(args)) {
4142
args = [args];
4243
}
4344
if (args && args[0] && args[0].type === undefined) {
@@ -48,8 +49,8 @@ export default function(subject) {
4849
args = args || [];
4950
}
5051

51-
fn.apply(this, args)
52-
})
52+
fn.apply(this, args);
53+
});
5354
}
54-
}
55+
};
5556
};

src/signalr-jquery-polyfill.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
import jqueryFunction from './jquery-function';
21
import jQuery from 'jquery-deferred';
2+
import jqueryFunction from './jquery-function';
33
import ajax from './ajax';
4+
45
module.exports = jQuery.extend(
56
jqueryFunction,
67
jQuery,
78
{
8-
defaultAjaxHeaders: null,
9-
ajax: ajax,
10-
inArray: (arr, item) => arr.indexOf(item) !== -1,
11-
trim: str => str && str.trim(),
12-
isEmptyObject: obj => !obj || Object.keys(obj).length === 0,
13-
makeArray: arr => [].slice.call(arr, 0),
14-
support: {
15-
cors: true
9+
defaultAjaxHeaders: null,
10+
ajax,
11+
inArray: (arr, item) => arr.indexOf(item) !== -1,
12+
trim: str => str && str.trim(),
13+
isEmptyObject: obj => !obj || Object.keys(obj).length === 0,
14+
makeArray: arr => [].slice.call(arr, 0),
15+
support: {
16+
cors: true
17+
}
1618
}
17-
});
19+
);

0 commit comments

Comments
 (0)