Skip to content

Commit

Permalink
[js] Move the DeferredExecutor class to the command module
Browse files Browse the repository at this point in the history
  • Loading branch information
jleyba committed Jan 25, 2016
1 parent 428398f commit 3c1f820
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 23 deletions.
2 changes: 2 additions & 0 deletions javascript/node/selenium-webdriver/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ the selenium-webdriver package README.
promises instead of using callback passing.
* Migrated the `webdriver.Command*` types from using the Closure Library to the
new `lib/command` module.
* Deprecated `executors.DeferredExecutor` in favor of
`lib/command.DeferredExecutor`.
* API documentation is no longer distributed with the npm package, but remains
available at <http://seleniumhq.github.io/selenium/docs/api/javascript/>
* Rewrote the `error` module to export an Error subtype for each type of error
Expand Down
3 changes: 1 addition & 2 deletions javascript/node/selenium-webdriver/chrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ var fs = require('fs'),
util = require('util');

var webdriver = require('./index'),
executors = require('./executors'),
http = require('./http'),
io = require('./io'),
command = require('./lib/command'),
Expand Down Expand Up @@ -150,7 +149,7 @@ var Command = {
* @return {!command.Executor} The new command executor.
*/
function createExecutor(url) {
return new executors.DeferredExecutor(url.then(function(url) {
return new command.DeferredExecutor(url.then(function(url) {
var client = new http.HttpClient(url);
var executor = new http.Executor(client);
executor.defineCommand(
Expand Down
21 changes: 2 additions & 19 deletions javascript/node/selenium-webdriver/executors.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,13 @@ var HttpClient = require('./http').HttpClient,
HttpExecutor = require('./http').Executor,
promise = require('./lib/_base').require('webdriver.promise');



/**
* Wraps a promised {@link ./lib/command.Executor}, ensuring no commands are
* executed until the wrapped executor has been fully built.
* @implements {./lib/command.Executor}
*/
class DeferredExecutor {
/**
* @param {!webdriver.promise.Promise<!./lib/command.Executor>} delegate
* The promised delegate.
*/
constructor(delegate) {
/** @override */
this.execute = function(command) {
return delegate.then(executor => executor.execute(command));
};
}
}
var DeferredExecutor = require('./lib/command').DeferredExecutor;


// PUBLIC API


/** @deprecated Use {@link ./lib/command.DeferredExecutor} instead. */
exports.DeferredExecutor = DeferredExecutor;

/**
Expand Down
21 changes: 21 additions & 0 deletions javascript/node/selenium-webdriver/lib/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,30 @@ class Executor {
}


/**
* Wraps a promised {@link Executor}, ensuring no commands are executed until
* the wrapped executor has been fully resolved.
* @implements {Executor}
*/
class DeferredExecutor {
/**
* @param {!IThenable<Executor>} delegate The promised delegate, which may
* be provided by any promise-like thenable object.
*/
constructor(delegate) {
/** @override */
this.execute = function(command) {
return delegate.then(executor => executor.execute(command));
};
}
}



// PUBLIC API


exports.Command = Command;
exports.Name = Name;
exports.Executor = Executor;
exports.DeferredExecutor = DeferredExecutor;
3 changes: 1 addition & 2 deletions javascript/node/selenium-webdriver/phantomjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ var fs = require('fs'),
util = require('util');

var webdriver = require('./index'),
executors = require('./executors'),
http = require('./http'),
io = require('./io'),
command = require('./lib/command'),
Expand Down Expand Up @@ -117,7 +116,7 @@ var WEBDRIVER_TO_PHANTOMJS_LEVEL = (function() {
* @return {!command.Executor} The new command executor.
*/
function createExecutor(url) {
return new executors.DeferredExecutor(url.then(function(url) {
return new command.DeferredExecutor(url.then(function(url) {
var client = new http.HttpClient(url);
var executor = new http.Executor(client);

Expand Down

0 comments on commit 3c1f820

Please sign in to comment.