Explorar el Código

Switch appendFilesToHead to use template strings to make it clearer

Rich hace 7 años
padre
commit
855b1636dc
Se han modificado 2 ficheros con 16 adiciones y 29 borrados
  1. 8
    18
      autoHeightWebView/index.android.js
  2. 8
    11
      autoHeightWebView/index.ios.js

+ 8
- 18
autoHeightWebView/index.android.js Ver fichero

@@ -216,24 +216,14 @@ export default class AutoHeightWebView extends PureComponent {
216 216
     if (!files) {
217 217
       return script;
218 218
     }
219
-    for (let file of files) {
220
-      script =
221
-        `
222
-                var link  = document.createElement('link');
223
-                link.rel  = '` +
224
-        file.rel +
225
-        `';
226
-                link.type = '` +
227
-        file.type +
228
-        `';
229
-                link.href = '` +
230
-        file.href +
231
-        `';
232
-                document.head.appendChild(link);
233
-                ` +
234
-        script;
235
-    }
236
-    return script;
219
+    return files.reduceRight((file, combinedScript) => `
220
+      var link  = document.createElement('link');
221
+      link.rel  = '${file.rel}';
222
+      link.type = '${file.type}';
223
+      link.href = '${file.href}';
224
+      document.head.appendChild(link);
225
+      ${combinedScript}
226
+    `, script)
237 227
   }
238 228
 
239 229
   appendStylesToHead(styles, script) {

+ 8
- 11
autoHeightWebView/index.ios.js Ver fichero

@@ -77,17 +77,14 @@ export default class AutoHeightWebView extends PureComponent {
77 77
         if (!files) {
78 78
             return script;
79 79
         }
80
-        for (let file of files) {
81
-            script =
82
-                `
83
-                var link  = document.createElement('link');
84
-                link.rel  = '` + file.rel + `';
85
-                link.type = '` + file.type + `';
86
-                link.href = '` + file.href + `';
87
-                document.head.appendChild(link);
88
-                `+ script;
89
-        }
90
-        return script;
80
+        return files.reduceRight((file, combinedScript) => `
81
+          var link  = document.createElement('link');
82
+          link.rel  = '${file.rel}';
83
+          link.type = '${file.type}';
84
+          link.href = '${file.href}';
85
+          document.head.appendChild(link);
86
+          ${combinedScript}
87
+        `, script)
91 88
     }
92 89
 
93 90
     appendStylesToHead(styles, script) {