Skip to content

Commit 14ffee2

Browse files
committed
Merge branch 'topic/timeout-interval'
2 parents df350bb + d47d3e3 commit 14ffee2

File tree

7 files changed

+192
-17
lines changed

7 files changed

+192
-17
lines changed

MODULE.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,32 @@
319319
invoke :: forall e r a b c. a -> Maybe { | b } -> Maybe { | c } -> Injector -> InjEff e r
320320

321321

322+
## Module Angular.Interval
323+
324+
### Types
325+
326+
data Interval :: *
327+
328+
type IntervalEff e r = Eff (nginterval :: NgInterval | e) r
329+
330+
type IntervalPromise = Promise Unit Number
331+
332+
data NgInterval :: !
333+
334+
335+
### Values
336+
337+
cancel :: forall e. IntervalPromise -> Interval -> IntervalEff e Boolean
338+
339+
interval :: forall e f r. Eff f r -> Number -> Number -> Boolean -> Interval -> IntervalEff e IntervalPromise
340+
341+
interval' :: forall e f r. Eff f r -> Number -> Number -> Interval -> IntervalEff e IntervalPromise
342+
343+
interval'' :: forall e f r. Eff f r -> Number -> Interval -> IntervalEff e IntervalPromise
344+
345+
intervalk :: forall e f r. Number -> Number -> Boolean -> Interval -> Eff f r -> IntervalEff e IntervalPromise
346+
347+
322348
## Module Angular.Location
323349

324350
### Types
@@ -630,6 +656,32 @@
630656
writeThis :: forall e a b. String -> b -> This a -> WriteEff e
631657

632658

659+
## Module Angular.Timeout
660+
661+
### Types
662+
663+
data NgTimeout :: !
664+
665+
data Timeout :: *
666+
667+
type TimeoutEff e r = Eff (ngtimeout :: NgTimeout | e) r
668+
669+
type TimeoutPromise a = Promise Error a
670+
671+
672+
### Values
673+
674+
cancel :: forall e r. TimeoutPromise r -> Timeout -> TimeoutEff e Boolean
675+
676+
timeout :: forall e f r. Eff f r -> Number -> Boolean -> Timeout -> TimeoutEff e (TimeoutPromise r)
677+
678+
timeout' :: forall e f r. Eff f r -> Number -> Timeout -> TimeoutEff e (TimeoutPromise r)
679+
680+
timeout'' :: forall e f r. Eff f r -> Timeout -> TimeoutEff e (TimeoutPromise r)
681+
682+
timeoutk :: forall e f r. Number -> Boolean -> Timeout -> Eff f r -> TimeoutEff e (TimeoutPromise r)
683+
684+
633685
## Module DOM.Event
634686

635687
### Types

bower.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"dependencies": {
2020
"purescript-bifunctors": "0.0.4",
2121
"purescript-either": "0.1.2",
22+
"purescript-exceptions": "0.2.0",
2223
"purescript-foldable-traversable": "0.1.3",
2324
"purescript-maybe": "0.2.0",
2425
"purescript-tuples": "0.2.0"

examples/Todomvc/Controller.purs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ controller scope location = do
111111
todos <- get
112112
pushAllSTArray todosRef todos
113113
let remainingCount = foldl (\b a -> if a.completed then b else b + 1) 0 todos
114-
extendScope { newTodo: ""
114+
extendScope { fromMaybe: fromMaybe
115+
, newTodo: ""
115116
, editedTodo: Nothing
116117
, originalTodo: Nothing
117118
, todos: todosRef

examples/Todomvc/Focus.purs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,20 @@ import qualified DOM.Node as D
99
import Angular.Attributes (get)
1010
import Angular.Element ((!!))
1111
import Angular.Scope (watch, apply, applyExpr)
12+
import Angular.Timeout (timeout)
1213

1314
foreign import data FocusDirective :: *
1415

15-
link scope element attrs = do
16+
link scope element attrs ngtimeout = do
1617
as <- get attrs
17-
watch as.todoFocus (Just (\a _ _ -> when a $ zeroTimeout
18-
$ maybe (return unit) D.focus (element !! 0))) false scope
19-
20-
foreign import zeroTimeout
21-
" function zeroTimeout(k) { \
22-
\ return function(){ \
23-
\ var $timeout = angular.element(document).injector().get('$timeout'); \
24-
\ return $timeout(k, 0, false); \
25-
\ }; \
26-
\ }"
27-
:: forall e. Eff e Unit -> Eff e Unit
18+
let k = maybe (return unit) D.focus (element !! 0)
19+
watch as.todoFocus (Just (\a _ _ -> when a $ const unit <$> (timeout k 0 false ngtimeout))) false scope
2820

2921
foreign import focus
30-
" /*@ngInject*/function focus(){ \
22+
" /*@ngInject*/function focus($timeout){ \
3123
\ return { \
3224
\ link: function($scope, $element, $attrs){ \
33-
\ return link($scope)($element)($attrs)(); \
25+
\ return link($scope)($element)($attrs)($timeout)(); \
3426
\ } \
3527
\ }; \
3628
\ } " :: FocusDirective

examples/Todomvc/main.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ <h1>todos</h1>
3333
<label for="toggle-all">Mark all as complete</label>
3434
<ul id="todo-list">
3535
<li ng-repeat="todo in todos | filter:statusFilter track by $index"
36-
ng-class="{completed: todo.completed, editing: todo == editedTodo.values[0]}">
36+
ng-class="{completed: todo.completed, editing: todo == fromMaybe(undefined)(editedTodo)}">
3737
<div class="view">
3838
<input class="toggle"
3939
type="checkbox"
@@ -49,7 +49,7 @@ <h1>todos</h1>
4949
ng-model="todo.title"
5050
ng-blur="doneEditing(todo)()"
5151
todo-escape="revertEditing(todo)()"
52-
todo-focus="todo == editedTodo.values[0]">
52+
todo-focus="todo == fromMaybe(undefined)(editedTodo)">
5353
</form>
5454
</li>
5555
</ul>

src/Angular/Interval.purs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
module Angular.Interval
2+
( Interval()
3+
, NgInterval()
4+
, IntervalEff()
5+
, IntervalPromise()
6+
, interval
7+
, interval'
8+
, interval''
9+
, intervalk
10+
, cancel
11+
) where
12+
13+
import Control.Monad.Eff
14+
import Data.Function
15+
import Data.Maybe
16+
17+
import Angular.Promise (Promise())
18+
19+
foreign import data Interval :: *
20+
21+
foreign import data NgInterval :: !
22+
23+
type IntervalEff e r = Eff (nginterval :: NgInterval | e) r
24+
25+
type IntervalPromise = Promise Unit Number
26+
27+
foreign import intervalFn
28+
" function intervalFn(fromMaybe, fn, delay, count, invokeApply, $interval){ \
29+
\ return function(){ \
30+
\ return $interval(fn, delay, fromMaybe(undefined)(count), fromMaybe(undefined)(invokeApply)); \
31+
\ }; \
32+
\ } "
33+
:: forall e f r. Fn6 (forall a. a -> Maybe a -> a)
34+
(Eff f r)
35+
Number
36+
(Maybe Number)
37+
(Maybe Boolean)
38+
Interval
39+
(IntervalEff e IntervalPromise)
40+
41+
interval :: forall e f r. Eff f r -> Number -> Number -> Boolean -> Interval -> IntervalEff e IntervalPromise
42+
interval fn delay count invoke = runFn6 intervalFn fromMaybe fn delay (Just count) (Just invoke)
43+
44+
interval' :: forall e f r. Eff f r -> Number -> Number -> Interval -> IntervalEff e IntervalPromise
45+
interval' fn delay count = runFn6 intervalFn fromMaybe fn delay (Just count) Nothing
46+
47+
interval'' :: forall e f r. Eff f r -> Number -> Interval -> IntervalEff e IntervalPromise
48+
interval'' fn delay = runFn6 intervalFn fromMaybe fn delay Nothing Nothing
49+
50+
intervalk :: forall e f r. Number -> Number -> Boolean -> Interval -> Eff f r -> IntervalEff e IntervalPromise
51+
intervalk delay count invoke interval fn = runFn6 intervalFn fromMaybe fn delay (Just count) (Just invoke) interval
52+
53+
foreign import cancelFn
54+
" function cancelFn(promise, $interval){ \
55+
\ return function(){ \
56+
\ return $interval.cancel(promise); \
57+
\ }; \
58+
\ } "
59+
:: forall e. Fn2 IntervalPromise
60+
Interval
61+
(IntervalEff e Boolean)
62+
63+
cancel :: forall e. IntervalPromise -> Interval -> IntervalEff e Boolean
64+
cancel = runFn2 cancelFn

src/Angular/Timeout.purs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
module Angular.Timeout
2+
( Timeout()
3+
, NgTimeout()
4+
, TimeoutEff()
5+
, TimeoutPromise()
6+
, timeout
7+
, timeout'
8+
, timeout''
9+
, timeoutk
10+
, cancel
11+
) where
12+
13+
import Control.Monad.Eff
14+
import Control.Monad.Eff.Exception (Error())
15+
import Data.Function
16+
import Data.Maybe
17+
18+
import Angular.Promise (Promise())
19+
20+
foreign import data Timeout :: *
21+
22+
foreign import data NgTimeout :: !
23+
24+
type TimeoutEff e r = Eff (ngtimeout :: NgTimeout | e) r
25+
26+
type TimeoutPromise a = Promise Error a
27+
28+
foreign import timeoutFn
29+
" function timeoutFn(fromMaybe, fn, delay, invokeApply, $timeout){ \
30+
\ return function(){ \
31+
\ return $timeout(fn, fromMaybe(undefined)(delay), fromMaybe(undefined)(invokeApply)); \
32+
\ }; \
33+
\ } "
34+
:: forall e f r. Fn5 (forall a. a -> Maybe a -> a)
35+
(Eff f r)
36+
(Maybe Number)
37+
(Maybe Boolean)
38+
Timeout
39+
(TimeoutEff e (TimeoutPromise r))
40+
41+
timeout :: forall e f r. Eff f r -> Number -> Boolean -> Timeout -> TimeoutEff e (TimeoutPromise r)
42+
timeout fn delay invoke = runFn5 timeoutFn fromMaybe fn (Just delay) (Just invoke)
43+
44+
timeout' :: forall e f r. Eff f r -> Number -> Timeout -> TimeoutEff e (TimeoutPromise r)
45+
timeout' fn delay = runFn5 timeoutFn fromMaybe fn (Just delay) Nothing
46+
47+
timeout'' :: forall e f r. Eff f r -> Timeout -> TimeoutEff e (TimeoutPromise r)
48+
timeout'' fn = runFn5 timeoutFn fromMaybe fn Nothing Nothing
49+
50+
timeoutk :: forall e f r. Number -> Boolean -> Timeout -> Eff f r -> TimeoutEff e (TimeoutPromise r)
51+
timeoutk delay invoke timeout fn = runFn5 timeoutFn fromMaybe fn (Just delay) (Just invoke) timeout
52+
53+
foreign import cancelFn
54+
" function cancelFn(fromMaybe, promise, $timeout){ \
55+
\ return function(){ \
56+
\ return $timeout.cancel(fromMaybe(undefined)(promise)); \
57+
\ }; \
58+
\ } "
59+
:: forall e r. Fn3 ((TimeoutPromise r) -> Maybe (TimeoutPromise r) -> (TimeoutPromise r))
60+
(Maybe (TimeoutPromise r))
61+
Timeout
62+
(TimeoutEff e Boolean)
63+
64+
cancel :: forall e r. TimeoutPromise r -> Timeout -> TimeoutEff e Boolean
65+
cancel promise = runFn3 cancelFn fromMaybe (Just promise)

0 commit comments

Comments
 (0)