Skip to content

Commit

Permalink
Merge pull request #766 from TimLariviere/fix-attached-properties
Browse files Browse the repository at this point in the history
Fix attached properties
  • Loading branch information
TimLariviere authored Jun 26, 2020
2 parents 5ff9ebb + 2542112 commit 169b474
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ module CodeGenerator =
// Attached properties updaters
if data.PropertiesWithAttachedProperties.Length > 0 then
for p in data.PropertiesWithAttachedProperties do
w.printfn " let update%sAttachedProperties overrideFunc (prevChildOpt: ViewElement voption) (newChild: ViewElement) targetChild =" p.UniqueName
let targetChildType = p.CollectionDataElementType |> Option.defaultValue "obj"
w.printfn " let update%sAttachedProperties overrideFunc (prevChildOpt: ViewElement voption) (newChild: ViewElement) (targetChild: %s) =" p.UniqueName targetChildType
for ap in p.AttachedProperties do
let hasApply = not (System.String.IsNullOrWhiteSpace(ap.ConvertModelToValue)) || not (System.String.IsNullOrWhiteSpace(ap.UpdateCode))
let attributeKey = getAttributeKey ap.CustomAttributeKey ap.UniqueName
Expand All @@ -177,8 +178,8 @@ module CodeGenerator =
else
w.printfn " match prev%sOpt, curr%sOpt with" ap.UniqueName ap.UniqueName
w.printfn " | ValueSome prevChildValue, ValueSome currChildValue when prevChildValue = currChildValue -> ()"
w.printfn " | _, ValueSome currChildValue -> %s.Set%s(targetChild, %s currChildValue)" data.FullName ap.Name ap.ConvertModelToValue
w.printfn " | ValueSome _, ValueNone -> %s.Set%s(targetChild, %s)" data.FullName ap.Name ap.DefaultValue
w.printfn " | _, ValueSome currChildValue -> targetChild.SetValue(%s.%sProperty, %s currChildValue)" data.FullName ap.Name ap.ConvertModelToValue
w.printfn " | ValueSome _, ValueNone -> targetChild.ClearValue(%s.%sProperty)" data.FullName ap.Name
w.printfn " | _ -> ()"

w.printfn " overrideFunc prevChildOpt newChild targetChild"
Expand Down
1 change: 1 addition & 0 deletions Fabulous.CodeGen/src/Fabulous.CodeGen/Generator/Models.fs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ module Models =
type UpdatePropertyWithAttachedProperties =
{ UniqueName: string
CustomAttributeKey: string option
CollectionDataElementType: string option
AttachedProperties: UpdateAttachedProperty array }

type UpdateData =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ module Preparer =
|> Array.map (fun p ->
{ UniqueName = p.UniqueName
CustomAttributeKey = p.CustomAttributeKey
CollectionDataElementType = p.CollectionData |> Option.map (fun c -> c.ElementType)
AttachedProperties =
p.CollectionData
|> Option.map (fun cd ->
Expand Down

0 comments on commit 169b474

Please sign in to comment.