-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
150 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import Observable from 'next/dist/compiled/zen-observable' | ||
|
||
export default class RenderResult { | ||
_response: string | Observable<string> | ||
_dynamic: boolean | ||
|
||
constructor(response: string | Observable<string>, dynamic: boolean) { | ||
this._response = response | ||
this._dynamic = dynamic | ||
} | ||
|
||
async toUnchunkedString(): Promise<string> { | ||
if (typeof this._response === 'string') { | ||
return this._response | ||
} | ||
const chunks: string[] = [] | ||
await this._response.forEach((chunk) => chunks.push(chunk)) | ||
return chunks.join('') | ||
} | ||
|
||
forEach(fn: (chunk: string) => void): Promise<void> { | ||
if (typeof this._response === 'string') { | ||
const value = this._response | ||
return new Promise((resolve) => { | ||
fn(value) | ||
resolve() | ||
}) | ||
} | ||
return this._response.forEach(fn) | ||
} | ||
|
||
isDynamic(): boolean { | ||
return this._dynamic | ||
} | ||
|
||
static fromStatic(value: string): RenderResult { | ||
return new RenderResult(value, false) | ||
} | ||
|
||
static empty = RenderResult.fromStatic('') | ||
} |
Oops, something went wrong.