Skip to content

Commit d693458

Browse files
committed
fix wat state not updating.
1 parent 692bbeb commit d693458

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

state/actions/compileCode.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { saveFile } from './saveFile'
66
import { decodeBinary } from '../../utils/decodeBinary'
77
import { ref } from 'valtio'
88
import asc from "@muzamilsofi/assemblyscript/dist/asc"
9-
import { getFileExtention, getFileNamePart } from '../../utils/helpers'
9+
import { getFileExtention } from '../../utils/helpers'
1010

1111
type CompilationResult = Pick<IFile, "compiledContent" | "compiledWatContent">
1212

@@ -160,6 +160,7 @@ export const compileWat = async (file: IFile): Promise<CompilationResult> => {
160160

161161
export const compileTs = async (file: IFile): Promise<CompilationResult> => {
162162
return new Promise(async (resolve, reject) => {
163+
let result: Partial<CompilationResult> = {}
163164
const { error, stdout, stderr } = await asc.main([
164165
// Command line options
165166
file.name,
@@ -180,23 +181,15 @@ export const compileTs = async (file: IFile): Promise<CompilationResult> => {
180181
},
181182
writeFile: async (name, data: ArrayBuffer | string, baseDir) => {
182183
console.log("writeFile", { name, data, baseDir })
183-
const filename = getFileNamePart(name);
184184
const ext = getFileExtention(name);
185-
let file = state.files.find(file => file.name === filename)
186-
if (!file) {
187-
return reject(Error("No source of compiled content found!"));
188-
}
189-
190-
// TODO maybe clean? or NOT!
191-
192185
if (ext === 'wasm') {
193-
file.compiledContent = ref(data as ArrayBuffer)
186+
result.compiledContent = data as ArrayBuffer;
194187
}
195188
else if (ext === 'wat') {
196-
file.compiledWatContent = data as string;
189+
result.compiledWatContent = data as string;
197190
}
198-
if (file.compiledContent && file.compiledWatContent) {
199-
resolve({ compiledContent: file.compiledContent, compiledWatContent: file.compiledWatContent });
191+
if (result.compiledContent && result.compiledWatContent) {
192+
resolve({ ...result });
200193
}
201194
},
202195
listFiles: (dirname, baseDir) => {

0 commit comments

Comments
 (0)