remove _deffer (#3114)

* remove _deffer

Signed-off-by: Paul Tagliamonte <paul@zoo.dev>
This commit is contained in:
Paul Tagliamonte
2024-07-23 20:37:04 -04:00
committed by GitHub
parent a68748abcf
commit 22df47fa96
10 changed files with 11 additions and 33 deletions

View File

@ -177,7 +177,7 @@ const FileTreeItem = ({
codeManager.writeToFile()
kclManager.isFirstRender = true
kclManager.executeCode(true, true).then(() => {
kclManager.executeCode(true).then(() => {
kclManager.isFirstRender = false
})
} else {

View File

@ -175,7 +175,7 @@ export const ModelingMachineProvider = ({
}
store.videoElement?.pause()
kclManager.executeCode(true).then(() => {
kclManager.executeCode().then(() => {
if (engineCommandManager.engineConnection?.idleMode) return
store.videoElement?.play()

View File

@ -66,7 +66,7 @@ export const KclEditorPane = () => {
useEffect(() => {
if (typeof window === 'undefined') return
const onlineCallback = () => kclManager.executeCode(true, true)
const onlineCallback = () => kclManager.executeCode(true)
window.addEventListener('online', onlineCallback)
return () => window.removeEventListener('online', onlineCallback)
}, [])

View File

@ -177,7 +177,7 @@ export const SettingsAuthProviderBase = ({
},
'Execute AST': () => {
kclManager.isFirstRender = true
kclManager.executeCode(true, true).then(() => {
kclManager.executeCode(true).then(() => {
kclManager.isFirstRender = false
})
},

View File

@ -117,11 +117,7 @@ export class KclPlugin implements PluginValue {
}
if (!this.client.ready) return
try {
kclManager.executeCode()
} catch (e) {
console.error(e)
}
}
ensureDocUpdated() {

View File

@ -55,7 +55,7 @@ export function useSetupEngineManager(
// We only want to execute the code here that we already have set.
// Nothing else.
kclManager.isFirstRender = true
return kclManager.executeCode(true, true).then(() => {
return kclManager.executeCode(true).then(() => {
kclManager.isFirstRender = false
})
},

View File

@ -38,22 +38,6 @@ export class KclManager {
private _wasmInitFailed = true
engineCommandManager: EngineCommandManager
private _defferer = deferExecution((code: string) => {
const ast = this.safeParse(code)
if (!ast) {
this.clearAst()
return
}
try {
const fmtAndStringify = (ast: Program) =>
JSON.stringify(parse(recast(ast)))
const isAstTheSame = fmtAndStringify(ast) === fmtAndStringify(this._ast)
if (isAstTheSame) return
} catch (e) {
console.error(e)
}
this.executeAst(ast)
}, 600)
private _isExecutingCallback: (arg: boolean) => void = () => {}
private _astCallBack: (arg: Program) => void = () => {}
@ -331,10 +315,8 @@ export class KclManager {
this._cancelTokens.set(key, true)
})
}
async executeCode(force?: boolean, zoomToFit?: boolean): Promise<void> {
// If we want to force it we don't want to defer it.
if (!force) return this._defferer(codeManager.code)
async executeCode(zoomToFit?: boolean): Promise<void> {
console.log('[kcl/KclSingleton] executeCode')
const ast = this.safeParse(codeManager.code)
if (!ast) {
this.clearAst()

View File

@ -105,7 +105,7 @@ export const fileLoader: LoaderFunction = async ({
codeManager.updateCurrentFilePath(current_file_path)
codeManager.updateCodeStateEditor(code)
// We don't want to call await on execute code since we don't want to block the UI
kclManager.executeCode(true, true)
kclManager.executeCode(true)
// Set the file system manager to the project path
// So that WASM gets an updated path for operations

View File

@ -56,7 +56,7 @@ function OnboardingWithNewFile() {
next={() => {
// We do want to update both the state and editor here.
codeManager.updateCodeEditor(bracket)
kclManager.executeCode(true, true)
kclManager.executeCode(true)
next()
}}
nextText="Overwrite code and continue"

View File

@ -14,7 +14,7 @@ export default function Sketching() {
codeManager.updateCodeEditor('')
if (kclManager.engineCommandManager.engineConnection?.isReady()) {
// If the engine is ready, promptly execute the loaded code
kclManager.executeCode(true, true)
kclManager.executeCode(true)
}
}, [])