soiz1 commited on
Commit
db39eac
·
verified ·
1 Parent(s): 12f3fe8

Update src/components/loader/tw-progress-monitor.js

Browse files
src/components/loader/tw-progress-monitor.js CHANGED
@@ -1,6 +1,3 @@
1
- // This file implements some extremely terrible tricks to monitor project loading progress.
2
- // Please don't use this as a reference for "good JS code"
3
-
4
  let total = 0;
5
  let complete = 0;
6
 
@@ -54,7 +51,7 @@ const setState = newState => {
54
  export const fetchWithProgress = url => {
55
  setState(1);
56
  return new Promise((resolve, reject) => {
57
- // fetch() does not support progress, so we use XMLHttpRequest
58
  const xhr = new XMLHttpRequest();
59
  xhr.responseType = 'blob';
60
  xhr.onload = () => {
@@ -75,7 +72,7 @@ export const fetchWithProgress = url => {
75
  });
76
  };
77
 
78
- // Scratch uses fetch() to download the project JSON, so we override it to monitor when the project is being downloaded.
79
  const originalFetch = window.fetch;
80
  window.fetch = (url, opts) => {
81
  const isGET = typeof opts === 'object' && opts && opts.method === 'GET';
@@ -86,6 +83,7 @@ window.fetch = (url, opts) => {
86
  return originalFetch(url, opts);
87
  };
88
 
 
89
  const handleWorkerMessage = e => {
90
  const data = e.data;
91
  if (Array.isArray(data)) {
 
 
 
 
1
  let total = 0;
2
  let complete = 0;
3
 
 
51
  export const fetchWithProgress = url => {
52
  setState(1);
53
  return new Promise((resolve, reject) => {
54
+ // XMLHttpRequestの進行状況処理
55
  const xhr = new XMLHttpRequest();
56
  xhr.responseType = 'blob';
57
  xhr.onload = () => {
 
72
  });
73
  };
74
 
75
+ // fetchのオーバーライド
76
  const originalFetch = window.fetch;
77
  window.fetch = (url, opts) => {
78
  const isGET = typeof opts === 'object' && opts && opts.method === 'GET';
 
83
  return originalFetch(url, opts);
84
  };
85
 
86
+ // Web Workerのメッセージ処理
87
  const handleWorkerMessage = e => {
88
  const data = e.data;
89
  if (Array.isArray(data)) {