Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit ad35703

Browse files
committed
Reduce indentation in installGlobalHook
1 parent 3fa2421 commit ad35703

1 file changed

Lines changed: 42 additions & 41 deletions

File tree

backend/installGlobalHook.js

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,47 +17,48 @@ import type {Hook} from './types';
1717
* function in some places and inject the source into the page.
1818
*/
1919
function installGlobalHook(window: Object) {
20-
if (!window.__REACT_DEVTOOLS_GLOBAL_HOOK__) {
21-
Object.defineProperty(window, '__REACT_DEVTOOLS_GLOBAL_HOOK__', {
22-
value: ({
23-
_renderers: {},
24-
helpers: {},
25-
inject: function(renderer) {
26-
var id = Math.random().toString(16).slice(2);
27-
this._renderers[id] = renderer;
28-
this.emit('renderer', {id, renderer});
29-
},
30-
_listeners: {},
31-
sub: function(evt, fn) {
32-
this.on(evt, fn);
33-
return () => this.off(evt, fn);
34-
},
35-
on: function(evt, fn) {
36-
if (!this._listeners[evt]) {
37-
this._listeners[evt] = [];
38-
}
39-
this._listeners[evt].push(fn);
40-
},
41-
off: function(evt, fn) {
42-
if (!this._listeners[evt]) {
43-
return;
44-
}
45-
var ix = this._listeners[evt].indexOf(fn);
46-
if (ix !== -1) {
47-
this._listeners[evt].splice(ix, 1);
48-
}
49-
if (!this._listeners[evt].length) {
50-
this._listeners[evt] = null;
51-
}
52-
},
53-
emit: function(evt, data) {
54-
if (this._listeners[evt]) {
55-
this._listeners[evt].map(fn => fn(data));
56-
}
57-
},
58-
}: Hook),
59-
});
20+
if (window.__REACT_DEVTOOLS_GLOBAL_HOOK__) {
21+
return;
6022
}
61-
};
23+
Object.defineProperty(window, '__REACT_DEVTOOLS_GLOBAL_HOOK__', {
24+
value: ({
25+
_renderers: {},
26+
helpers: {},
27+
inject: function(renderer) {
28+
var id = Math.random().toString(16).slice(2);
29+
this._renderers[id] = renderer;
30+
this.emit('renderer', {id, renderer});
31+
},
32+
_listeners: {},
33+
sub: function(evt, fn) {
34+
this.on(evt, fn);
35+
return () => this.off(evt, fn);
36+
},
37+
on: function(evt, fn) {
38+
if (!this._listeners[evt]) {
39+
this._listeners[evt] = [];
40+
}
41+
this._listeners[evt].push(fn);
42+
},
43+
off: function(evt, fn) {
44+
if (!this._listeners[evt]) {
45+
return;
46+
}
47+
var ix = this._listeners[evt].indexOf(fn);
48+
if (ix !== -1) {
49+
this._listeners[evt].splice(ix, 1);
50+
}
51+
if (!this._listeners[evt].length) {
52+
this._listeners[evt] = null;
53+
}
54+
},
55+
emit: function(evt, data) {
56+
if (this._listeners[evt]) {
57+
this._listeners[evt].map(fn => fn(data));
58+
}
59+
},
60+
}: Hook),
61+
});
62+
}
6263

6364
module.exports = installGlobalHook;

0 commit comments

Comments
 (0)