mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 21:00:40 -07:00
perf: use polymophism instead duck test
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { create, stringify } from '../../util/underscore'
|
||||
import { stringify, isFunction } from '../../util/underscore'
|
||||
import assert from '../../util/assert'
|
||||
import Context from '../../context/context'
|
||||
import ITagImpl from './itag-impl'
|
||||
@@ -21,7 +21,8 @@ export default class Tag extends Template<TagToken> implements ITemplate {
|
||||
|
||||
const impl = Tag.impls[token.name]
|
||||
assert(impl, `tag ${token.name} not found`)
|
||||
this.impl = create<ITagImplOptions, ITagImpl>(impl)
|
||||
|
||||
this.impl = Object.create(impl)
|
||||
this.impl.liquid = liquid
|
||||
if (this.impl.parse) {
|
||||
this.impl.parse(token, tokens)
|
||||
@@ -30,11 +31,7 @@ export default class Tag extends Template<TagToken> implements ITemplate {
|
||||
async render (ctx: Context) {
|
||||
const hash = await Hash.create(this.token.args, ctx)
|
||||
const impl = this.impl
|
||||
if (typeof impl.render !== 'function') {
|
||||
return ''
|
||||
}
|
||||
const html = await impl.render(ctx, hash)
|
||||
return stringify(html)
|
||||
return isFunction(impl.render) ? stringify(await impl.render(ctx, hash)) : ''
|
||||
}
|
||||
static register (name: string, tag: ITagImplOptions) {
|
||||
Tag.impls[name] = tag
|
||||
|
||||
@@ -4,8 +4,8 @@ import Context from '../context/context'
|
||||
|
||||
export default class Value {
|
||||
private strictFilters: boolean
|
||||
initial: string
|
||||
filters: Array<Filter> = []
|
||||
private initial: string
|
||||
private filters: Array<Filter> = []
|
||||
|
||||
/**
|
||||
* @param str value string, like: "i have a dream | truncate: 3
|
||||
|
||||
Reference in New Issue
Block a user