Skip to content

Commit aafac51

Browse files
committed
Merge branch 'topic/cache-ngmodel-form'
2 parents a7f13d8 + f60dc68 commit aafac51

File tree

3 files changed

+468
-0
lines changed

3 files changed

+468
-0
lines changed

src/Angular/Cache.purs

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
module Angular.Cache
2+
( Cache(..)
3+
, CacheFactory(..)
4+
, CACHE(..)
5+
, Key(..)
6+
, Name(..)
7+
, Options(..)
8+
, injCacheFactory
9+
, cache
10+
, put
11+
, get
12+
, remove
13+
, removeAll
14+
, destroy
15+
, info
16+
) where
17+
18+
import Control.Monad.Eff
19+
import Data.Maybe
20+
21+
import Angular.Injector (InjectDependency(..))
22+
23+
foreign import data CACHE :: !
24+
25+
foreign import data Cache :: *
26+
27+
foreign import data CacheFactory :: *
28+
29+
type Key = String
30+
31+
type Name = String
32+
33+
type Options a = { capacity :: Number | a }
34+
35+
foreign import injCacheFactory
36+
" function injCacheFactory(){ \
37+
\ var $injector = angular.element(document).injector(); \
38+
\ return $injector.get('$cacheFactory'); \
39+
\ } "
40+
:: forall e. Eff (nginj :: InjectDependency | e) CacheFactory
41+
42+
foreign import cache
43+
" function cache(name){ \
44+
\ return function(opts){ \
45+
\ return function($cacheFactory){ \
46+
\ return function(){ \
47+
\ return $cacheFactory(name, opts.values[0]); \
48+
\ }; \
49+
\ }; \
50+
\ }; \
51+
\ } "
52+
:: forall e a. Name -> Maybe (Options a) -> CacheFactory -> Eff (ngcache :: CACHE | e) Cache
53+
54+
foreign import put
55+
" function put(key){ \
56+
\ return function(value){ \
57+
\ return function(cache){ \
58+
\ return function(){ \
59+
\ return cache.put(key, value); \
60+
\ }; \
61+
\ }; \
62+
\ }; \
63+
\ } "
64+
:: forall e a. Key -> a -> Cache -> Eff (ngcache :: CACHE | e) a
65+
66+
foreign import get
67+
" function get(key){ \
68+
\ return function(cache){ \
69+
\ return function(){ \
70+
\ return cache.get(key); \
71+
\ }; \
72+
\ }; \
73+
\ } "
74+
:: forall e a. Key -> Cache -> Eff (ngcache :: CACHE | e) a
75+
76+
foreign import remove
77+
" function remove(key){ \
78+
\ return function(cache){ \
79+
\ return function(){ \
80+
\ return cache.remove(key); \
81+
\ }; \
82+
\ }; \
83+
\ } "
84+
:: forall e a. Key -> Cache -> Eff (ngcache :: CACHE | e) Unit
85+
86+
foreign import removeAll
87+
" function removeAll(cache){ \
88+
\ return function(){ \
89+
\ return cache.removeAll(); \
90+
\ }; \
91+
\ } "
92+
:: forall e. Cache -> Eff (ngcache :: CACHE | e) Unit
93+
94+
foreign import destroy
95+
" function destroy(cache){ \
96+
\ return function(){ \
97+
\ return cache.destroy(); \
98+
\ }; \
99+
\ } "
100+
:: forall e. Cache -> Eff (ngcache :: CACHE | e) Unit
101+
102+
foreign import info
103+
" function info(cache){ \
104+
\ return function(){ \
105+
\ return cache.info(); \
106+
\ }; \
107+
\ } "
108+
:: forall e a. Cache -> Eff (ngcache :: CACHE | e) { id :: String, size :: Number | a }

src/Angular/FormController.purs

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
module Angular.FormController
2+
( FormController(..)
3+
, FormCtrl(..)
4+
, addControl
5+
, removeControl
6+
, setValidity
7+
, setDirty
8+
, setPristine
9+
, pristine
10+
, dirty
11+
, valid
12+
, invalid
13+
, error
14+
) where
15+
16+
import Control.Monad.Eff
17+
18+
import Angular.NgModelController (NgModelController(..), ValidationErrorKey(..))
19+
20+
foreign import data FormController :: *
21+
22+
foreign import data FormCtrl :: !
23+
24+
foreign import addControl
25+
" function addControl(control){ \
26+
\ return function($ctrl){ \
27+
\ return function(){ \
28+
\ return $ctrl.$addControl(control); \
29+
\ }; \
30+
\ }; \
31+
\ } "
32+
:: forall e a. NgModelController a -> FormController -> Eff (ngform :: FormCtrl | e) Unit
33+
34+
foreign import removeControl
35+
" function removeControl(control){ \
36+
\ return function($ctrl){ \
37+
\ return function(){ \
38+
\ return $ctrl.$removeControl(control); \
39+
\ }; \
40+
\ }; \
41+
\ } "
42+
:: forall e a. NgModelController a -> FormController -> Eff (ngform :: FormCtrl | e) Unit
43+
44+
foreign import setValidity
45+
" function setValidity(key){ \
46+
\ return function(isValid){ \
47+
\ return function(control){ \
48+
\ return function($ctrl){ \
49+
\ return function(){ \
50+
\ return $ctrl.$setValidity(key, isValid, control, $ctrl); \
51+
\ }; \
52+
\ }; \
53+
\ }; \
54+
\ }; \
55+
\ } "
56+
:: forall e a. ValidationErrorKey -> Boolean -> NgModelController a -> FormController -> Eff (ngform :: FormCtrl | e) Unit
57+
58+
foreign import setDirty
59+
" function setDirty($ctrl){ \
60+
\ return function(){ \
61+
\ return $ctrl.$setDirty(); \
62+
\ }; \
63+
\ } "
64+
:: forall e. FormController -> Eff (ngform :: FormCtrl | e) Unit
65+
66+
foreign import setPristine
67+
" function setPristine($ctrl){ \
68+
\ return function(){ \
69+
\ return $ctrl.$setPristine(); \
70+
\ }; \
71+
\ } "
72+
:: forall e. FormController -> Eff (ngform :: FormCtrl | e) Unit
73+
74+
foreign import pristine
75+
" function pristine($ctrl){ \
76+
\ return function(){ \
77+
\ return $ctrl.$pristine; \
78+
\ }; \
79+
\ } "
80+
:: forall e. FormController -> Eff (ngform :: FormCtrl | e) Boolean
81+
82+
foreign import dirty
83+
" function dirty($ctrl){ \
84+
\ return function(){ \
85+
\ return $ctrl.$dirty; \
86+
\ }; \
87+
\ } "
88+
:: forall e. FormController -> Eff (ngform :: FormCtrl | e) Boolean
89+
90+
foreign import valid
91+
" function valid($ctrl){ \
92+
\ return function(){ \
93+
\ return $ctrl.$valid; \
94+
\ }; \
95+
\ } "
96+
:: forall e. FormController -> Eff (ngform :: FormCtrl | e) Boolean
97+
98+
foreign import invalid
99+
" function invalid($ctrl){ \
100+
\ return function(){ \
101+
\ return $ctrl.$invalid; \
102+
\ }; \
103+
\ } "
104+
:: forall e. FormController -> Eff (ngform :: FormCtrl | e) Boolean
105+
106+
foreign import error
107+
" function error($ctrl){ \
108+
\ return function(){ \
109+
\ return $ctrl.$error; \
110+
\ }; \
111+
\ } "
112+
:: forall e a. FormController -> Eff (ngform :: FormCtrl | e) { | a }

0 commit comments

Comments
 (0)