Skip to content

Commit

Permalink
fix(Browser): Update browser execute function
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-ketch committed Oct 28, 2019
1 parent 4ae78d6 commit ebac2a3
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions src/browser/init.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -16,20 +10,21 @@ import { WebSocketClient } from '../ws/WebSocketClient'
let executor: BaseExecutor
let session: null | SoftwareSession = null

const executeCodeChunk = async (text: string): Promise<Node> => {
const code = codeChunk(text, { programmingLanguage: 'python' })

const executeCodeChunk = async (codeChunk: CodeChunk): Promise<CodeChunk> => {
if (session === null) {
session = await executor.begin(softwareSession())
}

return executor.execute(code, session)
return executor.execute(codeChunk)
}

const executeHandler = (text: string): Promise<void> =>
executeCodeChunk(text)
.then(res => console.log(res))
.catch(err => console.error(err))
const executeHandler = (codeChunk: CodeChunk): Promise<CodeChunk> =>
executeCodeChunk(codeChunk)
.then(res => res)
.catch(err => {
console.error(err)
return codeChunk
})

const setCodeChunkProps = (): void => {
const codeChunks = document.querySelectorAll('stencila-code-chunk')
Expand Down

0 comments on commit ebac2a3

Please sign in to comment.