MCPcopy Create free account
hub / github.com/Effect-TS/effect / text

Function text

packages/platform/browser/src/BrowserHttpClient.ts:285–320  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

283
284 _textEffect: Effect.Effect<string, E> | undefined
285 get text(): Effect.Effect<string, E> {
286 if (this._textEffect) {
287 return this._textEffect
288 }
289 if (this.source.responseType === "arraybuffer") {
290 return this._textEffect = this.arrayBuffer.pipe(
291 Effect.map((buffer) => new TextDecoder().decode(buffer)),
292 Effect.cached,
293 Effect.runSync
294 )
295 }
296 return this._textEffect = Effect.callback<string, E>((resume) => {
297 if (this.source.readyState === 4) {
298 resume(Effect.succeed(this.source.responseText))
299 return
300 }
301
302 const onReadyStateChange = () => {
303 if (this.source.readyState === 4) {
304 resume(Effect.succeed(this.source.responseText))
305 }
306 }
307 const onError = () => {
308 resume(Effect.fail(this.onError(this.source.statusText)))
309 }
310 this.source.addEventListener("readystatechange", onReadyStateChange)
311 this.source.addEventListener("error", onError)
312 return Effect.sync(() => {
313 this.source.removeEventListener("readystatechange", onReadyStateChange)
314 this.source.removeEventListener("error", onError)
315 })
316 }).pipe(
317 Effect.cached,
318 Effect.runSync
319 )
320 }
321
322 get json(): Effect.Effect<Schema.Json, E> {
323 return Effect.flatMap(this.text, (text) =>

Callers

nothing calls this directly

Calls 8

pipeMethod · 0.65
addEventListenerMethod · 0.65
removeEventListenerMethod · 0.65
resumeFunction · 0.50
mapMethod · 0.45
decodeMethod · 0.45
succeedMethod · 0.45
syncMethod · 0.45

Tested by

no test coverage detected