mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-17 05:10:40 -07:00
perf: make the most of streamed rendering
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
export interface Emitter {
|
||||
/**
|
||||
* Write a html value into emitter
|
||||
* @param html string, Drop or other primitive value
|
||||
*/
|
||||
write (html: any): void;
|
||||
/**
|
||||
* Notify the emitter render has ended
|
||||
*/
|
||||
end (): void;
|
||||
/**
|
||||
* Collect rendered string value immediately
|
||||
*/
|
||||
collect (): string;
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import { KeepingTypeEmitter } from '../emitters/keeping-type-emitter'
|
||||
export class Render {
|
||||
public renderTemplatesToNodeStream (templates: Template[], ctx: Context): NodeJS.ReadableStream {
|
||||
const emitter = new StreamedEmitter()
|
||||
toThenable(this.renderTemplates(templates, ctx, emitter))
|
||||
toThenable(this.renderTemplates(templates, ctx, emitter)).then(() => emitter.end())
|
||||
return emitter.stream
|
||||
}
|
||||
public * renderTemplates (templates: Template[], ctx: Context, emitter?: Emitter): IterableIterator<any> {
|
||||
@@ -29,6 +29,6 @@ export class Render {
|
||||
throw err
|
||||
}
|
||||
}
|
||||
return emitter.end()
|
||||
return emitter.buffer
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user