Skip to content

Commit aa72cff

Browse files
committed
Merge pull request #14 from dylex/master
DI: Automatically infer and annotate dependencies for injection
2 parents cc0b870 + c527f8c commit aa72cff

File tree

5 files changed

+320
-27
lines changed

5 files changed

+320
-27
lines changed

MODULE.md

100644100755
Lines changed: 154 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,102 @@
101101
removeAll :: forall e. Cache -> CacheEff e Unit
102102

103103

104+
## Module Angular.DI
105+
106+
### Types
107+
108+
data Annotated :: * -> *
109+
110+
newtype RootElement where
111+
RootElement :: Element -> RootElement
112+
113+
newtype RootScope a where
114+
RootScope :: Scope a -> RootScope
115+
116+
117+
### Type Classes
118+
119+
class Dependency a where
120+
name :: String
121+
122+
class Injectable a where
123+
dependencies :: a -> [String]
124+
125+
126+
### Type Class Instances
127+
128+
instance dependencyAnimate :: Dependency Animate
129+
130+
instance dependencyAttributes :: Dependency Attributes
131+
132+
instance dependencyCacheFactory :: Dependency CacheFactory
133+
134+
instance dependencyElement :: Dependency Element
135+
136+
instance dependencyHttp :: Dependency Http
137+
138+
instance dependencyInjector :: Dependency Injector
139+
140+
instance dependencyInterpolate :: Dependency Interpolate
141+
142+
instance dependencyInterval :: Dependency Interval
143+
144+
instance dependencyLocation :: Dependency Location
145+
146+
instance dependencyLog :: Dependency Log
147+
148+
instance dependencyParse :: Dependency Parse
149+
150+
instance dependencyQ :: Dependency Q
151+
152+
instance dependencyRootElement :: Dependency RootElement
153+
154+
instance dependencyRootScope :: Dependency (RootScope a)
155+
156+
instance dependencyScope :: Dependency (Scope a)
157+
158+
instance dependencyThis :: Dependency (This a)
159+
160+
instance dependencyTimeout :: Dependency Timeout
161+
162+
instance injectableEff :: Injectable (Eff e r)
163+
164+
instance injectableFn :: (Dependency a, Injectable b) => Injectable (a -> b)
165+
166+
instance serviceAnimate :: Service Animate
167+
168+
instance serviceCacheFactory :: Service CacheFactory
169+
170+
instance serviceHttp :: Service Http
171+
172+
instance serviceInjector :: Service Injector
173+
174+
instance serviceInterpolate :: Service Interpolate
175+
176+
instance serviceInterval :: Service Interval
177+
178+
instance serviceLocation :: Service Location
179+
180+
instance serviceLog :: Service Log
181+
182+
instance serviceParse :: Service Parse
183+
184+
instance serviceQ :: Service Q
185+
186+
instance serviceRootElement :: Service RootElement
187+
188+
instance serviceRootScope :: Service (RootScope a)
189+
190+
instance serviceTimeout :: Service Timeout
191+
192+
193+
### Values
194+
195+
annotate :: forall a. (Injectable a) => a -> Annotated a
196+
197+
get :: forall e a. (Service a) => Injector -> InjEff e a
198+
199+
104200
## Module Angular.Deferred
105201

106202
### Types
@@ -605,6 +701,10 @@
605701

606702
finally' :: forall e r a b. Eff e r -> Promise a b -> Promise a b
607703

704+
pureReject :: forall a b. a -> Promise a b
705+
706+
pureResolve :: forall a b. b -> Promise a b
707+
608708
then' :: forall a b c d. (b -> Promise c d) -> Promise a b -> Promise c d
609709

610710
then'' :: forall a b c d. (b -> Promise c d) -> (a -> Promise c d) -> Promise a b -> Promise c d
@@ -654,9 +754,9 @@
654754
### Types
655755

656756
data ApplyExpr e r a where
657-
DefaultApplyExpr :: ApplyExpr e r a
658-
StringApplyExpr :: String -> ApplyExpr e r a
659-
FnApplyExpr :: Scope a -> Eff e r -> ApplyExpr e r a
757+
DefaultApplyExpr :: ApplyExpr
758+
StringApplyExpr :: String -> ApplyExpr
759+
FnApplyExpr :: (Scope a -> Eff e r) -> ApplyExpr
660760

661761
type Event e a b = { defaultPrevented :: Boolean, preventDefault :: Eff e Unit, stopPropagation :: Eff e Unit, name :: String, currentScope :: Scope b, targetScope :: Scope a }
662762

@@ -926,23 +1026,23 @@
9261026
data NgHttp :: !
9271027

9281028
data RequestData a where
929-
NoRequestData :: RequestData a
930-
StringRequestData :: String -> RequestData a
931-
ObjectRequestData :: a -> RequestData a
1029+
NoRequestData :: RequestData
1030+
StringRequestData :: String -> RequestData
1031+
ObjectRequestData :: a -> RequestData
9321032

9331033
type RequestDataFn a = { objectRequestData :: a -> RequestData a, stringRequestData :: String -> RequestData a, noRequestData :: RequestData a }
9341034

9351035
data ResponseData a where
936-
NoResponseData :: ResponseData a
937-
DefaultResponseData :: String -> ResponseData a
938-
ArrayBufferResponseData :: D.ArrayBuffer -> ResponseData a
939-
BlobResponseData :: D.Blob -> ResponseData a
940-
DocumentResponseData :: D.Document -> ResponseData a
941-
JsonResponseData :: a -> ResponseData a
942-
TextResponseData :: String -> ResponseData a
943-
MozBlobResponseData :: D.MozBlob -> ResponseData a
944-
MozChunkedTextResponseData :: D.MozChunkedText -> ResponseData a
945-
MozChunkedArrayBufferResponseData :: D.MozChunkedArrayBuffer -> ResponseData a
1036+
NoResponseData :: ResponseData
1037+
DefaultResponseData :: String -> ResponseData
1038+
ArrayBufferResponseData :: D.ArrayBuffer -> ResponseData
1039+
BlobResponseData :: D.Blob -> ResponseData
1040+
DocumentResponseData :: D.Document -> ResponseData
1041+
JsonResponseData :: a -> ResponseData
1042+
TextResponseData :: String -> ResponseData
1043+
MozBlobResponseData :: D.MozBlob -> ResponseData
1044+
MozChunkedTextResponseData :: D.MozChunkedText -> ResponseData
1045+
MozChunkedArrayBufferResponseData :: D.MozChunkedArrayBuffer -> ResponseData
9461046

9471047
type ResponseDataFn a = { mozChunkedArrayBufferResponseData :: D.MozChunkedArrayBuffer -> ResponseData a, mozChunkedTextResponseData :: D.MozChunkedText -> ResponseData a, mozBlobResponseData :: D.MozBlob -> ResponseData a, textResponseData :: String -> ResponseData a, jsonResponseData :: a -> ResponseData a, documentResponseData :: D.Document -> ResponseData a, blobResponseData :: D.Blob -> ResponseData a, arrayBufferResponseData :: D.ArrayBuffer -> ResponseData a, defaultResponseData :: String -> ResponseData a, noResponseData :: ResponseData a }
9481048

@@ -1005,4 +1105,42 @@
10051105
writeRequestData :: forall a. RequestData a -> ForeignRequestData
10061106

10071107

1108+
## Module Angular.Promise.Eff
1109+
1110+
### Types
1111+
1112+
newtype PromiseEff e f a b where
1113+
PromiseEff :: Promise (Eff e a) (Eff f b) -> PromiseEff
1114+
1115+
1116+
### Type Class Instances
1117+
1118+
instance applicativePromiseEff :: Applicative (PromiseEff e f a)
1119+
1120+
instance applyPromise :: Apply (PromiseEff e f a)
1121+
1122+
instance bifunctorPromise :: Bifunctor (PromiseEff e f)
1123+
1124+
instance bindPromiseEff :: Bind (PromiseEff e f a)
1125+
1126+
instance functorPromiseEff :: Functor (PromiseEff e f a)
1127+
1128+
1129+
### Values
1130+
1131+
liftPromiseEff :: forall e f a b. Eff e a -> Eff f b -> PromiseEff e f a b
1132+
1133+
liftPromiseEff' :: forall e f a b. Eff f b -> PromiseEff e f a b
1134+
1135+
promiseEff :: forall e f a b. Promise a b -> PromiseEff e f a b
1136+
1137+
promiseEff' :: forall e f a b. Promise a (Eff f b) -> PromiseEff e f a b
1138+
1139+
promiseEff'' :: forall e f a b. Promise (Eff e a) b -> PromiseEff e f a b
1140+
1141+
runPromiseEff :: forall e f a b. PromiseEff e f a b -> Promise (Eff e a) (Eff f b)
1142+
1143+
unsafeRunPromiseEff :: forall e f a b. PromiseEff e f a b -> Promise a b
1144+
1145+
10081146

bower.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
"purescript-tuples": "0.2.1"
2626
},
2727
"devDependencies": {
28-
"angular": "1.2.23",
28+
"angular": "1.2.25",
2929
"todomvc-common": "0.1.9",
3030
"purescript-strings": "0.2.1",
3131
"purescript-arrays": "0.2.0",
32-
"purescript-control": "0.2.0"
32+
"purescript-control": "0.2.1"
3333
}
3434
}

examples/Todomvc/Controller.purs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ watchLocationPath scope =
102102
_ -> extendScope { statusFilter: { } } scope
103103
in watch expr (return listener) false scope
104104

105-
controller scope location = do
105+
todoctrl scope this location = do
106+
t <- readThis this
106107
path <- getPath location
107108
if S.length path == 0 then setPath "/" location else return ""
108109
watchRemainingCount scope
@@ -126,10 +127,3 @@ controller scope location = do
126127
, doneEditing: doneEditing scope
127128
, removeTodo: removeTodo scope
128129
, revertEditing: revertEditing scope } scope
129-
130-
foreign import todoctrl
131-
" /*@ngInject*/function todoctrl($scope, $location) { \
132-
\ var impl = controller($scope)($location); \
133-
\ return impl.apply(this, []); \
134-
\ } "
135-
:: forall e a. Scope a -> Location -> Eff e Unit

examples/Todomvc/Main.purs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
module Todomvc.Main where
22

33
import Angular.Module (controller, directive, ngmodule')
4+
import Angular.DI (annotate)
45

56
import Todomvc.Controller (todoctrl)
67
import Todomvc.Escape (escape)
78
import Todomvc.Focus (focus)
89

910
main = do
1011
m <- ngmodule' "todomvc" []
11-
controller "TodoCtrl" todoctrl m
12+
controller "TodoCtrl" (annotate todoctrl) m
1213
directive "todoEscape" escape m
1314
directive "todoFocus" focus m

0 commit comments

Comments
 (0)