|
| 1 | +module Angular.Parse |
| 2 | + ( NgParse() |
| 3 | + , Parse() |
| 4 | + , ParseEff() |
| 5 | + , Expression() |
| 6 | + , Getter() |
| 7 | + , Setter() |
| 8 | + , parse |
| 9 | + , get |
| 10 | + , assign |
| 11 | + , literal |
| 12 | + , constant |
| 13 | + , set |
| 14 | + ) where |
| 15 | + |
| 16 | +import Control.Monad.Eff |
| 17 | +import Data.Function |
| 18 | +import Data.Maybe |
| 19 | + |
| 20 | +foreign import data Parse :: * |
| 21 | + |
| 22 | +foreign import data NgParse :: ! |
| 23 | + |
| 24 | +foreign import data Getter :: * -> * |
| 25 | + |
| 26 | +foreign import data Setter :: * -> * |
| 27 | + |
| 28 | +type ParseEff e r = Eff (ngparse :: NgParse | e) r |
| 29 | + |
| 30 | +type Expression = String |
| 31 | + |
| 32 | +foreign import parseFn |
| 33 | + " function parseFn(expression, $parse){ \ |
| 34 | + \ return function(){ \ |
| 35 | + \ return $parse(expression); \ |
| 36 | + \ }; \ |
| 37 | + \ } " |
| 38 | + :: forall e a. Fn2 Expression Parse (ParseEff e (Getter a)) |
| 39 | + |
| 40 | +parse :: forall e a. Expression -> Parse -> ParseEff e (Getter a) |
| 41 | +parse = runFn2 parseFn |
| 42 | + |
| 43 | +foreign import getFn |
| 44 | + " function getFn(context, locals, getter){ \ |
| 45 | + \ return function(){ \ |
| 46 | + \ return getter(context, locals); \ |
| 47 | + \ }; \ |
| 48 | + \ } " |
| 49 | + :: forall e a b c. Fn3 { | a } { | b } (Getter c) (ParseEff e c) |
| 50 | + |
| 51 | +get :: forall e a b c. { | a } -> { | b } -> Getter c -> ParseEff e c |
| 52 | +get = runFn3 getFn |
| 53 | + |
| 54 | +foreign import assignFn |
| 55 | + " function assignFn(nothing, just, getter){ \ |
| 56 | + \ var fn = getter.assign; \ |
| 57 | + \ return angular.isFunction(fn) ? just(fn) : nothing; \ |
| 58 | + \ } " |
| 59 | + :: forall a. Fn3 (Maybe (Setter a)) |
| 60 | + (Setter a -> Maybe (Setter a)) |
| 61 | + (Getter a) |
| 62 | + (Maybe (Setter a)) |
| 63 | + |
| 64 | +assign :: forall a. Getter a -> Maybe (Setter a) |
| 65 | +assign = runFn3 assignFn Nothing Just |
| 66 | + |
| 67 | +foreign import literal |
| 68 | + " function literal(getter){ \ |
| 69 | + \ return getter.literal; \ |
| 70 | + \ } " |
| 71 | + :: forall a. Getter a -> Boolean |
| 72 | + |
| 73 | +foreign import constant |
| 74 | + " function constant(getter){ \ |
| 75 | + \ return getter.constant; \ |
| 76 | + \ } " |
| 77 | + :: forall a. Getter a -> Boolean |
| 78 | + |
| 79 | +foreign import setFn |
| 80 | + " function setFn(context, value, setter){ \ |
| 81 | + \ return function(){ \ |
| 82 | + \ return setter(context, value); \ |
| 83 | + \ }; \ |
| 84 | + \ } " |
| 85 | + :: forall e a b. Fn3 { | a } b (Setter b) (ParseEff e b) |
| 86 | + |
| 87 | +set :: forall e a b. { | a } -> b -> Setter b -> ParseEff e b |
| 88 | +set = runFn3 setFn |
0 commit comments