diff --git a/src/browser/init.ts b/src/browser/init.ts index 42c792c1..f3cb9fda 100644 --- a/src/browser/init.ts +++ b/src/browser/init.ts @@ -1,13 +1,7 @@ import '@stencila/components' -import { - codeChunk, - Node, - softwareEnvironment, - softwareSession, - SoftwareSession -} from '@stencila/schema' -import { ClientType } from '../base/Client' +import { CodeChunk, softwareSession, SoftwareSession } from '@stencila/schema' import { BaseExecutor } from '../base/BaseExecutor' +import { ClientType } from '../base/Client' import { HttpAddress } from '../base/Transports' import { discover } from '../http/discover' import { HttpClient } from '../http/HttpClient' @@ -16,20 +10,21 @@ import { WebSocketClient } from '../ws/WebSocketClient' let executor: BaseExecutor let session: null | SoftwareSession = null -const executeCodeChunk = async (text: string): Promise => { - const code = codeChunk(text, { programmingLanguage: 'python' }) - +const executeCodeChunk = async (codeChunk: CodeChunk): Promise => { if (session === null) { session = await executor.begin(softwareSession()) } - return executor.execute(code, session) + return executor.execute(codeChunk) } -const executeHandler = (text: string): Promise => - executeCodeChunk(text) - .then(res => console.log(res)) - .catch(err => console.error(err)) +const executeHandler = (codeChunk: CodeChunk): Promise => + executeCodeChunk(codeChunk) + .then(res => res) + .catch(err => { + console.error(err) + return codeChunk + }) const setCodeChunkProps = (): void => { const codeChunks = document.querySelectorAll('stencila-code-chunk')