Skip to content

Commit

Permalink
fix: onChange无法触发
Browse files Browse the repository at this point in the history
  • Loading branch information
1360151219 committed Oct 10, 2023
1 parent fb4c3ed commit c684f94
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
6 changes: 2 additions & 4 deletions packages/design/components/MonacoEditor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import InitPlugin from './plugins/initPlugin';
import { useControlled, useDebounce } from '../hooks';
import Preview from './components/Preview';
import { useWorkers } from './workers/useWorkers';
import { omit } from '../utils/omit';
interface MocacoEditorProps extends EditorProps {
modules?: TabsItemProps[];
}
Expand Down Expand Up @@ -45,10 +46,7 @@ const MonacoEditor = (props: MocacoEditorProps) => {
InitPlugin(monaco);
};

// todo: 这里没有处罚
const handleEditorChange: OnChange = useDebounce((value, e) => {
console.log(111);

onChange?.(value ?? '', e);
compilerWorker.postMessage({
type: MessageChangeType.Compile,
Expand All @@ -70,7 +68,7 @@ const MonacoEditor = (props: MocacoEditorProps) => {
theme={theme}
onChange={handleEditorChange}
onMount={handleEditorDidMount}
{...rest}
{...omit(rest, ['value', 'onChange'])}
// beforeMount={handleEditorWillMount}
// onValidate={handleEditorValidation}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,9 @@ const babelTransform = (

self.addEventListener('message', (e) => {
const { type, data } = e.data;
console.log(e);

if (type === MessageChangeType.Compile) {
// 发送结果回主线程

self.postMessage({
type,
data: babelTransform(data.filename, data.code, data.modules),
Expand Down
15 changes: 15 additions & 0 deletions packages/design/components/utils/omit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export function omit<T extends Record<string, any>, K extends keyof T>(
obj: T,
keys: K[]
): Omit<T, K> {
const result = { ...obj };

keys.forEach((key) => {
// eslint-disable-next-line no-prototype-builtins
if (result.hasOwnProperty(key)) {
delete result[key];
}
});

return result;
}

0 comments on commit c684f94

Please sign in to comment.