@@ -19,76 +19,46 @@ module Program =
19
19
open Browser
20
20
open Elmish
21
21
22
- // Use the new rendering API in React 18+
23
- let useRootApi = try int ReactBindings.React.version.[ .. 1 ] >= 18 with _ -> false
24
-
25
22
let withReactBatchedUsing lazyView2With placeholderId ( program : Program < _ , _ , _ , _ >) =
26
23
let setState =
27
24
let mutable lastRequest = None
25
+ let root = ReactDomClient.createRoot ( document.getElementById placeholderId)
28
26
29
- if useRootApi then
30
- let root = ReactDomClient.createRoot ( document.getElementById placeholderId)
31
-
32
- fun model dispatch ->
33
- match lastRequest with
34
- | Some r -> window.cancelAnimationFrame r
35
- | _ -> ()
36
-
37
- lastRequest <- Some ( window.requestAnimationFrame ( fun _ ->
38
- root.render ( lazyView2With ( fun x y -> obj.ReferenceEquals( x, y)) ( Program.view program) model dispatch)))
39
- else
40
- fun model dispatch ->
41
- match lastRequest with
42
- | Some r -> window.cancelAnimationFrame r
43
- | _ -> ()
27
+ fun model dispatch ->
28
+ match lastRequest with
29
+ | Some r -> window.cancelAnimationFrame r
30
+ | _ -> ()
44
31
45
- lastRequest <- Some ( window.requestAnimationFrame ( fun _ ->
46
- ReactDom.render(
47
- lazyView2With ( fun x y -> obj.ReferenceEquals( x, y)) ( Program.view program) model dispatch,
48
- document.getElementById placeholderId
49
- )))
32
+ lastRequest <- Some ( window.requestAnimationFrame ( fun _ ->
33
+ root.render ( lazyView2With ( fun x y -> obj.ReferenceEquals( x, y)) ( Program.view program) model dispatch)))
50
34
51
35
program
52
36
|> Program.withSetState setState
53
37
54
38
let withReactSynchronousUsing lazyView2With placeholderId ( program : Elmish.Program < _ , _ , _ , _ >) =
55
39
let setState =
56
- if useRootApi then
57
- let root = ReactDomClient.createRoot ( document.getElementById placeholderId)
40
+ let root = ReactDomClient.createRoot ( document.getElementById placeholderId)
58
41
59
- fun model dispatch ->
60
- root.render ( lazyView2With ( fun x y -> obj.ReferenceEquals( x, y)) ( Program.view program) model dispatch)
61
- else
62
- fun model dispatch ->
63
- ReactDom.render(
64
- lazyView2With ( fun x y -> obj.ReferenceEquals( x, y)) ( Program.view program) model dispatch,
65
- document.getElementById placeholderId
66
- )
42
+ fun model dispatch ->
43
+ root.render ( lazyView2With ( fun x y -> obj.ReferenceEquals( x, y)) ( Program.view program) model dispatch)
67
44
68
45
program
69
46
|> Program.withSetState setState
70
47
71
48
let withReactHydrateUsing lazyView2With placeholderId ( program : Elmish.Program < _ , _ , _ , _ >) =
72
49
let setState =
73
- if useRootApi then
74
- let mutable root = None
75
-
76
- fun model dispatch ->
77
- match root with
78
- | None ->
79
- root <-
80
- ReactDomClient.hydrateRoot (
81
- document.getElementById placeholderId,
82
- lazyView2With ( fun x y -> obj.ReferenceEquals( x, y)) ( Program.view program) model dispatch
83
- ) |> Some
84
- | Some root ->
85
- root.render ( lazyView2With ( fun x y -> obj.ReferenceEquals( x, y)) ( Program.view program) model dispatch)
86
- else
87
- fun model dispatch ->
88
- ReactDom.hydrate(
89
- lazyView2With ( fun x y -> obj.ReferenceEquals( x, y)) ( Program.view program) model dispatch,
90
- document.getElementById placeholderId
91
- )
50
+ let mutable root = None
51
+
52
+ fun model dispatch ->
53
+ match root with
54
+ | None ->
55
+ root <-
56
+ ReactDomClient.hydrateRoot (
57
+ document.getElementById placeholderId,
58
+ lazyView2With ( fun x y -> obj.ReferenceEquals( x, y)) ( Program.view program) model dispatch
59
+ ) |> Some
60
+ | Some root ->
61
+ root.render ( lazyView2With ( fun x y -> obj.ReferenceEquals( x, y)) ( Program.view program) model dispatch)
92
62
93
63
program
94
64
|> Program.withSetState setState
0 commit comments