Skip to content

Commit

Permalink
解决异常编译
Browse files Browse the repository at this point in the history
  • Loading branch information
239573049 committed Apr 11, 2024
1 parent f9c6a67 commit 04ea495
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 56 deletions.
37 changes: 0 additions & 37 deletions web/src/userWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,43 +25,6 @@ self.MonacoEnvironment = {
}
};

monaco.languages.register({ id: 'javascript' });

monaco.languages.setLanguageConfiguration('javascript', {
indentationRules: {
increaseIndentPattern: /^(.*\bcase\b\s*.*|.*\bdefault\b\s*.*)$/,
decreaseIndentPattern: /^\s*[\}\]].*$/,
},
folding: {
markers: {
start: new RegExp('^\\s*//\\s*#?region\\b'),
end: new RegExp('^\\s*//\\s*#?endregion\\b'),
},
},
brackets: [
['{', '}'],
['[', ']'],
['(', ')'],
],
wordPattern: /(-?\d*\.\d\w*)|([^`~!@#%^&*()=+[{\]}\\|;:'",.<>\/?\s]+)/g,
});
const formatCommand = {
id: 'format-command',
label: 'Format',
keybindings: [
monaco.KeyMod.chord(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyK, monaco.KeyCode.KeyF) // 绑定到 Ctrl + K, Ctrl + F
],
run: function (editor: any) {
// 格式化代码逻辑
const model = editor.getModel();
const range = model.getFullModelRange();
editor.executeEdits('format-command', [{
range: range,
text: '格式化代码'
}]);
}
};

monaco.languages.typescript.javascriptDefaults.setCompilerOptions({
target: monaco.languages.typescript.ScriptTarget.ES2015,
allowNonTsExtensions: true
Expand Down
38 changes: 19 additions & 19 deletions web/src/utils/IndexedDBWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ class IndexedDBWrapper {
return new Promise((resolve, reject) => {
const request = indexedDB.open(this.dbName, this.dbVersion);

request.onupgradeneeded = (event: IDBVersionChangeEvent) => {
request.onupgradeneeded = () => {
this.db = request.result;
if (!this.db.objectStoreNames.contains(this.storeName)) {
this.db.createObjectStore(this.storeName, { keyPath: 'id', autoIncrement: true });
}
};

request.onsuccess = (event: Event) => {
request.onsuccess = () => {
this.db = request.result;
resolve(this.db);
};

request.onerror = (event: Event) => {
request.onerror = () => {
reject(request.error);
};
});
Expand All @@ -44,11 +44,11 @@ class IndexedDBWrapper {
const store = transaction.objectStore(this.storeName);
const request = store.add(data);

request.onsuccess = (event: Event) => {
request.onsuccess = () => {
resolve(request.result as number);
};

request.onerror = (event: Event) => {
request.onerror = () => {
reject(request.error);
};
});
Expand All @@ -60,11 +60,11 @@ class IndexedDBWrapper {
const store = transaction.objectStore(this.storeName);
const request = store.get(id);

request.onsuccess = (event: Event) => {
request.onsuccess = () => {
resolve(request.result as T);
};

request.onerror = (event: Event) => {
request.onerror = () => {
reject(request.error);
};
});
Expand All @@ -76,11 +76,11 @@ class IndexedDBWrapper {
const store = transaction.objectStore(this.storeName);
const request = store.getAll();

request.onsuccess = (event: Event) => {
request.onsuccess = () => {
resolve(request.result as T[]);
};

request.onerror = (event: Event) => {
request.onerror = () => {
reject(request.error);
};
});
Expand All @@ -92,11 +92,11 @@ class IndexedDBWrapper {
const store = transaction.objectStore(this.storeName);
const request = store.put(data, id);

request.onsuccess = (event: Event) => {
request.onsuccess = () => {
resolve();
};

request.onerror = (event: Event) => {
request.onerror = () => {
reject(request.error);
};
});
Expand All @@ -109,21 +109,21 @@ class IndexedDBWrapper {
const store = transaction.objectStore(this.storeName);
const request = store.get(id);

request.onsuccess = (event: Event) => {
request.onsuccess = () => {
const oldData = request.result;
const newData = { ...oldData, ...data };
const requestUpdate = store.put(newData, id);

requestUpdate.onsuccess = (event: Event) => {
requestUpdate.onsuccess = () => {
resolve();
};

requestUpdate.onerror = (event: Event) => {
requestUpdate.onerror = () => {
reject(requestUpdate.error);
};
};

request.onerror = (event: Event) => {
request.onerror = () => {
reject(request.error);
};
});
Expand All @@ -136,11 +136,11 @@ class IndexedDBWrapper {
const store = transaction.objectStore(this.storeName);
const request = store.delete(id);

request.onsuccess = (event: Event) => {
request.onsuccess = () => {
resolve();
};

request.onerror = (event: Event) => {
request.onerror = () => {
reject(request.error);
};
});
Expand All @@ -152,11 +152,11 @@ class IndexedDBWrapper {
const store = transaction.objectStore(this.storeName);
const request = store.delete(id);

request.onsuccess = (event: Event) => {
request.onsuccess = () => {
resolve();
};

request.onerror = (event: Event) => {
request.onerror = () => {
reject(request.error);
};
});
Expand Down

0 comments on commit 04ea495

Please sign in to comment.