diff options
Diffstat (limited to 'src/LoaderRef.purs')
-rw-r--r-- | src/LoaderRef.purs | 74 |
1 files changed, 0 insertions, 74 deletions
diff --git a/src/LoaderRef.purs b/src/LoaderRef.purs deleted file mode 100644 index f1efa04..0000000 --- a/src/LoaderRef.purs +++ /dev/null | |||
@@ -1,74 +0,0 @@ | |||
1 | module PursLoader.LoaderRef | ||
2 | ( LoaderRef() | ||
3 | , Loader() | ||
4 | , async | ||
5 | , cacheable | ||
6 | , query | ||
7 | , clearDependencies | ||
8 | , addDependency | ||
9 | , resourcePath | ||
10 | ) where | ||
11 | |||
12 | import Control.Monad.Eff (Eff()) | ||
13 | import Control.Monad.Eff.Exception (Error()) | ||
14 | |||
15 | import Data.Function (Fn3(), runFn3) | ||
16 | import Data.Maybe (Maybe(), fromMaybe, isJust) | ||
17 | |||
18 | data LoaderRef | ||
19 | |||
20 | foreign import data Loader :: ! | ||
21 | |||
22 | foreign import asyncFn """ | ||
23 | function asyncFn(isJust, fromMaybe, ref){ | ||
24 | return function(){ | ||
25 | var callback = ref.async(); | ||
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 | |||
40 | 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 | ||
42 | |||
43 | foreign import cacheable """ | ||
44 | function cacheable(ref){ | ||
45 | return function(){ | ||
46 | return ref.cacheable && ref.cacheable(); | ||
47 | }; | ||
48 | }""" :: forall eff. LoaderRef -> Eff (loader :: Loader | eff) Unit | ||
49 | |||
50 | foreign import query """ | ||
51 | function query(ref){ | ||
52 | return ref.query; | ||
53 | }""" :: LoaderRef -> String | ||
54 | |||
55 | foreign import clearDependencies """ | ||
56 | function clearDependencies(ref){ | ||
57 | return function(){ | ||
58 | return ref.clearDependencies(); | ||
59 | }; | ||
60 | }""" :: forall eff. LoaderRef -> Eff (loader :: Loader | eff) Unit | ||
61 | |||
62 | foreign import resourcePath """ | ||
63 | function resourcePath(ref){ | ||
64 | return ref.resourcePath; | ||
65 | }""" :: LoaderRef -> String | ||
66 | |||
67 | foreign import addDependency """ | ||
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 | ||