mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 20:30:39 -07:00
pref: remove await/async from internal async calls
This commit is contained in:
+4
-15
@@ -4,26 +4,15 @@ import { ITemplate } from '../template/itemplate'
|
||||
import { Emitter } from './emitter'
|
||||
|
||||
export class Render {
|
||||
public async renderTemplates (templates: ITemplate[], ctx: Context, emitter = new Emitter()): Promise<string> {
|
||||
public * renderTemplates (templates: ITemplate[], ctx: Context, emitter = new Emitter()): IterableIterator<string> {
|
||||
for (const tpl of templates) {
|
||||
try {
|
||||
const html = await tpl.render(ctx, emitter)
|
||||
const html = yield tpl.render(ctx, emitter)
|
||||
html && emitter.write(html)
|
||||
if (emitter.break || emitter.continue) break
|
||||
} catch (e) {
|
||||
throw RenderError.is(e) ? e : new RenderError(e, tpl)
|
||||
}
|
||||
}
|
||||
return emitter.html
|
||||
}
|
||||
public renderTemplatesSync (templates: ITemplate[], ctx: Context, emitter = new Emitter()): string {
|
||||
for (const tpl of templates) {
|
||||
try {
|
||||
const html = tpl.renderSync(ctx, emitter)
|
||||
html && !(html instanceof Promise) && emitter.write(html)
|
||||
if (emitter.break || emitter.continue) break
|
||||
} catch (e) {
|
||||
throw RenderError.is(e) ? e : new RenderError(e, tpl)
|
||||
const err = RenderError.is(e) ? e : new RenderError(e, tpl)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
return emitter.html
|
||||
|
||||
Reference in New Issue
Block a user