Permalink
Browse files

Merge pull request #1 from gkz/patch-1

changed to more idiomatic LiveScript, JS compilation is unchanged
  • Loading branch information...
2 parents 11aa2a8 + b9717f8 commit c1c08d74e009d01dfcd1047b2dc14b4bdd5a116e @audreyt committed Jun 16, 2012
Showing with 9 additions and 12 deletions.
  1. +3 −3 src/example.ls
  2. +6 −9 src/jscex-jquery.ls
View
6 src/example.ls
@@ -3,11 +3,11 @@ say = !-> console.log it; console.log ''
fetch = eval $.async (url) ->
it = $await $.get url
- a = $(it) .find 'h2:first a'
+ a = $ it .find 'h2:first a'
title = a.text!
it = $await $.get "#url/#{ a.attr \href }"
- text = $(it) .find '.post p:last' .text!
- return { title, text }
+ text = $ it .find '.post p:last' .text!
+ { title, text }
say '[Demo: Fetching invalid host, expecting ENOENT...]'
View
15 src/jscex-jquery.ls
@@ -13,10 +13,9 @@ else
/* Convert a Promise (Q, jQuery, Dojo) object into a Task */
Jscex.Async.@Binding.fromPromise = (p) ->
t <- Jscex.Async.Task.create
- p.then(
+ p.then do
-> t.complete \success, it
-> t.complete \failure, it
- )
return t
/* Our own monad that runs on $.Deferred instead of Task */
@@ -30,27 +29,25 @@ class AsyncBuilder extends Jscex.BuilderBase
| otherwise => throw new Error "Unsupported type: #type"
return __
Bind: (promise, generator) ->
- return next: (_this, cb) -> promise.then(
+ next: (_this, cb) -> promise.then do
!(result) ->
- try step = generator.call _this, result
+ try step = generator.call _this, result
catch return cb \throw, e
step.next _this, cb
!(error) -> cb \throw, error
- )
-Jscex.binders.\async-jquery = \$await
+Jscex.binders .\async-jquery = \$await
Jscex.builders.\async-jquery = new AsyncBuilder
-Jscex.modules.\async-jquery = true
+Jscex.modules .\async-jquery = true
/* Compile a function containing the special $await keyword.
Once invoked, we implicitly start the task, and return a
deferred Promise object representing its result.
*/
-$.async = (cb) -> Jscex.compile(\async-jquery, cb).replace(
+$.async = (cb) -> Jscex.compile(\async-jquery, cb).replace do
/(Jscex.builders\["async-jquery"\])/
'$.$1'
-)
$.async.sleep = (ms) ->
__ = $.Deferred!

0 comments on commit c1c08d7

Please sign in to comment.