Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deferred object #32

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Deferred object #32

wants to merge 2 commits into from

Conversation

johncant
Copy link

Hello, and Merry Christmas!

I've gone ahead and made a rudimentary implementation of jQuery's Deferred object. I've opened this PR mainly to ask for help in solving some of the issues that arose, and to show you what I've built so far, so please don't assume that it's ready to be merged yet. 😃

Things that are done or not done depending on the checkbox:

  • Make new Deferred objects in Fay code
  • .fail() and .reject() on those objects
  • .done() and .resolve() on those objects, passing a single value
  • .always() handler
  • .then() to filter a single value
  • .state()
  • jQuery.when() with a homogeneous list
  • Promise, by pretending that it is a Deferrable
  • Many, many, tests.
  • Multiple arguments to a callback
  • Failure argument(s)
  • Progress callbacks and notify
  • Promise locked down at compile time
  • Monad interface for chaining and binding Deferred(s)
  • .when() with different types
  • Pass JS this argument
  • Make an existing object deferred, using resolve and reject.
  • Deal with the Fay "bugs" I found
  • Compatability with jQuery < 1.8

Notes:

  • Probably should have used Null instead of Undefined to represent nothing being passed
  • I might have found 2 "bugs" in Fay but they are hard to replicate - Comparing two arrays is always false (like JS), and a situation where a case statement on the type Text just defaulted to the first case every time. I can't replicate the second "bug" outside of src/JQuery/Deferred.hs

Hope this helps!

bergmark added a commit to faylang/fay that referenced this pull request Jan 5, 2015
@bergmark
Copy link
Member

bergmark commented Jan 5, 2015

Cool!

  • As an API user of this it may be most convenient to pass Maybe a instead of Nullable a or Defined a. The intention of Nullable and Defined is that they should mostly be used at a low level. It's a good start to use these though, it's probably simple to abstract this away later on once the implementation is in place.
  • I added a test case for list equality to fay, it works. Did you check the actual values that are being compared? It may be that one of them is a fay list and the other is a js array, for instance.
  • Are you able to make a smaller reproduction of the case issue? It may be because you are using just OverloadedStrings, I'd recommend also enabling RebindableSyntax so all literals are Text. It's possible that bugs can appear if GHC typechecking allows something polymorphic. I haven't really looked into this.

@johncant
Copy link
Author

johncant commented Jan 5, 2015

Hi @bergmark!

I also wrote some tests on Fay itself, including one for list equality, and found that they all worked until faylang/fay#424 . I think what was happening was exactly as you describe. I think that nearly all of my "bugs" are manifestations of faylang/fay/issues/424 without me having realised.

Your 3rd point is really useful. Cheers. BTW All of my case examples worked correctly when I tried to write a test.

Before I do anything else, I'm going to have a go at getting type information into Fay and then I might take another look! I wrote this unintentionally because I misread Angular's $q as being jQuery, whereas they have a slightly different API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants