Skip to content

Commit

Permalink
refactor: IDrop interface => abstract method
Browse files Browse the repository at this point in the history
  • Loading branch information
harttle committed Feb 27, 2019
1 parent d5b9916 commit b69c3a3
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/drop/blank-drop.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { isNil, isString } from '../util/underscore'
import { isDrop } from '../drop/idrop'
import { Drop } from '../drop/drop'
import { EmptyDrop } from '../drop/empty-drop'

export class BlankDrop extends EmptyDrop {
equals (value: any) {
if (value === false) return true
if (isNil(isDrop(value) ? value.valueOf() : value)) return true
if (isNil(value instanceof Drop ? value.valueOf() : value)) return true
if (isString(value)) return /^\s*$/.test(value)
return super.equals(value)
}
Expand Down
4 changes: 4 additions & 0 deletions src/drop/drop.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
export abstract class Drop {
abstract valueOf(): any;

liquid_method_missing (name: string) { // eslint-disable-line
}
}
3 changes: 1 addition & 2 deletions src/drop/empty-drop.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Drop } from './drop'
import { IComparable } from './icomparable'
import { isObject, isString, isArray } from '../util/underscore'
import { IDrop } from '../drop/idrop'

export class EmptyDrop extends Drop implements IDrop, IComparable {
export class EmptyDrop extends Drop implements IComparable {
equals (value: any) {
if (isString(value) || isArray(value)) return value.length === 0
if (isObject(value)) return Object.keys(value).length === 0
Expand Down
10 changes: 0 additions & 10 deletions src/drop/idrop.ts

This file was deleted.

5 changes: 2 additions & 3 deletions src/drop/null-drop.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Drop } from './drop'
import { IComparable } from './icomparable'
import { isNil } from '../util/underscore'
import { IDrop, isDrop } from '../drop/idrop'
import { BlankDrop } from '../drop/blank-drop'

export class NullDrop extends Drop implements IDrop, IComparable {
export class NullDrop extends Drop implements IComparable {
equals (value: any) {
return isNil(isDrop(value) ? value.valueOf() : value) || value instanceof BlankDrop
return isNil(value instanceof Drop ? value.valueOf() : value) || value instanceof BlankDrop
}
gt () {
return false
Expand Down
6 changes: 3 additions & 3 deletions src/render/syntax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { isComparable } from '../drop/icomparable'
import { NullDrop } from '../drop/null-drop'
import { EmptyDrop } from '../drop/empty-drop'
import { BlankDrop } from '../drop/blank-drop'
import { isDrop } from '../drop/idrop'
import { Drop } from '../drop/drop'

const binaryOperators: {[key: string]: (lhs: any, rhs: any) => boolean} = {
'==': (l: any, r: any) => {
Expand Down Expand Up @@ -74,7 +74,7 @@ export function parseExp (exp: string, scope: Scope): any {

export function evalExp (str: string, scope: Scope): any {
const value = parseExp(str, scope)
return isDrop(value) ? value.valueOf() : value
return value instanceof Drop ? value.valueOf() : value
}

function parseValue (str: string, scope: Scope): any {
Expand All @@ -93,7 +93,7 @@ function parseValue (str: string, scope: Scope): any {

export function evalValue (str: string, scope: Scope): any {
const value = parseValue(str, scope)
return isDrop(value) ? value.valueOf() : value
return value instanceof Drop ? value.valueOf() : value
}

export function isTruthy (val: any): boolean {
Expand Down

0 comments on commit b69c3a3

Please sign in to comment.