Skip to content

Commit

Permalink
[#61] Add attr.key
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarmil committed Aug 25, 2019
1 parent d33eef3 commit c61520b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ bin/
obj/
.vs/
*.user
.ionide/
paket-files/
packages/
.fake/
Expand Down
3 changes: 3 additions & 0 deletions src/Bolero/Html.fs
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,9 @@ module attr =
let bindRef (refBinder: ElementReferenceBinder) =
ref refBinder.SetRef

let key (k: obj) =
Attr.Key k

// BEGIN ATTRS
/// Create an HTML `accept` attribute.
let accept (v: obj) : Attr = "accept" => v
Expand Down
1 change: 1 addition & 0 deletions src/Bolero/Node.fs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ open Microsoft.AspNetCore.Components
type Attr =
| Attr of string * obj
| Attrs of list<Attr>
| Key of obj
#if !IS_DESIGNTIME
| ExplicitAttr of (RenderTree.RenderTreeBuilder -> int -> obj -> unit)
| Ref of Action<ElementReference>
Expand Down
25 changes: 15 additions & 10 deletions src/Bolero/Render.fs
Original file line number Diff line number Diff line change
Expand Up @@ -155,28 +155,33 @@ let rec renderNode (currentComp: obj) (builder: RenderTreeBuilder) (matchCache:
/// Render a list of attributes into `builder` at `sequence` number.
and renderAttrs currentComp builder sequence attrs =
// AddAttribute calls want to be just after the OpenElement/OpenComponent call,
// so we make sure that AddElementReferenceCapture is called last.
// so we make sure that AddElementReferenceCapture and SetKey are called last.
let rec run attrs =
((sequence, None), attrs)
||> List.fold (fun (sequence, ref) attr ->
((sequence, None, None), attrs)
||> List.fold (fun (sequence, ref, key) attr ->
match attr with
| Attr (name, value) ->
builder.AddAttribute(sequence, name, value)
(sequence + 1, ref)
(sequence + 1, ref, key)
| Attrs attrs ->
run attrs
| ExplicitAttr setAttr ->
setAttr builder sequence currentComp
//builder.AddAttribute(sequence, name, mkCallback currentComp)
(sequence + 1, ref)
(sequence + 1, ref, key)
| Ref ref ->
(sequence, Some ref)
(sequence, Some ref, key)
| Key key ->
(sequence, ref, Some key)
)
match run attrs with
| sequence, Some r ->
let sequence, ref, key = run attrs
match key with
| Some k -> builder.SetKey(k)
| None -> ()
match ref with
| Some r ->
builder.AddElementReferenceCapture(sequence, r)
sequence + 1
| sequence, None ->
| None ->
sequence

let RenderNode currentComp builder (matchCache: Dictionary<Type, _>) node =
Expand Down

0 comments on commit c61520b

Please sign in to comment.