Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

changed to more idiomatic LiveScript, JS compilation is unchanged #1

Merged
merged 1 commit into from

2 participants

@gkz

as title

@audreyt
Owner

Ooh, nice use of do-as-parens. Thanks for the stylistic feedback! :-)

@audreyt audreyt merged commit c1c08d7 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
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!
Something went wrong with that request. Please try again.