()
| 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) => |
nothing calls this directly
no test coverage detected