Skip to content

Commit

Permalink
changed Selector to Query
Browse files Browse the repository at this point in the history
  • Loading branch information
refractalize committed Jan 16, 2019
1 parent 31084f6 commit eb5ec39
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions create.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
var Selector = require('./lib/selector')
var Query = require('./lib/query')
var finders = require('./lib/finders')
var actions = require('./lib/actions')
var button = require('./lib/button')
var fields = require('./lib/fields')
var assertions = require('./lib/assertions')

module.exports = function (rootSelector) {
return new Selector()
return new Query()
.component(finders)
.component(actions)
.component(button)
Expand Down
42 changes: 21 additions & 21 deletions lib/selector.js → lib/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var inspect = require('object-inspect')
var uniq = require('lowscore/uniq')
var debug = require('debug')('browser-monkey')

function Selector () {
function Query () {
this._conditions = []
this._options = {
visibleOnly: true,
Expand Down Expand Up @@ -75,7 +75,7 @@ function Selector () {
this._value = undefined
}

Selector.prototype.action = function (action) {
Query.prototype.action = function (action) {
return this.clone(function (clone) {
if (clone._action) {
throw new Error('can only have one action')
Expand All @@ -96,7 +96,7 @@ function retryFromOptions (options) {
}
}

Selector.prototype.mapAll = function (mapper, description) {
Query.prototype.mapAll = function (mapper, description) {
return this.clone(function (clone) {
clone._conditions.push(function (elements) {
return {
Expand All @@ -107,7 +107,7 @@ Selector.prototype.mapAll = function (mapper, description) {
})
}

Selector.prototype.map = function (mapper, description) {
Query.prototype.map = function (mapper, description) {
return this.clone(function (clone) {
clone._conditions.push(function (elements) {
return {
Expand All @@ -118,7 +118,7 @@ Selector.prototype.map = function (mapper, description) {
})
}

Selector.prototype.filter = function (filter, description) {
Query.prototype.filter = function (filter, description) {
return this.clone(function (clone) {
clone._conditions.push(function (elements) {
return {
Expand All @@ -129,7 +129,7 @@ Selector.prototype.filter = function (filter, description) {
})
}

Selector.prototype.all = function (queryCreators) {
Query.prototype.all = function (queryCreators) {
var self = this

var queries = queryCreators.map(function (queryCreator) {
Expand All @@ -154,11 +154,11 @@ Selector.prototype.all = function (queryCreators) {
})
}

Selector.prototype.subQuery = function (createQuery) {
Query.prototype.subQuery = function (createQuery) {
var clone = this.clone()
clone._conditions = []
var query = createQuery(clone)
if (!(query instanceof Selector)) {
if (!(query instanceof Query)) {
throw new Error('expected to create query: ' + createQuery)
}
return query
Expand All @@ -168,7 +168,7 @@ Selector.prototype.resolveSubQuery = function (createQuery, value) {
return this.subQuery(createQuery).resolve(value)
}

Selector.prototype.resolve = function (value, options) {
Query.prototype.resolve = function (value, options) {
var accumulator = {}
var includeScope = options && options.hasOwnProperty('includeScope') && options.includeScope !== undefined
? options.includeScope
Expand Down Expand Up @@ -208,7 +208,7 @@ Selector.prototype.resolve = function (value, options) {
}
}

Selector.prototype.race = function (queryCreators) {
Query.prototype.race = function (queryCreators) {
var self = this

var queries = queryCreators.map(function (queryCreator) {
Expand Down Expand Up @@ -250,7 +250,7 @@ Selector.prototype.race = function (queryCreators) {
})
}

Selector.prototype.options = function (options) {
Query.prototype.options = function (options) {
if (options) {
return this.clone(function (clone) {
extend(clone._options, options)
Expand All @@ -260,7 +260,7 @@ Selector.prototype.options = function (options) {
}
}

Selector.prototype.then = function () {
Query.prototype.then = function () {
var self = this
var retry = retryFromOptions(this._options)
var originalStack = new Error().stack
Expand Down Expand Up @@ -320,7 +320,7 @@ function describeTransform (transform) {
return transform.description + ' ' + v
}

Selector.prototype.catch = function (fn) {
Query.prototype.catch = function (fn) {
return this.then(undefined, fn)
}

Expand All @@ -335,7 +335,7 @@ function copySelectorFields (from, to) {
})
}

Selector.prototype.clone = function (modifier) {
Query.prototype.clone = function (modifier) {
var clone = new this.constructor()
copySelectorFields(this, clone)
if (modifier) {
Expand All @@ -344,14 +344,14 @@ Selector.prototype.clone = function (modifier) {
return clone
}

Selector.prototype.ensure = function (assertion, name) {
Query.prototype.ensure = function (assertion, name) {
return this.mapAll(function (value) {
assertion(value)
return value
}, name || 'ensure')
}

Selector.prototype.zero = function () {
Query.prototype.zero = function () {
return this.mapAll(function (results) {
if (results instanceof Array) {
if (results.length !== 0) {
Expand All @@ -365,7 +365,7 @@ Selector.prototype.zero = function () {
}, 'zero')
}

Selector.prototype.one = function () {
Query.prototype.one = function () {
return this.mapAll(function (results) {
if (results instanceof Array) {
if (results.length === 1) {
Expand All @@ -379,7 +379,7 @@ Selector.prototype.one = function () {
}, 'one')
}

Selector.prototype.some = function () {
Query.prototype.some = function () {
return this.mapAll(function (results) {
if (results instanceof Array && results.length !== 0) {
return results
Expand All @@ -389,13 +389,13 @@ Selector.prototype.some = function () {
}, 'some')
}

Selector.prototype.input = function (value) {
Query.prototype.input = function (value) {
return this.clone(function (clone) {
clone._value = value
})
}

Selector.prototype.component = function (methods) {
Query.prototype.component = function (methods) {
var self = this

function Component () {
Expand All @@ -416,4 +416,4 @@ Selector.prototype.component = function (methods) {
return new Component()
}

module.exports = Selector
module.exports = Query
4 changes: 2 additions & 2 deletions test/selectorsSpec.js → test/querySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var describeAssemblies = require('./describeAssemblies')
const expect = require('must')
const DomAssembly = require('./assemblies/DomAssembly')

describe('selectors', () => {
describe('query', () => {
describeAssemblies([DomAssembly], Assembly => {
let assembly
let browserMonkey
Expand Down Expand Up @@ -436,7 +436,7 @@ describe('selectors', () => {
})

describe('race', () => {
it('finds the first of two or more selectors', async () => {
it('finds the first of two or more queries', async () => {
const promise = browserMonkey.race([
b => b.find('.a').one(),
b => b.find('.b').one()
Expand Down

0 comments on commit eb5ec39

Please sign in to comment.