Skip to content

Commit baacf92

Browse files
committed
Merge branch 'topic/fixing-constructors'
2 parents 262bb14 + ab7d0f8 commit baacf92

File tree

6 files changed

+179
-166
lines changed

6 files changed

+179
-166
lines changed

src/Angular/Cache.purs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module Angular.Cache
1616

1717
import Control.Monad.Eff
1818
import Data.Maybe
19+
import Data.Function
1920

2021
foreign import data CACHE :: !
2122

@@ -29,17 +30,20 @@ type Name = String
2930

3031
type Options a = { capacity :: Number | a }
3132

32-
foreign import cache
33-
" function cache(name){ \
34-
\ return function(opts){ \
35-
\ return function($cacheFactory){ \
36-
\ return function(){ \
37-
\ return $cacheFactory(name, opts.values[0]); \
38-
\ }; \
39-
\ }; \
33+
cache :: forall e a. Name -> Maybe (Options a) -> CacheFactory -> Eff (ngcache :: CACHE | e) Cache
34+
cache = runFn4 cacheFn fromMaybe
35+
36+
foreign import cacheFn
37+
" function cacheFn(fromMaybe, name, opts, $cacheFactory){ \
38+
\ return function(){ \
39+
\ return $cacheFactory(name, fromMaybe(undefined)(opts)); \
4040
\ }; \
4141
\ } "
42-
:: forall e a. Name -> Maybe (Options a) -> CacheFactory -> Eff (ngcache :: CACHE | e) Cache
42+
:: forall e a. Fn4 (Options a -> Maybe (Options a) -> Options a)
43+
Name
44+
(Maybe (Options a))
45+
CacheFactory
46+
(Eff (ngcache :: CACHE | e) Cache)
4347

4448
foreign import put
4549
" function put(key){ \

src/Angular/Element.purs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ module Angular.Element
5858
import Prelude (Unit())
5959

6060
import Control.Monad.Eff
61-
import Data.Function (Fn3(), Fn4(), runFn3, runFn4)
61+
import Data.Function (Fn3(), Fn4(), Fn5(), runFn3, runFn4, runFn5)
6262
import Data.Maybe
6363

6464
import DOM.Event (Event())
@@ -517,16 +517,22 @@ foreign import wrap
517517
\ }"
518518
:: forall e. Element -> Element -> Eff (ngel :: El | e) Element
519519

520-
foreign import controller
521-
" function controller(nameOpt){ \
522-
\ return function(el){ \
523-
\ return function(){ \
524-
\ var a = el.controller(nameOpt.values[0]); \
525-
\ return angular.isDefined(a) ? Data_Maybe.Just(a) : Data_Maybe.Nothing; \
526-
\ }; \
520+
foreign import controllerFn
521+
" function controllerFn(fromMaybe, nothing, just, name, el){ \
522+
\ return function(){ \
523+
\ var a = el.controller(fromMaybe(undefined)(name)); \
524+
\ return angular.isDefined(a) ? just(a) : nothing; \
527525
\ }; \
528526
\ }"
529-
:: forall e a. Maybe String -> Element -> Eff (ngel :: El | e) (Maybe a)
527+
:: forall e a. Fn5 (String -> Maybe String -> String)
528+
(Maybe a)
529+
(a -> Maybe a)
530+
(Maybe String)
531+
Element
532+
(Eff (ngel :: El | e) (Maybe a))
533+
534+
controller :: forall e a. Maybe String -> Element -> Eff (ngel :: El | e) (Maybe a)
535+
controller = runFn5 controllerFn fromMaybe Nothing Just
530536

531537
foreign import injectorFn
532538
" function injectorFn(nothing, just, el){ \

src/Angular/Http.purs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module Angular.Http
22
( Http()
3+
, HttpEff()
34
, HttpResponse()
45
, Response()
56
, Config()

src/Angular/NgModelController.purs

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module Angular.NgModelController
2828
) where
2929

3030
import Control.Monad.Eff
31+
import Data.Function
3132
import Data.Maybe
3233

3334
foreign import data NgModelController :: * -> *
@@ -129,39 +130,47 @@ foreign import setModelValue
129130
\ } "
130131
:: forall e a b. b -> NgModelController a -> Eff (ngmodel :: NgModelCtrl | e) (NgModelController b)
131132

132-
foreign import appendParsers
133-
" function appendParsers(parsers){ \
134-
\ return function($ctrl){ \
135-
\ return function(){ \
136-
\ var as = []; \
137-
\ angular.forEach(parsers, function(p){ \
138-
\ as.push(function(v){ \
139-
\ return p(v).values[0]; \
140-
\ }); \
133+
foreign import appendParsersFn
134+
" function appendParsersFn(fromMaybe, parsers, $ctrl){ \
135+
\ return function(){ \
136+
\ var as = []; \
137+
\ angular.forEach(parsers, function(p){ \
138+
\ as.push(function(v){ \
139+
\ return fromMaybe(undefined)(p(v)); \
141140
\ }); \
142-
\ $ctrl.$parsers.push.apply($ctrl.$parsers, as); \
143-
\ return {}; \
144-
\ }; \
141+
\ }); \
142+
\ $ctrl.$parsers.push.apply($ctrl.$parsers, as); \
143+
\ return {}; \
145144
\ }; \
146145
\ } "
147-
:: forall e a. [Parser a] -> NgModelController a -> Eff (ngmodel :: NgModelCtrl | e) Unit
146+
:: forall e a. Fn3 (a -> Maybe a -> a)
147+
[Parser a]
148+
(NgModelController a)
149+
(Eff (ngmodel :: NgModelCtrl | e) Unit)
148150

149-
foreign import prependParsers
150-
" function prependParsers(parsers){ \
151-
\ return function($ctrl){ \
152-
\ return function(){ \
153-
\ var as = []; \
154-
\ angular.forEach(parsers, function(p){ \
155-
\ as.push(function(v){ \
156-
\ return p(v).values[0]; \
157-
\ }); \
151+
appendParsers :: forall e a. [Parser a] -> NgModelController a -> Eff (ngmodel :: NgModelCtrl | e) Unit
152+
appendParsers = runFn3 appendParsersFn fromMaybe
153+
154+
foreign import prependParsersFn
155+
" function prependParsersFn(fromMaybe, parsers, $ctrl){ \
156+
\ return function(){ \
157+
\ var as = []; \
158+
\ angular.forEach(parsers, function(p){ \
159+
\ as.push(function(v){ \
160+
\ return fromMaybe(undefined)(p(v)); \
158161
\ }); \
159-
\ $ctrl.$parsers.unshift.apply($ctrl.$parsers, as); \
160-
\ return {}; \
161-
\ }; \
162+
\ }); \
163+
\ $ctrl.$parsers.unshift.apply($ctrl.$parsers, as); \
164+
\ return {}; \
162165
\ }; \
163166
\ } "
164-
:: forall e a. [Parser a] -> NgModelController a -> Eff (ngmodel :: NgModelCtrl | e) Unit
167+
:: forall e a. Fn3 (a -> Maybe a -> a)
168+
[Parser a]
169+
(NgModelController a)
170+
(Eff (ngmodel :: NgModelCtrl | e) Unit)
171+
172+
prependParsers :: forall e a. [Parser a] -> NgModelController a -> Eff (ngmodel :: NgModelCtrl | e) Unit
173+
prependParsers = runFn3 prependParsersFn fromMaybe
165174

166175
foreign import appendFormatters
167176
" function appendFormatters(formatters){ \

0 commit comments

Comments
 (0)