Verified Commit 1f95b6f6 authored by Camil Staps's avatar Camil Staps 🚀

Add back .$! in iTasks.UI.JS.Interface

parent 54983ea2
......@@ -12,9 +12,6 @@ import iTasks.UI.JS.Interface
import iTasks.UI.Prompt
import iTasks.WF.Tasks.Interaction
// TODO: remove
import Text.GenJSON
Start w = doTasks task w
//import iTasks.Internal.SDS
......@@ -37,6 +34,7 @@ task = updateInformation "test"
where
initUI :: !(JSObj ()) !*JSWorld -> *JSWorld
initUI comp w
# w = (jsGlobal "console.log" .$! (1,2,3)) w
# (jsInitDOMEl,w) = jsWrapFun (initDOMEl comp) w
# w = (comp .# "initDOMEl" .= jsInitDOMEl) w
= w
......
......@@ -9,26 +9,41 @@ definition module iTasks.UI.JS.Interface
:: JSObject a
:: JSFunction a
class toJS a :: !a -> JSVal a
class toJS a :: !a -> JSVal b
instance toJS Int, String
jsNull :: JSVal a
/**
* Should not be used outside this library. The argument is a reference to a
* DOM element stored somewhere in JavaScript.
*/
referenceToJS :: !Int -> JSVal a
/**
* Access properties of a JavaScript value.
*/
class (.#) infixl 3 attr :: !(JSVal a) !attr -> JSObj b
class (.#) infixl 3 attr :: !(JSVal a) !attr -> JSVal b
instance .# String // object access; may contain dots
instance .# Int // array access
(.=) infixl 2 :: !(JSObj a) !(JSVal b) !*JSWorld -> *JSWorld
(.=) infixl 1 :: !(JSObj a) !(JSVal b) !*JSWorld -> *JSWorld
class toJSArgs a :: !a -> [JSVal a]
instance toJSArgs Int, String, ()
instance toJSArgs (a,b) | toJS a & toJS b
instance toJSArgs (a,b,c) | toJS a & toJS b & toJS c
instance toJSArgs (a,b,c,d) | toJS a & toJS b & toJS c & toJS d
instance toJSArgs (a,b,c,d,e) | toJS a & toJS b & toJS c & toJS d & toJS e
instance toJSArgs (a,b,c,d,e,f) | toJS a & toJS b & toJS c & toJS d & toJS e & toJS f
(.$!) infixl 2 :: !(JSFun a) !b !*JSWorld -> *JSWorld | toJSArgs b
jsGlobal :: !String -> JSVal a
jsNull :== jsGlobal "null"
jsThis :== jsGlobal "this"
jsWindow :== jsGlobal "window"
jsDocument :== jsGlobal "document"
/**
* Should not be used outside this library. The argument is a reference to a
* DOM element stored somewhere in JavaScript.
*/
referenceToJS :: !Int -> JSVal a
/**
* @param A function of the type (a b .. z *JSWorld -> *JSWorld)
......
implementation module iTasks.UI.JS.Interface
import StdEnv
import Text
:: *JSWorld = JSWorld
......@@ -9,7 +10,7 @@ import StdEnv
| JSString !String
| JSRef !Int // a reference to shared_js_values
| JSCleanRef !Int // a reference to shared_clean_values
| JSNull
| JSVar !String
| E.b c: JSSel !(JSVal b) !(JSVal c) // b[c]
| E.b: JSSelPath !(JSVal b) !String // b.path1.path2...pathn
......@@ -24,7 +25,7 @@ where
JSString s -> "'"+++s+++"'" // TODO escape
JSRef i -> "abc_interpreter.shared_js_values["+++toString i+++"]"
JSCleanRef i -> "abc_interpreter.apply_to_clean_value("+++toString i+++")"
JSNull -> "null"
JSVar v -> v
JSSel obj attr -> toString obj+++"["+++toString attr+++"]"
JSSelPath obj path -> toString obj+++"."+++path
......@@ -33,6 +34,49 @@ js_set :: !(JSVal a) !(JSVal b) !*JSWorld -> *JSWorld
js_set var val w = case eval_js (toString var+++"="+++toString val) of
True -> w
instance toJS Int where toJS i = JSInt i
instance toJS String where toJS s = JSString s
instance .# String where .# obj path = JSSelPath obj path
instance .# Int where .# arr i = JSSel arr (JSInt i)
(.=) infixl 1 :: !(JSObj a) !(JSVal b) !*JSWorld -> *JSWorld
(.=) sel v w = js_set sel v w
instance toJSArgs Int where toJSArgs i = [toJS i]
instance toJSArgs String where toJSArgs s = [toJS s]
instance toJSArgs () where toJSArgs _ = []
instance toJSArgs (a,b) | toJS a & toJS b
where toJSArgs (a,b) = [toJS a, toJS b]
instance toJSArgs (a,b,c) | toJS a & toJS b & toJS c
where toJSArgs (a,b,c) = [toJS a, toJS b, toJS c]
instance toJSArgs (a,b,c,d) | toJS a & toJS b & toJS c & toJS d
where toJSArgs (a,b,c,d) = [toJS a, toJS b, toJS c, toJS d]
instance toJSArgs (a,b,c,d,e) | toJS a & toJS b & toJS c & toJS d & toJS e
where toJSArgs (a,b,c,d,e) = [toJS a, toJS b, toJS c, toJS d, toJS e]
instance toJSArgs (a,b,c,d,e,f) | toJS a & toJS b & toJS c & toJS d & toJS e & toJS f
where toJSArgs (a,b,c,d,e,f) = [toJS a, toJS b, toJS c, toJS d, toJS e, toJS f]
(.$!) infixl 2 :: !(JSFun a) !b !*JSWorld -> *JSWorld | toJSArgs b
(.$!) f args w = case eval_js call of
True -> w
where
call = toString f+++"("+++join "," [toString a \\ a <- toJSArgs args]+++")"
jsGlobal :: !String -> JSVal a
jsGlobal s = JSVar s
jsWrapFun :: !f !*JSWorld -> *(!JSFun f, !*JSWorld)
jsWrapFun f world = (cast (share f), world)
referenceToJS :: !Int -> JSVal a
referenceToJS ref = JSRef ref
eval_js :: !String -> Bool
eval_js s = code {
instruction 1
......@@ -56,21 +100,3 @@ cast :: !.a -> .b
cast _ = code {
no_op
}
instance toJS Int where toJS i = JSInt i
instance toJS String where toJS s = JSString s
jsNull :: JSVal a
jsNull = JSNull
referenceToJS :: !Int -> JSVal a
referenceToJS ref = JSRef ref
instance .# String where .# obj path = JSSelPath obj path
instance .# Int where .# arr i = JSSel arr (JSInt i)
(.=) infixl 2 :: !(JSObj a) !(JSVal b) !*JSWorld -> *JSWorld
(.=) sel v w = js_set sel v w
jsWrapFun :: !f !*JSWorld -> *(!JSFun f, !*JSWorld)
jsWrapFun f world = (cast (share f), world)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment