-
Notifications
You must be signed in to change notification settings - Fork 0
/
timeline-element.fs
55 lines (45 loc) · 1.63 KB
/
timeline-element.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
namespace Van
module TimelineElement =
open Fable.Core.JsInterop
type StateElement<'a> =
{``val``: 'a} // native VanJS state object
// val is a reserved word in F#
// so we use backticks to escape it
let state<'a> (a: 'a): StateElement<'a> =
importMember "../ts/state"
type Timeline<'a> =
{ mutable lastVal: 'a
mutable _fns: list<'a -> unit>
el: StateElement<'a> } // <== add native VanJS state object
let Timeline =
fun a ->
{ lastVal = a
_fns = []
el = state a } // <== add native VanJS state object
let nextT =
fun a timeline ->
timeline.lastVal <- a // mutable
timeline._fns
|> List.iter (fun f -> f a) //perform all fns in the list
// Update the native VanJS state object simultaneously.
timeline.el?``val`` <- a // <======================= add
//----------------------------------------------------
timeline // return the modified timeline
let bindT =
fun monadf timelineA ->
let timelineB = timelineA.lastVal |> monadf
let newFn =
fun a ->
timelineB
|> nextT (a |> monadf).lastVal
|> ignore
timelineA._fns <- timelineA._fns @ [ newFn ]
timelineB
//----------------------------------------------
let mapT =
fun f -> (f >> Timeline) |> bindT
//==============================================================
let logT =
fun a ->
log a
Timeline a