Browse Source

[RN] Extract a function

master
Saúl Ibarra Corretgé 7 years ago
parent
commit
9833965a27
1 changed files with 24 additions and 14 deletions
  1. 24
    14
      react/features/mobile/external-api/middleware.js

+ 24
- 14
react/features/mobile/external-api/middleware.js View File

40
 
40
 
41
         // The (externa API) event's name is the string representation of the
41
         // The (externa API) event's name is the string representation of the
42
         // (redux) action's type.
42
         // (redux) action's type.
43
-        let name = type.toString();
44
-
45
-        // XXX We are using Symbol for (redux) action types at the time of this
46
-        // writing so the Symbol's description should be used.
47
-        if (name.startsWith('Symbol(') && name.endsWith(')')) {
48
-            name = name.slice(7, -1);
49
-        }
50
-
51
-        // The polyfill es6-symbol that we use does not appear to comply with
52
-        // the Symbol standard and, merely, adds @@ at the beginning of the
53
-        // description.
54
-        if (name.startsWith('@@')) {
55
-            name = name.slice(2);
56
-        }
43
+        const name = _getSymbolDescription(type);
57
 
44
 
58
         _sendEvent(store, name, data);
45
         _sendEvent(store, name, data);
59
         break;
46
         break;
63
     return result;
50
     return result;
64
 });
51
 });
65
 
52
 
53
+/**
54
+ * Gets the description of a specific <tt>Symbol</tt>.
55
+ *
56
+ * @param {Symbol} symbol - The <tt>Symbol</tt> to retrieve the description of.
57
+ * @private
58
+ * @returns {string} The description of <tt>symbol</tt>.
59
+ */
60
+function _getSymbolDescription(symbol: Symbol) {
61
+    let description = symbol.toString();
62
+
63
+    if (description.startsWith('Symbol(') && description.endsWith(')')) {
64
+        description = description.slice(7, -1);
65
+    }
66
+
67
+    // The polyfill es6-symbol that we use does not appear to comply with the
68
+    // Symbol standard and, merely, adds @@ at the beginning of the description.
69
+    if (description.startsWith('@@')) {
70
+        description = description.slice(2);
71
+    }
72
+
73
+    return description;
74
+}
75
+
66
 /**
76
 /**
67
  * Sends a specific event to the native counterpart of the External API. Native
77
  * Sends a specific event to the native counterpart of the External API. Native
68
  * apps may listen to such events via the mechanisms provided by the (native)
78
  * apps may listen to such events via the mechanisms provided by the (native)

Loading…
Cancel
Save