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 {
equals (value: any) {
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)
return super.equals(value)
}
+1 -1
View File
@@ -21,7 +21,7 @@ export class EmptyDrop extends Drop implements IDrop, IComparable {
leq () {
return false
}
value () {
valueOf () {
return ''
}
}
+2 -2
View File
@@ -2,9 +2,9 @@ import { Drop } from './drop'
import { isFunction } from '../util/underscore'
export interface IDrop {
value(): any
valueOf(): any
}
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 {
equals (value: any) {
return isNil(isDrop(value) ? value.value() : value) || value instanceof BlankDrop
return isNil(isDrop(value) ? value.valueOf() : value) || value instanceof BlankDrop
}
gt () {
return false
@@ -20,7 +20,7 @@ export class NullDrop extends Drop implements IDrop, IComparable {
leq () {
return false
}
value () {
valueOf () {
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 {
const value = parseExp(str, scope)
return isDrop(value) ? value.value() : value
return isDrop(value) ? value.valueOf() : value
}
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 {
const value = parseValue(str, scope)
return isDrop(value) ? value.value() : value
return isDrop(value) ? value.valueOf() : value
}
export function isTruthy (val: any): boolean {