(json:string)
| 127 | } |
| 128 | |
| 129 | handleEvent(json:string) { |
| 130 | let data = JSON.parse(json); |
| 131 | |
| 132 | // Events are expected to be objects that have a type property |
| 133 | // if they aren't, we toss the event out |
| 134 | if(typeof data !== "object" || data.type === undefined) { |
| 135 | console.error("Got invalid JSON event: " + json); |
| 136 | return; |
| 137 | } |
| 138 | |
| 139 | if(data.type === "event") { |
| 140 | if(!this.evaluation) return; |
| 141 | // console.info("EVENT", json); |
| 142 | let scopes = ["event"]; |
| 143 | let actions = []; |
| 144 | for(let insert of data.insert) { |
| 145 | let [e, a, v] = insert; |
| 146 | // @TODO: this is a hack to deal with external ids. We should really generate |
| 147 | // a local id for them |
| 148 | if(e[0] === "⍦") e = ids.get([e]); |
| 149 | if(v[0] === "⍦") v = ids.get([v]); |
| 150 | actions.push(new ActionImplementations["+="]("event", e, a, v, "event", scopes)); |
| 151 | } |
| 152 | this.evaluation.executeActions(actions); |
| 153 | } else if(data.type === "close") { |
| 154 | if(!this.evaluation) return; |
| 155 | this.evaluation.close(); |
| 156 | this.evaluation = undefined; |
| 157 | } else if(data.type === "parse") { |
| 158 | let {results, errors}: {results: any, errors: any[]} = parser.parseDoc(data.code || "", "user"); |
| 159 | let {text, spans, extraInfo} = results; |
| 160 | let build = builder.buildDoc(results); |
| 161 | let {blocks, errors: buildErrors} = build; |
| 162 | results.code = data.code; |
| 163 | this.lastParse = results; |
| 164 | this.lastParse.documentId = data.documentId; |
| 165 | for(let error of buildErrors) { |
| 166 | error.injectSpan(spans, extraInfo); |
| 167 | } |
| 168 | this.send(JSON.stringify({type: "parse", generation: data.generation, text, spans, extraInfo, css: this.lastCss + this.enabledCss()})); |
| 169 | } else if(data.type === "eval") { |
| 170 | let parse = this.lastParse; |
| 171 | if(config.multiDoc) { |
| 172 | let code = ""; |
| 173 | let documents = eveSource.fetchAll("root"); |
| 174 | let css = ""; |
| 175 | let currentCss = ""; |
| 176 | for(let documentId in documents) { |
| 177 | code += `# !!! ${documentId} !!! \n`; |
| 178 | code += documents[documentId] + "\n\n"; |
| 179 | |
| 180 | if(this.lastParse && documentId !== this.lastParse.documentId) { |
| 181 | css += this.enabledCss(documents[documentId]) + "\n\n"; |
| 182 | } else { |
| 183 | currentCss = this.enabledCss(documents[documentId]) + "\n\n"; |
| 184 | } |
| 185 | } |
| 186 |
nothing calls this directly
no test coverage detected