Code Monkey home page Code Monkey logo

Comments (12)

james-jw avatar james-jw commented on September 25, 2024

First, I would say I have failed to truly align with either; however, with that said. I am certainly closer to the JQuery.

For example Q.js uses catch, while I choose jquery's fail, primarily due to using it more often. What would be your opinion? Thinking about it now, I think catch actually makes more sense.

Additionally a few changes were made to align more with the nature of XQuery.

In regards to when, it is analogous to JQuery's when method or Q's all method, except unlike in Q.js, it accepts a mix of promises, raw values (static) or single arity functions, instead of just a sequence of promises. Its purpose is not around static vs non static, but around using multi arity functions in a pipeline.

For example:

let $phrase := 'Hello'
let $name := p:defer(api:getName(?), '23')
return
  p:when(($phrase, $name))
    => p:then(function ($phrase , $name) { $phrase || $name });

Raw values are actually not supported due to oversight on my part in the current build out there. Ill fix that here quick, still recovering. ;0

There is a lot of stuff which doesn't transfer, or atleast need not, from javascript. For example, I don't have an any clause.

Thoughts?

from xq-promise.

james-jw avatar james-jw commented on September 25, 2024

I think I completely missed one piece of this pattern in this implementation and what you were eluding to. Basically I didn't account for a very important facet to this pattern, the returning of a promise from a callback. The idea labelled by Q as static or non static.

let $greet:= function ($name) {
  let $greeting:= if($name = 'world') then $greet-world else $greet-non-world
  return p:defer($greeting, $name)
}
let $promise := p:defer($greet, 'world')
return
  $promise()

from xq-promise.

james-jw avatar james-jw commented on September 25, 2024

So with all this said, I think this implementation proofs the pattern works, but I implemented the pattern slightly wrong. I agree we should decide on a template, and follow it all the way.

Luckily, whatever we choose will be a trivial change to actually implement.

What is your preference?

from xq-promise.

james-jw avatar james-jw commented on September 25, 2024

Wholly crap... I can write this entirely in XQuery except fork and fork-join...

more to come...

from xq-promise.

mgaerber avatar mgaerber commented on September 25, 2024

I tend to APIs with lighter footprint (jQuery in this case). On the other hand, the only official spec is A+ (also ECMA6) and I just read on the jQuery blog that they have a patch for jQuery 3.0 to align it with the spec.

Soo, in the end I guess A+ would be a good choice.

from xq-promise.

mgaerber avatar mgaerber commented on September 25, 2024

Now having said that - A+ is only defining then semantics. Q just added everything else on its own. So apart from then there is no single source of truth...

from xq-promise.

mgaerber avatar mgaerber commented on September 25, 2024

So, ECMA defines more methods, as always Mozilla MDN on Promise is a good read.

Promise.all() Promise.prototype.catch() Promise.prototype.then() Promise.race() Promise.reject() Promise.resolve()

Offical ECMA 2016 Spec: https://tc39.github.io/ecma262/#sec-promise-objects

from xq-promise.

james-jw avatar james-jw commented on September 25, 2024

Thanks for the links! Now that the original library is converted to basically pure XQuery it will be easier to modify towards a goal of A+ coherence, at least as close as possible. I need to start with adding support for the reject callback. I think otherwise the conformance is rather close.

Not sure if the concepts of fufilled, pending, etc will apply with xquery...

from xq-promise.

james-jw avatar james-jw commented on September 25, 2024

The then method should now behave like stated in the Offical ECMA 2016 Spec:
https://tc39.github.io/ecma262/#sec-promise-objects

With this, an additional overload accepts a reject callback. Additionally a fulfillment callback is not required. Multiple promises are also now supported.

Need to overhaul docs.

from xq-promise.

james-jw avatar james-jw commented on September 25, 2024

when should be working as outlined for Q's all method:

Use the Q function to turn the non-promise values into promises, or pass an array to Q.all to get back a promise for an array of the results.

Are you seeing it operation differently. If you can give me an example query which operates out of sync It might be helpful.

from xq-promise.

mgaerber avatar mgaerber commented on September 25, 2024

I'll soon add it to a project I am working on (for async image processing etc.) and tell you about my progress (or even add you to the repo)

from xq-promise.

james-jw avatar james-jw commented on September 25, 2024

Sounds interesting! Keep me posted.

from xq-promise.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.