Fixed auto compile

pull/1339/head
ioedeveloper 4 years ago
parent 39788c060c
commit af8bc1addf
  1. 2
      apps/remix-ide/src/app/tabs/compile-tab.js
  2. 43
      libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx

@ -312,6 +312,8 @@ class CompileTab extends ViewPlugin {
}
onDeactivation () {
this.editor.event.unregister('contentChanged')
this.editor.event.unregister('sessionSwitched')
this.editor.event.unregister('contentChanged', this.data.eventHandlers.onContentChanged)
this.compiler.event.unregister('loadingCompiler', this.data.eventHandlers.onLoadingCompiler)
this.compiler.event.unregister('compilerLoaded', this.data.eventHandlers.onCompilerLoaded)

@ -44,12 +44,17 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
_updateVersionSelector()
}
})
const currentFileName = config.get('currentFile')
currentFile(currentFileName)
listenToEvents()
}, [])
useEffect(() => {
if (compileTabLogic && compileTabLogic.compiler) {
compileTabLogic.compiler.event.register('compilerLoaded', compilerLoaded)
console.log(`${config.get('autoCompile') || false}`)
setState(prevState => {
return {
...prevState,
@ -173,19 +178,6 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
return extention.toLowerCase() === 'sol' || extention.toLowerCase() === 'yul'
}
const deactivate = () => {
// deactivate editor listeners
editor.event.unregister('contentChanged')
editor.event.unregister('sessionSwitched')
}
const activate = () => {
const currentFileName = config.get('currentFile')
currentFile(currentFileName)
listenToEvents()
}
const listenToEvents = () => {
editor.event.register('sessionSwitched', () => {
if (!compileIcon.current) return
@ -231,7 +223,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
// _disableCompileBtn(false)
compileIcon.current.setAttribute('title', '')
compileIcon.current.classList.remove('remixui_spinningIcon')
if (state.autoCompile) compileIfAutoCompileOn()
if (state.autoCompile) compile()
})
compileTabLogic.compiler.event.register('compilationFinished', (success, data, source) => {
@ -243,21 +235,16 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
}
const scheduleCompilation = () => {
if (!state.autoCompile) return
const autoCompile = config.get('autoCompile')
if (!autoCompile) return
if (state.compileTimeout) window.clearTimeout(state.compileTimeout)
const compileTimeout = window.setTimeout(() => compileIfAutoCompileOn(), state.timeout)
const compileTimeout = window.setTimeout(() => autoCompile && compile(), state.timeout)
setState(prevState => {
return { ...prevState, compileTimeout }
})
}
const compileIfAutoCompileOn = () => {
if (config.get('autoCompile')) {
compile()
}
}
const compile = () => {
const currentFile = config.get('currentFile')
@ -390,7 +377,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
} else {
compileTabLogic.setRuns(200)
}
compileIfAutoCompileOn()
state.autoCompile && compile()
setState(prevState => {
return { ...prevState, optimise: checked }
})
@ -400,7 +387,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
const runs = e.target.value
compileTabLogic.setRuns(parseInt(runs))
compileIfAutoCompileOn()
state.autoCompile && compile()
setState(prevState => {
return { ...prevState, runs }
})
@ -410,7 +397,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
const checked = e.target.checked
config.set('hideWarnings', checked)
compileIfAutoCompileOn()
state.autoCompile && compile()
setState(prevState => {
return { ...prevState, hideWarnings: checked }
})
@ -427,7 +414,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
const handleLanguageChange = (value) => {
compileTabLogic.setLanguage(value)
compileIfAutoCompileOn()
state.autoCompile && compile()
setState(prevState => {
return { ...prevState, language: value }
})
@ -439,7 +426,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
v = null
}
compileTabLogic.setEvmVersion(v)
compileIfAutoCompileOn()
state.autoCompile && compile()
setState(prevState => {
return { ...prevState, evmVersion: value }
})
@ -533,7 +520,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
<button id="compileBtn" data-id="compilerContainerCompileBtn" className="btn btn-primary btn-block remixui_disabled mt-3" title="Compile" onClick={compile} disabled={!state.compiledFileName || (state.compiledFileName && !isSolFileSelected(state.compiledFileName))}>
<span>
<i ref={warningIcon} title="Compilation Slow" style={{ visibility: 'hidden' }} className="remixui_warnCompilationSlow fas fa-exclamation-triangle" aria-hidden="true"></i>
<i ref={compileIcon} className="fas fa-sync remixui_icon" aria-hidden="true"></i>
{ warningIcon.current && warningIcon.current.style.visibility === 'hidden' && <i ref={compileIcon} className="fas fa-sync remixui_icon" aria-hidden="true"></i> }
Compile { state.compiledFileName || '<no file selected>' }
</span>
</button>

Loading…
Cancel
Save