()
| 170 | |
| 171 | _textEffect: Effect.Effect<string, E> | undefined |
| 172 | get text(): Effect.Effect<string, E> { |
| 173 | if (this._textEffect) { |
| 174 | return this._textEffect |
| 175 | } |
| 176 | return this._textEffect = Effect.async<string, E>((resume) => { |
| 177 | if (this.source.readyState === 4) { |
| 178 | resume(Effect.succeed(this.source.responseText)) |
| 179 | return |
| 180 | } |
| 181 | |
| 182 | const onReadyStateChange = () => { |
| 183 | if (this.source.readyState === 4) { |
| 184 | resume(Effect.succeed(this.source.responseText)) |
| 185 | } |
| 186 | } |
| 187 | const onError = () => { |
| 188 | resume(Effect.fail(this.onError(this.source.statusText))) |
| 189 | } |
| 190 | this.source.addEventListener("readystatechange", onReadyStateChange) |
| 191 | this.source.addEventListener("error", onError) |
| 192 | return Effect.sync(() => { |
| 193 | this.source.removeEventListener("readystatechange", onReadyStateChange) |
| 194 | this.source.removeEventListener("error", onError) |
| 195 | }) |
| 196 | }).pipe( |
| 197 | Effect.cached, |
| 198 | Effect.runSync |
| 199 | ) |
| 200 | } |
| 201 | |
| 202 | get json(): Effect.Effect<unknown, E> { |
| 203 | return Effect.tryMap(this.text, { |
nothing calls this directly
no test coverage detected