(client:EveClient)
| 454 | export let client = new EveClient(); |
| 455 | |
| 456 | function initIDE(client:EveClient) { |
| 457 | let ide = client.ide; |
| 458 | ide.onChange = (ide:IDE) => { |
| 459 | let generation = ide.generation; |
| 460 | let md = ide.editor.toMarkdown(); |
| 461 | console.groupCollapsed(`SENT ${generation}`); |
| 462 | console.info(md); |
| 463 | console.groupEnd(); |
| 464 | client.send({scope: "root", type: "parse", generation, code: md, documentId: ide.documentId}); |
| 465 | } |
| 466 | ide.onEval = (ide:IDE, persist) => { |
| 467 | client.send({type: "eval", persist, documentId: ide.documentId}); |
| 468 | } |
| 469 | ide.onLoadFile = (ide, documentId, code) => { |
| 470 | client.send({type: "close"}); |
| 471 | client.send({scope: "root", type: "parse", code, documentId: ide.documentId}) |
| 472 | client.send({type: "eval", persist: false, documentId: ide.documentId}); |
| 473 | |
| 474 | let url = `${location.pathname}#${documentId}`; |
| 475 | let currentHashChunks = location.hash.split("#").slice(1); |
| 476 | let curId = currentHashChunks[0]; |
| 477 | if(curId && curId[curId.length - 1] === "/") curId = curId.slice(0, -1); |
| 478 | if(curId === documentId && currentHashChunks[1]) { |
| 479 | url += "/#" + currentHashChunks[1]; |
| 480 | } |
| 481 | |
| 482 | history.pushState({}, "", url + location.search); |
| 483 | analyticsEvent("load-document", documentId); |
| 484 | } |
| 485 | |
| 486 | ide.onSaveDocument = (ide, documentId, code) => { |
| 487 | client.save(documentId, code); |
| 488 | } |
| 489 | |
| 490 | ide.onTokenInfo = (ide, tokenId) => { |
| 491 | client.send({type: "tokenInfo", tokenId}); |
| 492 | } |
| 493 | |
| 494 | let cache = window["_workspaceCache"]; |
| 495 | for(let workspace in cache || {}) { |
| 496 | ide.loadWorkspace(workspace, cache[workspace]); |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | function changeDocument() { |
| 501 | if(!client.showIDE) return; |
no test coverage detected