Permalink
Browse files

Move time dependent development to Time module

  • Loading branch information...
1 parent ea4e3fb commit 027dbab74fc3165791b11bbd5cbb3716a113e207 @danmey committed Jan 14, 2012
Showing with 119 additions and 0 deletions.
  1. +17 −0 examples/flapjax_catchup/catchup.html
  2. +38 −0 examples/flapjax_catchup/catchup.ml
  3. +40 −0 examples/flapjax_catchup/demo.css
  4. +24 −0 lib/time.ml
@@ -0,0 +1,17 @@
+<html>
+<head>
+<title>Catch Up</title>
+<link rel="stylesheet" href="demo.css"/>
+</head>
+
+<body id="body" style="text-align: center; margin: 0px; overflow: hidden;">
+<div class="block">
+<div>
+update every <input type="text" id="frameRate" value="10" size="5"/> ms
+with a delay of <input type="text" id="delayRate" value="800" size="5"/> ms
+</div>
+<span id="count"></span>
+</div>
+
+</body>
+</html>
@@ -0,0 +1,38 @@
+(*------------------------------------------------------------------------------
+ This file is part of Dom_react.
+
+ Dom_react is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Foobar is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ ----------------------------------------------------------------------------*)
+
+
+open Dom_react
+
+let js = Js.string
+
+let onload () =
+ let (>>=) = Js.Opt.bind in
+ let return = Js.Opt.return in
+ let _ = Dom_html.document##getElementById (js"body") >>=
+ (fun body ->
+ let open Input in
+ let time = Named.int 50 "frameRate" in
+ let delay_time = Named.int 500 "delayRate" in
+
+ return ()) in
+ ()
+;;
+
+let () =
+ let e = Base.E.create Dom_html.window Base.E.onload in
+ ignore(Base.E.map onload e)
@@ -0,0 +1,40 @@
+body {
+ background-image: url(/images/graybg.jpg);
+ background-repeat: repeat-x;
+ background-color: #ffffff;
+ padding: 10px;
+ font-family: sans-serif;
+}
+
+.block {
+ border: 1px solid black;
+ padding: 10px;
+ background-color: #ffffff;
+}
+
+li {
+ padding: 5px;
+}
+
+.contrastBlock {
+ background-color: #000000;
+ border: 1px solid #666666;
+ color: #ffffff;
+ padding: 10px;
+}
+
+.fixedBlock {
+ border: 1px solid black;
+ font-family: Courier New, Andale Mono, monospace
+ padding: 10px;
+ background-color: #ffffff;
+}
+
+label {
+ display: block;
+ padding: 5px;
+}
+fieldset {
+ border-style: solid;
+ border-width: 3px;
+}
View
@@ -0,0 +1,24 @@
+let updater ms f =
+ let ms' = float ms in
+ let rec timeout_id = ref (lazy (Dom_html.window ## setTimeout (Js.wrap_callback loop, ms')))
+ and loop ev =
+ Dom_html.window ## clearTimeout (Lazy.force !timeout_id);
+ let () = f () in
+ timeout_id := (lazy Dom_html.window ## setTimeout (Js.wrap_callback loop, ms'));
+ ignore (Lazy.force !timeout_id);
+ in
+ ignore (Lazy.force !timeout_id)
+
+let create w prop updater =
+ let signal, send = React.S.create (prop w) in
+ updater (fun () -> send (prop w));
+ signal
+
+let time ?(accuracy=0.01) ?(start=0.) () =
+ let time = ref start in
+ let signal, send = React.S.create !time in
+ updater (int_of_float (accuracy *. 1000.)) (fun () ->
+ time := !time +. accuracy;
+ send !time);
+ signal
+

0 comments on commit 027dbab

Please sign in to comment.