Skip to content

Commit a65629b

Browse files
committed
add Location core component
1 parent 5e368ea commit a65629b

File tree

1 file changed

+169
-172
lines changed

1 file changed

+169
-172
lines changed
+169-172
Original file line numberDiff line numberDiff line change
@@ -1,183 +1,180 @@
11
namespace Dash.NET.DCC
22

3-
//open Dash.NET
4-
//open System
5-
//open Plotly.NET
6-
//open Newtonsoft.Json
7-
//open System.Collections.Generic
3+
open Dash.NET
4+
open Plotly.NET
85

9-
/////<summary>
10-
/////Update and track the current window.location object through the window.history state.
11-
/////Use in conjunction with the &#96;dash_core_components.Link&#96; component to make apps with multiple pages.
12-
/////</summary>
13-
//[<RequireQualifiedAccess>]
14-
//module Location =
15-
// ///<summary>
16-
// ///• pathname (string) - pathname in window.location - e.g., "/my/full/pathname"
17-
// ///&#10;
18-
// ///• search (string) - search in window.location - e.g., "?myargument=1"
19-
// ///&#10;
20-
// ///• hash (string) - hash in window.location - e.g., "#myhash"
21-
// ///&#10;
22-
// ///• href (string) - href in window.location - e.g., "/my/full/pathname?myargument=1#myhash"
23-
// ///&#10;
24-
// ///• refresh (boolean; default true) - Refresh the page when the location is updated?
25-
// ///</summary>
26-
// type Prop =
27-
// | Pathname of string
28-
// | Search of string
29-
// | Hash of string
30-
// | Href of string
31-
// | Refresh of bool
32-
// static member toDynamicMemberDef(prop: Prop) =
33-
// match prop with
34-
// | Pathname (p) -> "pathname", box p
35-
// | Search (p) -> "search", box p
36-
// | Hash (p) -> "hash", box p
37-
// | Href (p) -> "href", box p
38-
// | Refresh (p) -> "refresh", box p
6+
///<summary>
7+
///Update and track the current window.location object through the window.history state.
8+
///Use in conjunction with the &#96;dash_core_components.Link&#96; component to make apps with multiple pages.
9+
///</summary>
10+
[<RequireQualifiedAccess>]
11+
module Location =
12+
///<summary>
13+
///• pathname (string) - pathname in window.location - e.g., "/my/full/pathname"
14+
///&#10;
15+
///• search (string) - search in window.location - e.g., "?myargument=1"
16+
///&#10;
17+
///• hash (string) - hash in window.location - e.g., "#myhash"
18+
///&#10;
19+
///• href (string) - href in window.location - e.g., "/my/full/pathname?myargument=1#myhash"
20+
///&#10;
21+
///• refresh (boolean; default true) - Refresh the page when the location is updated?
22+
///</summary>
23+
type Prop =
24+
| Pathname of string
25+
| Search of string
26+
| Hash of string
27+
| Href of string
28+
| Refresh of bool
29+
static member toDynamicMemberDef(prop: Prop) =
30+
match prop with
31+
| Pathname (p) -> "pathname", box p
32+
| Search (p) -> "search", box p
33+
| Hash (p) -> "hash", box p
34+
| Href (p) -> "href", box p
35+
| Refresh (p) -> "refresh", box p
3936

40-
// ///<summary>
41-
// ///A list of children or a property for this dash component
42-
// ///</summary>
43-
// type Attr =
44-
// | Prop of Prop
45-
// | Children of list<DashComponent>
46-
// ///<summary>
47-
// ///pathname in window.location - e.g., "/my/full/pathname"
48-
// ///</summary>
49-
// static member pathname(p: string) = Prop(Pathname p)
50-
// ///<summary>
51-
// ///search in window.location - e.g., "?myargument=1"
52-
// ///</summary>
53-
// static member search(p: string) = Prop(Search p)
54-
// ///<summary>
55-
// ///hash in window.location - e.g., "#myhash"
56-
// ///</summary>
57-
// static member hash(p: string) = Prop(Hash p)
58-
// ///<summary>
59-
// ///href in window.location - e.g., "/my/full/pathname?myargument=1#myhash"
60-
// ///</summary>
61-
// static member href(p: string) = Prop(Href p)
62-
// ///<summary>
63-
// ///Refresh the page when the location is updated?
64-
// ///</summary>
65-
// static member refresh(p: bool) = Prop(Refresh p)
66-
// ///<summary>
67-
// ///The child or children of this dash component
68-
// ///</summary>
69-
// static member children(value: int) = Children([ Html.Html.text value ])
70-
// ///<summary>
71-
// ///The child or children of this dash component
72-
// ///</summary>
73-
// static member children(value: string) = Children([ Html.Html.text value ])
74-
// ///<summary>
75-
// ///The child or children of this dash component
76-
// ///</summary>
77-
// static member children(value: float) = Children([ Html.Html.text value ])
78-
// ///<summary>
79-
// ///The child or children of this dash component
80-
// ///</summary>
81-
// static member children(value: System.Guid) = Children([ Html.Html.text value ])
82-
// ///<summary>
83-
// ///The child or children of this dash component
84-
// ///</summary>
85-
// static member children(value: DashComponent) = Children([ value ])
86-
// ///<summary>
87-
// ///The child or children of this dash component
88-
// ///</summary>
89-
// static member children(value: list<DashComponent>) = Children(value)
90-
// ///<summary>
91-
// ///The child or children of this dash component
92-
// ///</summary>
93-
// static member children(value: seq<DashComponent>) = Children(List.ofSeq value)
37+
///<summary>
38+
///A list of children or a property for this dash component
39+
///</summary>
40+
type Attr =
41+
| Prop of Prop
42+
| Children of list<DashComponent>
43+
///<summary>
44+
///pathname in window.location - e.g., "/my/full/pathname"
45+
///</summary>
46+
static member pathname(p: string) = Prop(Pathname p)
47+
///<summary>
48+
///search in window.location - e.g., "?myargument=1"
49+
///</summary>
50+
static member search(p: string) = Prop(Search p)
51+
///<summary>
52+
///hash in window.location - e.g., "#myhash"
53+
///</summary>
54+
static member hash(p: string) = Prop(Hash p)
55+
///<summary>
56+
///href in window.location - e.g., "/my/full/pathname?myargument=1#myhash"
57+
///</summary>
58+
static member href(p: string) = Prop(Href p)
59+
///<summary>
60+
///Refresh the page when the location is updated?
61+
///</summary>
62+
static member refresh(p: bool) = Prop(Refresh p)
63+
///<summary>
64+
///The child or children of this dash component
65+
///</summary>
66+
static member children(value: int) = Children([ Html.Html.text value ])
67+
///<summary>
68+
///The child or children of this dash component
69+
///</summary>
70+
static member children(value: string) = Children([ Html.Html.text value ])
71+
///<summary>
72+
///The child or children of this dash component
73+
///</summary>
74+
static member children(value: float) = Children([ Html.Html.text value ])
75+
///<summary>
76+
///The child or children of this dash component
77+
///</summary>
78+
static member children(value: System.Guid) = Children([ Html.Html.text value ])
79+
///<summary>
80+
///The child or children of this dash component
81+
///</summary>
82+
static member children(value: DashComponent) = Children([ value ])
83+
///<summary>
84+
///The child or children of this dash component
85+
///</summary>
86+
static member children(value: list<DashComponent>) = Children(value)
87+
///<summary>
88+
///The child or children of this dash component
89+
///</summary>
90+
static member children(value: seq<DashComponent>) = Children(List.ofSeq value)
9491

95-
// ///<summary>
96-
// ///Update and track the current window.location object through the window.history state.
97-
// ///Use in conjunction with the &#96;dash_core_components.Link&#96; component to make apps with multiple pages.
98-
// ///</summary>
99-
// type Location() =
100-
// inherit DashComponent()
101-
// static member applyMembers
102-
// (
103-
// id: string,
104-
// children: seq<DashComponent>,
105-
// ?pathname: string,
106-
// ?search: string,
107-
// ?hash: string,
108-
// ?href: string,
109-
// ?refresh: string
110-
// ) =
111-
// (fun (t: Location) ->
112-
// let props = DashComponentProps()
113-
// DynObj.setValue props "id" id
114-
// DynObj.setValue props "children" children
115-
// DynObj.setValueOpt props "pathname" pathname
116-
// DynObj.setValueOpt props "search" search
117-
// DynObj.setValueOpt props "hash" hash
118-
// DynObj.setValueOpt props "href" href
119-
// DynObj.setValueOpt props "refresh" refresh
120-
// DynObj.setValue t "namespace" "dash_core_components"
121-
// DynObj.setValue t "props" props
122-
// DynObj.setValue t "type" "Location"
123-
// t)
92+
///<summary>
93+
///Update and track the current window.location object through the window.history state.
94+
///Use in conjunction with the &#96;dash_core_components.Link&#96; component to make apps with multiple pages.
95+
///</summary>
96+
type Location() =
97+
inherit DashComponent()
98+
static member applyMembers
99+
(
100+
id: string,
101+
children: seq<DashComponent>,
102+
?pathname: string,
103+
?search: string,
104+
?hash: string,
105+
?href: string,
106+
?refresh: string
107+
) =
108+
(fun (t: Location) ->
109+
let props = DashComponentProps()
110+
DynObj.setValue props "id" id
111+
DynObj.setValue props "children" children
112+
DynObj.setValueOpt props "pathname" pathname
113+
DynObj.setValueOpt props "search" search
114+
DynObj.setValueOpt props "hash" hash
115+
DynObj.setValueOpt props "href" href
116+
DynObj.setValueOpt props "refresh" refresh
117+
DynObj.setValue t "namespace" "dash_core_components"
118+
DynObj.setValue t "props" props
119+
DynObj.setValue t "type" "Location"
120+
t)
124121

125-
// static member init
126-
// (
127-
// id: string,
128-
// children: seq<DashComponent>,
129-
// ?pathname: string,
130-
// ?search: string,
131-
// ?hash: string,
132-
// ?href: string,
133-
// ?refresh: string
134-
// ) =
135-
// Location.applyMembers
136-
// (id, children, ?pathname = pathname, ?search = search, ?hash = hash, ?href = href, ?refresh = refresh)
137-
// (Location())
122+
static member init
123+
(
124+
id: string,
125+
children: seq<DashComponent>,
126+
?pathname: string,
127+
?search: string,
128+
?hash: string,
129+
?href: string,
130+
?refresh: string
131+
) =
132+
Location.applyMembers
133+
(id, children, ?pathname = pathname, ?search = search, ?hash = hash, ?href = href, ?refresh = refresh)
134+
(Location())
138135

139-
// ///<summary>
140-
// ///Update and track the current window.location object through the window.history state.
141-
// ///Use in conjunction with the &#96;dash_core_components.Link&#96; component to make apps with multiple pages.
142-
// ///&#10;
143-
// ///Properties:
144-
// ///&#10;
145-
// ///• id (string) - The ID of this component, used to identify dash components
146-
// ///in callbacks. The ID needs to be unique across all of the
147-
// ///components in an app.
148-
// ///&#10;
149-
// ///• pathname (string) - pathname in window.location - e.g., "/my/full/pathname"
150-
// ///&#10;
151-
// ///• search (string) - search in window.location - e.g., "?myargument=1"
152-
// ///&#10;
153-
// ///• hash (string) - hash in window.location - e.g., "#myhash"
154-
// ///&#10;
155-
// ///• href (string) - href in window.location - e.g., "/my/full/pathname?myargument=1#myhash"
156-
// ///&#10;
157-
// ///• refresh (boolean; default true) - Refresh the page when the location is updated?
158-
// ///</summary>
159-
// let location (id: string) (attrs: list<Attr>) =
160-
// let props, children =
161-
// List.fold
162-
// (fun (props, children) (a: Attr) ->
163-
// match a with
164-
// | Prop (prop) -> prop :: props, children
165-
// | Children (child) -> props, child @ children)
166-
// ([], [])
167-
// attrs
136+
///<summary>
137+
///Update and track the current window.location object through the window.history state.
138+
///Use in conjunction with the &#96;dash_core_components.Link&#96; component to make apps with multiple pages.
139+
///&#10;
140+
///Properties:
141+
///&#10;
142+
///• id (string) - The ID of this component, used to identify dash components
143+
///in callbacks. The ID needs to be unique across all of the
144+
///components in an app.
145+
///&#10;
146+
///• pathname (string) - pathname in window.location - e.g., "/my/full/pathname"
147+
///&#10;
148+
///• search (string) - search in window.location - e.g., "?myargument=1"
149+
///&#10;
150+
///• hash (string) - hash in window.location - e.g., "#myhash"
151+
///&#10;
152+
///• href (string) - href in window.location - e.g., "/my/full/pathname?myargument=1#myhash"
153+
///&#10;
154+
///• refresh (boolean; default true) - Refresh the page when the location is updated?
155+
///</summary>
156+
let location (id: string) (attrs: list<Attr>) =
157+
let props, children =
158+
List.fold
159+
(fun (props, children) (a: Attr) ->
160+
match a with
161+
| Prop (prop) -> prop :: props, children
162+
| Children (child) -> props, child @ children)
163+
([], [])
164+
attrs
168165

169-
// let t = Location.init (id, children)
166+
let t = Location.init (id, children)
170167

171-
// let componentProps =
172-
// match t.TryGetTypedValue<DashComponentProps> "props" with
173-
// | Some (p) -> p
174-
// | None -> DashComponentProps()
168+
let componentProps =
169+
match t.TryGetTypedValue<DashComponentProps> "props" with
170+
| Some (p) -> p
171+
| None -> DashComponentProps()
175172

176-
// Seq.iter
177-
// (fun (prop: Prop) ->
178-
// let fieldName, boxedProp = Prop.toDynamicMemberDef prop
179-
// DynObj.setValue componentProps fieldName boxedProp)
180-
// props
173+
Seq.iter
174+
(fun (prop: Prop) ->
175+
let fieldName, boxedProp = Prop.toDynamicMemberDef prop
176+
DynObj.setValue componentProps fieldName boxedProp)
177+
props
181178

182-
// DynObj.setValue t "props" componentProps
183-
// t :> DashComponent
179+
DynObj.setValue t "props" componentProps
180+
t :> DashComponent

0 commit comments

Comments
 (0)