From d6934584215d5a33092f876a83007b7edbebe70c Mon Sep 17 00:00:00 2001 From: muzam1l Date: Wed, 1 Feb 2023 21:58:25 +0530 Subject: [PATCH] fix wat state not updating. --- state/actions/compileCode.ts | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/state/actions/compileCode.ts b/state/actions/compileCode.ts index 5c4826c..296bfeb 100644 --- a/state/actions/compileCode.ts +++ b/state/actions/compileCode.ts @@ -6,7 +6,7 @@ import { saveFile } from './saveFile' import { decodeBinary } from '../../utils/decodeBinary' import { ref } from 'valtio' import asc from "@muzamilsofi/assemblyscript/dist/asc" -import { getFileExtention, getFileNamePart } from '../../utils/helpers' +import { getFileExtention } from '../../utils/helpers' type CompilationResult = Pick @@ -160,6 +160,7 @@ export const compileWat = async (file: IFile): Promise => { export const compileTs = async (file: IFile): Promise => { return new Promise(async (resolve, reject) => { + let result: Partial = {} const { error, stdout, stderr } = await asc.main([ // Command line options file.name, @@ -180,23 +181,15 @@ export const compileTs = async (file: IFile): Promise => { }, writeFile: async (name, data: ArrayBuffer | string, baseDir) => { console.log("writeFile", { name, data, baseDir }) - const filename = getFileNamePart(name); const ext = getFileExtention(name); - let file = state.files.find(file => file.name === filename) - if (!file) { - return reject(Error("No source of compiled content found!")); - } - - // TODO maybe clean? or NOT! - if (ext === 'wasm') { - file.compiledContent = ref(data as ArrayBuffer) + result.compiledContent = data as ArrayBuffer; } else if (ext === 'wat') { - file.compiledWatContent = data as string; + result.compiledWatContent = data as string; } - if (file.compiledContent && file.compiledWatContent) { - resolve({ compiledContent: file.compiledContent, compiledWatContent: file.compiledWatContent }); + if (result.compiledContent && result.compiledWatContent) { + resolve({ ...result }); } }, listFiles: (dirname, baseDir) => {