diff options
Diffstat (limited to 'src/PursLoader/LoaderRef.purs')
-rw-r--r-- | src/PursLoader/LoaderRef.purs | 56 |
1 files changed, 11 insertions, 45 deletions
diff --git a/src/PursLoader/LoaderRef.purs b/src/PursLoader/LoaderRef.purs index f1efa04..33c4f7e 100644 --- a/src/PursLoader/LoaderRef.purs +++ b/src/PursLoader/LoaderRef.purs | |||
@@ -9,6 +9,8 @@ module PursLoader.LoaderRef | |||
9 | , resourcePath | 9 | , resourcePath |
10 | ) where | 10 | ) where |
11 | 11 | ||
12 | import Prelude (Unit()) | ||
13 | |||
12 | import Control.Monad.Eff (Eff()) | 14 | import Control.Monad.Eff (Eff()) |
13 | import Control.Monad.Eff.Exception (Error()) | 15 | import Control.Monad.Eff.Exception (Error()) |
14 | 16 | ||
@@ -19,56 +21,20 @@ data LoaderRef | |||
19 | 21 | ||
20 | foreign import data Loader :: ! | 22 | foreign import data Loader :: ! |
21 | 23 | ||
22 | foreign import asyncFn """ | 24 | foreign import asyncFn :: forall eff a. Fn3 (Maybe Error -> Boolean) |
23 | function asyncFn(isJust, fromMaybe, ref){ | 25 | (Error -> Maybe Error -> Error) |
24 | return function(){ | 26 | LoaderRef |
25 | var callback = ref.async(); | 27 | (Eff (loader :: Loader | eff) (Maybe Error -> a -> Eff (loader :: Loader | eff) Unit)) |
26 | return function(error){ | ||
27 | return function(value){ | ||
28 | return function(){ | ||
29 | return isJust(error) ? callback(fromMaybe(new Error())(error)) | ||
30 | : callback(null, value); | ||
31 | }; | ||
32 | }; | ||
33 | }; | ||
34 | }; | ||
35 | }""" :: forall eff a. Fn3 (Maybe Error -> Boolean) | ||
36 | (Error -> Maybe Error -> Error) | ||
37 | LoaderRef | ||
38 | (Eff (loader :: Loader | eff) (Maybe Error -> a -> Eff (loader :: Loader | eff) Unit)) | ||
39 | 28 | ||
40 | async :: forall eff a. LoaderRef -> Eff (loader :: Loader | eff) (Maybe Error -> a -> Eff (loader :: Loader | eff) Unit) | 29 | async :: forall eff a. LoaderRef -> Eff (loader :: Loader | eff) (Maybe Error -> a -> Eff (loader :: Loader | eff) Unit) |
41 | async ref = runFn3 asyncFn isJust fromMaybe ref | 30 | async ref = runFn3 asyncFn isJust fromMaybe ref |
42 | 31 | ||
43 | foreign import cacheable """ | 32 | foreign import cacheable :: forall eff. LoaderRef -> Eff (loader :: Loader | eff) Unit |
44 | function cacheable(ref){ | ||
45 | return function(){ | ||
46 | return ref.cacheable && ref.cacheable(); | ||
47 | }; | ||
48 | }""" :: forall eff. LoaderRef -> Eff (loader :: Loader | eff) Unit | ||
49 | 33 | ||
50 | foreign import query """ | 34 | foreign import query :: LoaderRef -> String |
51 | function query(ref){ | ||
52 | return ref.query; | ||
53 | }""" :: LoaderRef -> String | ||
54 | 35 | ||
55 | foreign import clearDependencies """ | 36 | foreign import clearDependencies :: forall eff. LoaderRef -> Eff (loader :: Loader | eff) Unit |
56 | function clearDependencies(ref){ | ||
57 | return function(){ | ||
58 | return ref.clearDependencies(); | ||
59 | }; | ||
60 | }""" :: forall eff. LoaderRef -> Eff (loader :: Loader | eff) Unit | ||
61 | 37 | ||
62 | foreign import resourcePath """ | 38 | foreign import resourcePath :: LoaderRef -> String |
63 | function resourcePath(ref){ | ||
64 | return ref.resourcePath; | ||
65 | }""" :: LoaderRef -> String | ||
66 | 39 | ||
67 | foreign import addDependency """ | 40 | foreign import addDependency :: forall eff. LoaderRef -> String -> Eff (loader :: Loader | eff) Unit |
68 | function addDependency(ref){ | ||
69 | return function(dep){ | ||
70 | return function(){ | ||
71 | return ref.addDependency(dep); | ||
72 | }; | ||
73 | }; | ||
74 | }""" :: forall eff. LoaderRef -> String -> Eff (loader :: Loader | eff) Unit | ||