ANN: Two small libraries/experiments: QProxy and QStep

24 views
Skip to first unread message

Tom Robinson

unread,
Jul 30, 2013, 2:38:30 PM7/30/13
to q-con...@googlegroups.com
I've released two little libraries that make working with promises a bit nicer in some cases:


QProxy is the more interesting one. It lets you chain method calls on unresolved promises like this:

    browser = QProxy(wd.promiseRemote("localhost", 4444));
    browser.elementById("some_id").click(); // returns a promise

instead of this:

    browser = wd.promiseRemote("localhost", 4444);
    browser.elementById("some_id").then(function(element) {
        return element.click()
    }); // returns a promise

The main thing to note is that elementById returns a Q promise (which is wrapped with a proxy), not a special object with a "click" method. You could call any method on it and it will be invoked once the promise is resolved, or the promise it returns will be rejected if the method doesn't exist.

It's similar in concept to Q's `promise.invoke("foo", ...args)` API (and in fact is implemented with that API), but much nicer looking syntax. Internally it uses JavaScript's new Proxy feature (node-proxy module on Node, should be trivial to adapt it for the browser)

QStep is just a simple control flow library similar to creationix's Step.

Here's an example using both QProxy and QStep with the "wd" WebDriver library to script a browser (admittedly it looks nicer in CoffeeScript than JS)

      QStep(
        -> browser.init(browserName: "firefox")
        -> browser.get("https://www.facebook.com/")
        -> browser.elementById("email").type(credentials.email)
        -> browser.elementById("pass").type(credentials.password)
        -> browser.elementById("u_0_b").click()
      )

Wout Mertens

unread,
Aug 7, 2013, 3:28:16 AM8/7/13
to q-continuum@googlegroups com

I like the step function, I wouldn't mind seeing that in Q proper... The proxy is a bit too magical for me, I'd be afraid to lose track of which vars are promises and which aren't...

Kris, weren't you talking about a plugin architecture for Q?

Wout.

--
You received this message because you are subscribed to the Google Groups "Q Continuum (JavaScript)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to q-continuum...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Kris Kowal

unread,
Aug 7, 2013, 12:24:51 PM8/7/13
to Q Continuum
I’m the enemy of plugin architectures, because they lack reliable composition, but I may add a facility to make it simple to create Q subtypes, but I’m not…promising. In general, I’m pushing back on feature creep at this point. I even swallowed my own enthusiasm and am refactoring my promise streams idea into a separate project.

Some years ago, I pushed hard to make CommonJS modules happen. It’s a good system I look forward to making more use of.
Reply all
Reply to author
Forward
0 new messages