diff options
author | eric thul <thul.eric@gmail.com> | 2015-08-11 20:27:04 -0400 |
---|---|---|
committer | eric thul <thul.eric@gmail.com> | 2015-08-11 20:27:04 -0400 |
commit | fa01c5a4cb42d80ac147dc5ab512a0795dbe14da (patch) | |
tree | 8bdb1f4c24a31c7fd5c69fcd804e8428ae6c49b6 /src/PursLoader/LoaderRef.purs | |
parent | eae2e182cec2d521166e5775294b52300c42f069 (diff) | |
download | purs-loader-fa01c5a4cb42d80ac147dc5ab512a0795dbe14da.tar.gz purs-loader-fa01c5a4cb42d80ac147dc5ab512a0795dbe14da.tar.zst purs-loader-fa01c5a4cb42d80ac147dc5ab512a0795dbe14da.zip |
Moving files to match module
Diffstat (limited to 'src/PursLoader/LoaderRef.purs')
-rw-r--r-- | src/PursLoader/LoaderRef.purs | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/PursLoader/LoaderRef.purs b/src/PursLoader/LoaderRef.purs new file mode 100644 index 0000000..f1efa04 --- /dev/null +++ b/src/PursLoader/LoaderRef.purs | |||
@@ -0,0 +1,74 @@ | |||
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 | ||