refactor: Drop.prototype.value => valueOf

This commit is contained in:
harttle
2019-02-28 00:05:08 +08:00
parent d0118402e4
commit d5b9916b2f
5 changed files with 8 additions and 8 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ import { EmptyDrop } from '../drop/empty-drop'
export class BlankDrop extends EmptyDrop { export class BlankDrop extends EmptyDrop {
equals (value: any) { equals (value: any) {
if (value === false) return true if (value === false) return true
if (isNil(isDrop(value) ? value.value() : value)) return true if (isNil(isDrop(value) ? value.valueOf() : value)) return true
if (isString(value)) return /^\s*$/.test(value) if (isString(value)) return /^\s*$/.test(value)
return super.equals(value) return super.equals(value)
} }
+1 -1
View File
@@ -21,7 +21,7 @@ export class EmptyDrop extends Drop implements IDrop, IComparable {
leq () { leq () {
return false return false
} }
value () { valueOf () {
return '' return ''
} }
} }
+2 -2
View File
@@ -2,9 +2,9 @@ import { Drop } from './drop'
import { isFunction } from '../util/underscore' import { isFunction } from '../util/underscore'
export interface IDrop { export interface IDrop {
value(): any valueOf(): any
} }
export function isDrop (value: any): value is IDrop { export function isDrop (value: any): value is IDrop {
return value instanceof Drop && isFunction((value as any).value) return value instanceof Drop && isFunction((value as any).valueOf)
} }
+2 -2
View File
@@ -6,7 +6,7 @@ import { BlankDrop } from '../drop/blank-drop'
export class NullDrop extends Drop implements IDrop, IComparable { export class NullDrop extends Drop implements IDrop, IComparable {
equals (value: any) { equals (value: any) {
return isNil(isDrop(value) ? value.value() : value) || value instanceof BlankDrop return isNil(isDrop(value) ? value.valueOf() : value) || value instanceof BlankDrop
} }
gt () { gt () {
return false return false
@@ -20,7 +20,7 @@ export class NullDrop extends Drop implements IDrop, IComparable {
leq () { leq () {
return false return false
} }
value () { valueOf () {
return null return null
} }
} }
+2 -2
View File
@@ -74,7 +74,7 @@ export function parseExp (exp: string, scope: Scope): any {
export function evalExp (str: string, scope: Scope): any { export function evalExp (str: string, scope: Scope): any {
const value = parseExp(str, scope) const value = parseExp(str, scope)
return isDrop(value) ? value.value() : value return isDrop(value) ? value.valueOf() : value
} }
function parseValue (str: string, scope: Scope): any { function parseValue (str: string, scope: Scope): any {
@@ -93,7 +93,7 @@ function parseValue (str: string, scope: Scope): any {
export function evalValue (str: string, scope: Scope): any { export function evalValue (str: string, scope: Scope): any {
const value = parseValue(str, scope) const value = parseValue(str, scope)
return isDrop(value) ? value.value() : value return isDrop(value) ? value.valueOf() : value
} }
export function isTruthy (val: any): boolean { export function isTruthy (val: any): boolean {