소스 검색

Switch appendFilesToHead to use template strings to make it clearer

Rich 6 년 전
부모
커밋
855b1636dc
2개의 변경된 파일16개의 추가작업 그리고 29개의 파일을 삭제
  1. 8
    18
      autoHeightWebView/index.android.js
  2. 8
    11
      autoHeightWebView/index.ios.js

+ 8
- 18
autoHeightWebView/index.android.js 파일 보기

@@ -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 파일 보기

@@ -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) {