提交 ca733287 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

use plain javascript for phantomjs #60

上级 8dce2d5d
...@@ -176,10 +176,10 @@ export class Contact implements Sayable { ...@@ -176,10 +176,10 @@ export class Contact implements Sayable {
} }
log.verbose('Cotnact', 'findAll({ name: %s })', query.name) log.verbose('Cotnact', 'findAll({ name: %s })', query.name)
const name = query.name const nameFilter = query.name
if (!name) { if (!nameFilter) {
throw new Error('name not found') throw new Error('nameFilter not found')
} }
/** /**
...@@ -188,10 +188,10 @@ export class Contact implements Sayable { ...@@ -188,10 +188,10 @@ export class Contact implements Sayable {
*/ */
let filterFunction: string let filterFunction: string
if (name instanceof RegExp) { if (nameFilter instanceof RegExp) {
filterFunction = `c => ${name.toString()}.test(c)` filterFunction = `function (c) { return ${nameFilter.toString()}.test(c) }`
} else if (typeof name === 'string') { } else if (typeof nameFilter === 'string') {
filterFunction = `c => c === '${name}'` filterFunction = `function (c) { return c === '${nameFilter}' }`
} else { } else {
throw new Error('unsupport name type') throw new Error('unsupport name type')
} }
......
...@@ -399,18 +399,18 @@ export class Room extends EventEmitter implements Sayable { ...@@ -399,18 +399,18 @@ export class Room extends EventEmitter implements Sayable {
public static async findAll(query: RoomQueryFilter): Promise<Room[]> { public static async findAll(query: RoomQueryFilter): Promise<Room[]> {
log.verbose('Room', 'findAll({ topic: %s })', query.topic) log.verbose('Room', 'findAll({ topic: %s })', query.topic)
const topic = query.topic const topicFilter = query.topic
if (!topic) { if (!topicFilter) {
throw new Error('topic not found') throw new Error('topicFilter not found')
} }
let filterFunction: string let filterFunction: string
if (topic instanceof RegExp) { if (topicFilter instanceof RegExp) {
filterFunction = `c => ${topic.toString()}.test(c)` filterFunction = `function (c) { return ${topicFilter.toString()}.test(c) }`
} else if (typeof topic === 'string') { } else if (typeof topicFilter === 'string') {
filterFunction = `c => c === '${topic}'` filterFunction = `function (c) { return c === '${topicFilter}' }`
} else { } else {
throw new Error('unsupport topic type') throw new Error('unsupport topic type')
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册