Skip to content

Commit

Permalink
reactive widget fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
melsman committed Dec 21, 2018
1 parent 911dd53 commit 75be78c
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 44 deletions.
15 changes: 8 additions & 7 deletions js/test/rwidget.sig
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
signature RWIDGET = sig
signature RWIDGET = sig
type 'a b = 'a RWP.b
type blk = RHtml.blk
type blk = RHtml.blk
type inl = RHtml.inl
type attrs = RHtml.attrs
type color = Color.t

val box : color b -> blk -> blk
val pad : int b -> blk -> blk

val textField : attrs -> string b * inl

val textField : attrs -> string b * inl
(*
val map : (''a b -> ''b b) -> ''a list b -> ''b list b
val fold : (''a b -> ''b b) -> (''b b * ''b b -> ''b b) -> ''b b -> ''a list b -> ''b b
val mouseOver : inl -> bool b * inl
(*
*)
(*
val selectBox : (string * string) list -> string b * RHtml.blk (* head is default *)
val mouseOver : RHtml.blk * RHtml.blk -> RHtml.blk
val mapConcat : (''a b -> ''b elm b) -> ''b elm b -> ''a list b -> ''b elm b
*)
end
20 changes: 10 additions & 10 deletions js/test/rwidget.sml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
structure RWidget :> RWIDGET = struct
type 'a b = 'a RWP.b
type blk = RHtml.blk
type blk = RHtml.blk
type inl = RHtml.inl
type attrs = RHtml.attrs
type color = Color.t
Expand All @@ -13,8 +13,8 @@ structure RWidget :> RWIDGET = struct
diva [S("float", const "left"),S("background", arr Color.toString c)]
(diva [S("background", const "url(ul.gif) no-repeat top left")]
(diva [S("background", const "url(ur.gif) no-repeat top right")]
(diva [S("background", const "url(ll.gif) no-repeat bottom left")]
(diva [S("background", const "url(lr.gif) no-repeat bottom right")]
(diva [S("background", const "url(ll.gif) no-repeat bottom left")]
(diva [S("background", const "url(lr.gif) no-repeat bottom right")]
b))))

fun pad (i : int b) b =
Expand All @@ -24,13 +24,13 @@ structure RWidget :> RWIDGET = struct
b

fun textField (attrs: attrs) : string b * inl =
let val b = const ""
let val b = const ""
fun handler e = true before send b (Js.value e)
val attrs = E(Js.onkeyup, handler)::attrs
val f = inputa attrs
in (b,f)
end

(*
fun map (f: ''a b -> ''b b) (l:''a list b) : ''b list b =
let fun g (xs : ''a list) : ''b b list = List.map (f o const) xs
in flatten(arr (list o g) l)
Expand All @@ -39,7 +39,7 @@ structure RWidget :> RWIDGET = struct
infix &
fun fold (f: ''a b -> ''b b) (op & : ''b b * ''b b -> ''b b) (e:''b b) (l: ''a list b) : ''b b =
let fun g (nil : ''a list) : ''b b = e
| g (y::xs) =
| g (y::xs) =
List.foldl (fn (x,a) => f(const x) & a) (f(const y)) xs
in flatten(arr g l)
end
Expand All @@ -49,12 +49,12 @@ structure RWidget :> RWIDGET = struct
in (b, spana [E(Js.onmouseover, fn _ => true before send b true),
E(Js.onmouseout, fn _ => true before send b false)] e)
end

(*
*)
(*
val selectBox : (string * string) list -> string b * RHtml.blk (* head is default *)
val mouseOver : RHtml.blk * RHtml.blk -> RHtml.blk
val mapConcat : (''a b -> ''b elm b) -> ''b elm b -> ''a list b -> ''b elm b
*)
end
4 changes: 2 additions & 2 deletions js/test/rwp.sig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
signature ARROW0 = sig
type ('b,'c,'k) arr
val arr : (''b -> ''c) -> (''b,''c,'k) arr
val >>> : (''b,''c,'k)arr * (''c,''d,'k)arr -> (''b,''d,'k)arr
val >>> : (''b,''c,'k)arr * (''c,''d,'k)arr -> (''b,''d,'k)arr
val fst : (''b,''c,'k)arr -> (''b*''d,''c*''d,'k)arr
end

Expand All @@ -17,7 +17,7 @@ end
signature RWP =
sig
eqtype B eqtype E (* kinds: Behaviors (B) and Events (E) *)
type ('a,'k)t
eqtype ('a,'k)t
type 'a b = ('a, B)t
type 'a e = ('a, E)t
include ARROW where type ('a,'b,'k)arr = ('a,'k)t -> ('b,'k)t
Expand Down
59 changes: 34 additions & 25 deletions js/test/tdom2_ex1.sml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
signature WIDGET = sig
structure H : TDOM2
type color = string
datatype corner = NW | NE | SW | SE
val bgcolor : color ->
datatype corner = NW | NE | SW | SE
val bgcolor : color ->
val box : {color:color,corners:corner list} -> H.blk -> H.blk
val width : sz -> H.blk -> H.blk
val height : sz -> H.blk -> H.blk
val || :
val || :
end
*)
local
fun ppMouse (x,y) =
fun ppMouse (x,y) =
Int.toString x ^ " - " ^ Int.toString y

open RWP
Expand All @@ -20,7 +20,9 @@ open TDom infix & nonfix div
fun f 0 = nil
| f n = Int.toString n :: f(n-1)

val mmB = arr ppMouse (mouse())
val themouse = mouse()

val mmB = arr ppMouse themouse

val tB = timer 500
val aB = arr (fn x => IntInf.toInt(IntInf.mod(Time.toSeconds x, 10))) tB
Expand All @@ -33,12 +35,13 @@ val unlist : 'a list b -> 'a b list <<<==== does not make sense
val map : ('a b -> 'b b) -> 'a list b -> 'b list b
val fold : ('a b * 'c -> 'c) -> 'c -> 'a list b -> 'c
*)
(*
fun map (f: ''a b -> ''b b) (l:''a list b) : ''b list b =
let fun g (xs : ''a list) : ''b b list = List.map (f o const) xs
in
in
flatten(arr (list o g) l)
end

*)
fun color i =
arr (fn 0 => "blue"
| 1 => "black"
Expand All @@ -52,46 +55,52 @@ fun color i =
infix &
fun fold (f: ''a b -> ''b b) (op & : ''b b * ''b b -> ''b b) (e:''b b) (l: ''a list b) : ''b b =
let fun g (nil : ''a list) : ''b b = e
| g (y::xs) =
| g (y::xs) =
List.foldl (fn (x,a) => f(const x) & a) (f(const y)) xs
in
flatten(arr g l)
val v : ''b b b = RWP.arr g l
in
flatten v
end

fun cB() = ul (fold (lia [S("color", color aB)] o $) (op &) (li ($(const"No items"))) bB)

(*
fun pos(x,y) =
("\"position: absolute; left: " ^ Int.toString x ^ "px; top: "
^ Int.toString y ^ "px; height: 10px; width: 10px; padding: 1em\"")
val mouse_x = arr #1 themouse
val mouse_y = arr #2 themouse

val d = diva (Attrs[("style",arr pos (mouse()))]) ($(const "hello"))
*)
val px = arr (fn i => Int.toString i ^ "px")

val d = diva [S("position",const "absolute"),
S("left",px mouse_x),
S("top",px mouse_y),
S("height",const "10px"),
S("width",const "10px"),
S("padding",const "1em")]
(cB())

val a = h1($(arr Time.toString tB))
val a = h1($(arr Time.toString tB))
& h1($mmB)
& table (tr (td (cB()) & th(cB())))
& table (tr (td (cB()) & th(cB())))
& hr
(* & d *)
& d

fun toPx i = Int.toString i ^ "px"

fun mkBox c e =
diva [S("float", const "left"),S("background", const c)]
(diva [S("background", const "url(ul.gif) no-repeat top left")]
(diva [S("background", const "url(ur.gif) no-repeat top right")]
(diva [S("background", const "url(ll.gif) no-repeat bottom left")]
(diva [S("background", const "url(lr.gif) no-repeat bottom right")]
(diva [S("background", const "url(ll.gif) no-repeat bottom left")]
(diva [S("background", const "url(lr.gif) no-repeat bottom right")]
e))))

fun mkBox' c e =
mkBox c (diva [S("padding", arr (fn x => let val p = toPx (4*x)
in String.concat[p," ",p," ",p," ",p]
end) aB)]
end) aB)]
e)

val h = html(const "Hej",
bodya [S("fontFamily", const "arial, sans-serif")]
val h = html(const "Hej",
bodya [S("fontFamily", const "arial, sans-serif")]
(a & table (tr(td(mkBox' "#e5ecf9" ($mmB)) & td(mkBox "#05ecf9" ($mmB))))))

in
Expand Down

0 comments on commit 75be78c

Please sign in to comment.