浏览代码

Use Symbol for Redux action types to prevent conflicts

j8
Lyubomir Marinov 8 年前
父节点
当前提交
daf56455a5

+ 4
- 2
react/features/app/actionTypes.js 查看文件

@@ -1,3 +1,5 @@
1
+import { Symbol } from '../base/react';
2
+
1 3
 /**
2 4
  * The type of the actions which signals that a specific App will mount (in the
3 5
  * terms of React).
@@ -7,7 +9,7 @@
7 9
  *     app: App
8 10
  * }
9 11
  */
10
-export const APP_WILL_MOUNT = 'APP_WILL_MOUNT';
12
+export const APP_WILL_MOUNT = Symbol('APP_WILL_MOUNT');
11 13
 
12 14
 /**
13 15
  * The type of the actions which signals that a specific App will unmount (in
@@ -18,4 +20,4 @@ export const APP_WILL_MOUNT = 'APP_WILL_MOUNT';
18 20
  *     app: App
19 21
  * }
20 22
  */
21
-export const APP_WILL_UNMOUNT = 'APP_WILL_UNMOUNT';
23
+export const APP_WILL_UNMOUNT = Symbol('APP_WILL_UNMOUNT');

+ 6
- 4
react/features/base/conference/actionTypes.js 查看文件

@@ -1,3 +1,5 @@
1
+import { Symbol } from '../react';
2
+
1 3
 /**
2 4
  * Action type to signal that we are joining the conference.
3 5
  *
@@ -8,7 +10,7 @@
8 10
  *      }
9 11
  * }
10 12
  */
11
-export const CONFERENCE_JOINED = 'CONFERENCE_JOINED';
13
+export const CONFERENCE_JOINED = Symbol('CONFERENCE_JOINED');
12 14
 
13 15
 /**
14 16
  * Action type to signal that we have left the conference.
@@ -20,7 +22,7 @@ export const CONFERENCE_JOINED = 'CONFERENCE_JOINED';
20 22
  *      }
21 23
  * }
22 24
  */
23
-export const CONFERENCE_LEFT = 'CONFERENCE_LEFT';
25
+export const CONFERENCE_LEFT = Symbol('CONFERENCE_LEFT');
24 26
 
25 27
 /**
26 28
  * Action type to signal that we will leave the specified conference.
@@ -32,7 +34,7 @@ export const CONFERENCE_LEFT = 'CONFERENCE_LEFT';
32 34
  *      }
33 35
  * }
34 36
  */
35
-export const CONFERENCE_WILL_LEAVE = 'CONFERENCE_WILL_LEAVE';
37
+export const CONFERENCE_WILL_LEAVE = Symbol('CONFERENCE_WILL_LEAVE');
36 38
 
37 39
 /**
38 40
  * The type of the Redux action which sets the name of the room of the
@@ -43,4 +45,4 @@ export const CONFERENCE_WILL_LEAVE = 'CONFERENCE_WILL_LEAVE';
43 45
  *      room: string
44 46
  * }
45 47
  */
46
-export const SET_ROOM = 'SET_ROOM';
48
+export const SET_ROOM = Symbol('SET_ROOM');

+ 6
- 10
react/features/base/connection/actionTypes.js 查看文件

@@ -1,23 +1,19 @@
1
+import { Symbol } from '../react';
2
+
1 3
 /**
2 4
  * Action type to signal that connection has disconnected.
3
- *
4
- * @type {string}
5 5
  */
6
-export const CONNECTION_DISCONNECTED = 'CONNECTION_DISCONNECTED';
6
+export const CONNECTION_DISCONNECTED = Symbol('CONNECTION_DISCONNECTED');
7 7
 
8 8
 /**
9 9
  * Action type to signal that have successfully established a connection.
10
- *
11
- * @type {string}
12 10
  */
13
-export const CONNECTION_ESTABLISHED = 'CONNECTION_ESTABLISHED';
11
+export const CONNECTION_ESTABLISHED = Symbol('CONNECTION_ESTABLISHED');
14 12
 
15 13
 /**
16 14
  * Action type to signal a connection failed.
17
- *
18
- * @type {string}
19 15
  */
20
-export const CONNECTION_FAILED = 'CONNECTION_FAILED';
16
+export const CONNECTION_FAILED = Symbol('CONNECTION_FAILED');
21 17
 
22 18
 /**
23 19
  * Action to signal to change connection domain.
@@ -27,4 +23,4 @@ export const CONNECTION_FAILED = 'CONNECTION_FAILED';
27 23
  *     domain: string
28 24
  * }
29 25
  */
30
-export const SET_DOMAIN = 'SET_DOMAIN';
26
+export const SET_DOMAIN = Symbol('SET_DOMAIN');

+ 6
- 4
react/features/base/lib-jitsi-meet/actionTypes.js 查看文件

@@ -1,3 +1,5 @@
1
+import { Symbol } from '../react';
2
+
1 3
 /**
2 4
  * Action to signal that lib-jitsi-meet library was disposed.
3 5
  *
@@ -5,7 +7,7 @@
5 7
  *     type: LIB_DISPOSED
6 8
  * }
7 9
  */
8
-export const LIB_DISPOSED = 'LIB_DISPOSED';
10
+export const LIB_DISPOSED = Symbol('LIB_DISPOSED');
9 11
 
10 12
 /**
11 13
  * Action to signal that lib-jitsi-meet initialized failed with error.
@@ -15,7 +17,7 @@ export const LIB_DISPOSED = 'LIB_DISPOSED';
15 17
  *     error: Error
16 18
  * }
17 19
  */
18
-export const LIB_INIT_ERROR = 'LIB_INIT_ERROR';
20
+export const LIB_INIT_ERROR = Symbol('LIB_INIT_ERROR');
19 21
 
20 22
 /**
21 23
  * Action to signal that lib-jitsi-meet initialization succeeded.
@@ -24,7 +26,7 @@ export const LIB_INIT_ERROR = 'LIB_INIT_ERROR';
24 26
  *     type: LIB_INITIALIZED
25 27
  * }
26 28
  */
27
-export const LIB_INITIALIZED = 'LIB_INITIALIZED';
29
+export const LIB_INITIALIZED = Symbol('LIB_INITIALIZED');
28 30
 
29 31
 /**
30 32
  * Action to signal that config was set.
@@ -34,4 +36,4 @@ export const LIB_INITIALIZED = 'LIB_INITIALIZED';
34 36
  *     config: Object
35 37
  * }
36 38
  */
37
-export const SET_CONFIG = 'SET_CONFIG';
39
+export const SET_CONFIG = Symbol('SET_CONFIG');

+ 27
- 27
react/features/base/lib-jitsi-meet/native/polyfills-browser.js 查看文件

@@ -85,6 +85,9 @@ function _visitNode(node, callback) {
85 85
 
86 86
 (global => {
87 87
 
88
+    // Polyfill for URL constructor
89
+    require('url-polyfill');
90
+
88 91
     const DOMParser = require('xmldom').DOMParser;
89 92
 
90 93
     // addEventListener
@@ -210,30 +213,6 @@ function _visitNode(node, callback) {
210 213
         };
211 214
     }
212 215
 
213
-    // performance
214
-    if (typeof global.performance === 'undefined') {
215
-        global.performance = {
216
-            now() {
217
-                return 0;
218
-            }
219
-        };
220
-    }
221
-
222
-    // sessionStorage
223
-    //
224
-    // Required by:
225
-    // - Strophe
226
-    if (typeof global.sessionStorage === 'undefined') {
227
-        global.sessionStorage = {
228
-            /* eslint-disable no-empty-function */
229
-            getItem() {},
230
-            removeItem() {},
231
-            setItem() {}
232
-
233
-            /* eslint-enable no-empty-function */
234
-        };
235
-    }
236
-
237 216
     const navigator = global.navigator;
238 217
 
239 218
     if (navigator) {
@@ -280,6 +259,30 @@ function _visitNode(node, callback) {
280 259
         })();
281 260
     }
282 261
 
262
+    // performance
263
+    if (typeof global.performance === 'undefined') {
264
+        global.performance = {
265
+            now() {
266
+                return 0;
267
+            }
268
+        };
269
+    }
270
+
271
+    // sessionStorage
272
+    //
273
+    // Required by:
274
+    // - Strophe
275
+    if (typeof global.sessionStorage === 'undefined') {
276
+        global.sessionStorage = {
277
+            /* eslint-disable no-empty-function */
278
+            getItem() {},
279
+            removeItem() {},
280
+            setItem() {}
281
+
282
+            /* eslint-enable no-empty-function */
283
+        };
284
+    }
285
+
283 286
     // WebRTC
284 287
     require('./polyfills-webrtc');
285 288
 
@@ -310,7 +313,4 @@ function _visitNode(node, callback) {
310 313
         }
311 314
     }
312 315
 
313
-    // Polyfill for URL constructor
314
-    require('url-polyfill');
315
-
316 316
 })(global || window || this); // eslint-disable-line no-invalid-this

+ 5
- 3
react/features/base/media/actionTypes.js 查看文件

@@ -1,3 +1,5 @@
1
+import { Symbol } from '../react';
2
+
1 3
 /**
2 4
  * Action to change muted state of the local audio.
3 5
  *
@@ -6,7 +8,7 @@
6 8
  *      muted: boolean
7 9
  * }
8 10
  */
9
-export const AUDIO_MUTED_CHANGED = 'AUDIO_MUTED_CHANGED';
11
+export const AUDIO_MUTED_CHANGED = Symbol('AUDIO_MUTED_CHANGED');
10 12
 
11 13
 /**
12 14
  * Action to signal a change of the facing mode of the local video camera.
@@ -16,7 +18,7 @@ export const AUDIO_MUTED_CHANGED = 'AUDIO_MUTED_CHANGED';
16 18
  *      cameraFacingMode: CAMERA_FACING_MODE
17 19
  * }
18 20
  */
19
-export const CAMERA_FACING_MODE_CHANGED = 'CAMERA_FACING_MODE_CHANGED';
21
+export const CAMERA_FACING_MODE_CHANGED = Symbol('CAMERA_FACING_MODE_CHANGED');
20 22
 
21 23
 /**
22 24
  * Action to change muted state of the local video.
@@ -26,4 +28,4 @@ export const CAMERA_FACING_MODE_CHANGED = 'CAMERA_FACING_MODE_CHANGED';
26 28
  *      muted: boolean
27 29
  * }
28 30
  */
29
-export const VIDEO_MUTED_CHANGED = 'VIDEO_MUTED_CHANGED';
31
+export const VIDEO_MUTED_CHANGED = Symbol('VIDEO_MUTED_CHANGED');

+ 8
- 6
react/features/base/participants/actionTypes.js 查看文件

@@ -1,3 +1,5 @@
1
+import { Symbol } from '../react';
2
+
1 3
 /**
2 4
  * Create an action for when dominant speaker changes.
3 5
  *
@@ -8,7 +10,7 @@
8 10
  *      }
9 11
  * }
10 12
  */
11
-export const DOMINANT_SPEAKER_CHANGED = 'DOMINANT_SPEAKER_CHANGED';
13
+export const DOMINANT_SPEAKER_CHANGED = Symbol('DOMINANT_SPEAKER_CHANGED');
12 14
 
13 15
 /**
14 16
  * Action to signal that ID of participant has changed. This happens when
@@ -20,7 +22,7 @@ export const DOMINANT_SPEAKER_CHANGED = 'DOMINANT_SPEAKER_CHANGED';
20 22
  *      oldValue: string
21 23
  * }
22 24
  */
23
-export const PARTICIPANT_ID_CHANGED = 'PARTICIPANT_ID_CHANGED';
25
+export const PARTICIPANT_ID_CHANGED = Symbol('PARTICIPANT_ID_CHANGED');
24 26
 
25 27
 /**
26 28
  * Action to signal that a participant has joined.
@@ -30,7 +32,7 @@ export const PARTICIPANT_ID_CHANGED = 'PARTICIPANT_ID_CHANGED';
30 32
  *      participant: Participant
31 33
  * }
32 34
  */
33
-export const PARTICIPANT_JOINED = 'PARTICIPANT_JOINED';
35
+export const PARTICIPANT_JOINED = Symbol('PARTICIPANT_JOINED');
34 36
 
35 37
 /**
36 38
  * Action to handle case when participant lefts.
@@ -42,7 +44,7 @@ export const PARTICIPANT_JOINED = 'PARTICIPANT_JOINED';
42 44
  *      }
43 45
  * }
44 46
  */
45
-export const PARTICIPANT_LEFT = 'PARTICIPANT_LEFT';
47
+export const PARTICIPANT_LEFT = Symbol('PARTICIPANT_LEFT');
46 48
 
47 49
 /**
48 50
  * Action to handle case when info about participant changes.
@@ -52,7 +54,7 @@ export const PARTICIPANT_LEFT = 'PARTICIPANT_LEFT';
52 54
  *      participant: Participant
53 55
  * }
54 56
  */
55
-export const PARTICIPANT_UPDATED = 'PARTICIPANT_UPDATED';
57
+export const PARTICIPANT_UPDATED = Symbol('PARTICIPANT_UPDATED');
56 58
 
57 59
 /**
58 60
  * The type of the Redux action which pins a conference participant.
@@ -64,4 +66,4 @@ export const PARTICIPANT_UPDATED = 'PARTICIPANT_UPDATED';
64 66
  *      }
65 67
  * }
66 68
  */
67
-export const PIN_PARTICIPANT = 'PIN_PARTICIPANT';
69
+export const PIN_PARTICIPANT = Symbol('PIN_PARTICIPANT');

+ 14
- 0
react/features/base/react/Symbol.js 查看文件

@@ -0,0 +1,14 @@
1
+// FIXME React Native does not polyfill Symbol at versions 0.39.2 or earlier.
2
+export default (global => {
3
+    let s = global.Symbol;
4
+
5
+    if (typeof s === 'undefined') {
6
+        // XXX At the time of this writing we use Symbol only as a way to
7
+        // prevent collisions in Redux action types. Consequently, the Symbol
8
+        // implementation provided bellow is minimal and specific to our
9
+        // purpose.
10
+        s = description => (description || '').split('');
11
+    }
12
+
13
+    return s;
14
+})(global || window || this); // eslint-disable-line no-invalid-this

+ 0
- 0
react/features/base/react/components/Container.web.js 查看文件


+ 0
- 0
react/features/base/react/components/Link.web.js 查看文件


+ 1
- 0
react/features/base/react/index.js 查看文件

@@ -1,2 +1,3 @@
1 1
 export * from './components';
2 2
 export * from './functions';
3
+export { default as Symbol } from './Symbol';

+ 5
- 3
react/features/base/tracks/actionTypes.js 查看文件

@@ -1,3 +1,5 @@
1
+import { Symbol } from '../react';
2
+
1 3
 /**
2 4
  * Action for when a track has been added to the conference,
3 5
  * local or remote.
@@ -7,7 +9,7 @@
7 9
  *     track: Track
8 10
  * }
9 11
  */
10
-export const TRACK_ADDED = 'TRACK_ADDED';
12
+export const TRACK_ADDED = Symbol('TRACK_ADDED');
11 13
 
12 14
 /**
13 15
  * Action for when a track has been removed from the conference,
@@ -18,7 +20,7 @@ export const TRACK_ADDED = 'TRACK_ADDED';
18 20
  *     track: Track
19 21
  * }
20 22
  */
21
-export const TRACK_REMOVED = 'TRACK_REMOVED';
23
+export const TRACK_REMOVED = Symbol('TRACK_REMOVED');
22 24
 
23 25
 /**
24 26
  * Action for when a track properties were updated.
@@ -28,4 +30,4 @@ export const TRACK_REMOVED = 'TRACK_REMOVED';
28 30
  *     track: Track
29 31
  * }
30 32
  */
31
-export const TRACK_UPDATED = 'TRACK_UPDATED';
33
+export const TRACK_UPDATED = Symbol('TRACK_UPDATED');

+ 0
- 22
react/features/conference/components/ParticipantView.web.js 查看文件

@@ -1,22 +0,0 @@
1
-import { Component } from 'react';
2
-
3
-/**
4
- * Implements a React Component which depicts a specific participant's avatar
5
- * and video.
6
- */
7
-export default class ParticipantView extends Component {
8
-
9
-   /**
10
-    * Implements React's {@link Component#render()}.
11
-    *
12
-    * @inheritdoc
13
-    * @returns {ReactElement|null}
14
-    */
15
-    render() {
16
-        // FIXME ParticipantView is supposed to be platform-independent.
17
-        // Temporarily though, ParticipantView is not in use on Web but has to
18
-        // exist in order to split App, Conference, and WelcomePage out of
19
-        // index.html.
20
-        return null;
21
-    }
22
- }

+ 3
- 1
react/features/largeVideo/actionTypes.js 查看文件

@@ -1,3 +1,5 @@
1
+import { Symbol } from '../base/react';
2
+
1 3
 /**
2 4
  * Action to change the participant to be displayed in LargeVideo.
3 5
  *
@@ -7,4 +9,4 @@
7 9
  * }
8 10
  */
9 11
 export const LARGE_VIDEO_PARTICIPANT_CHANGED
10
-    = 'LARGE_VIDEO_PARTICIPANT_CHANGED';
12
+    = Symbol('LARGE_VIDEO_PARTICIPANT_CHANGED');

正在加载...
取消
保存