Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement attach view #1057

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/Fabulous/Component.fs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,24 @@
{ Key = key
Name = "Component"
TargetType = typeof<Component>
AttachView = fun _ -> failwith "Component widget cannot be attached"
AttachView =
fun (widget, treeContext, _parentNode, view) ->
match widget.ScalarAttributes with
| ValueNone -> failwith "Component widget must have a body and a context"
| ValueSome attrs ->
let body =
match Array.tryFind (fun (attr: ScalarAttribute) -> attr.Key = Component.Body.Key) attrs with

Check failure on line 313 in src/Fabulous/Component.fs

View workflow job for this annotation

GitHub Actions / pull_request

The type 'Component' does not define the field, constructor or member 'Body'.

Check failure on line 313 in src/Fabulous/Component.fs

View workflow job for this annotation

GitHub Actions / pull_request

The type 'Component' does not define the field, constructor or member 'Body'.

Check failure on line 313 in src/Fabulous/Component.fs

View workflow job for this annotation

GitHub Actions / pull_request

The type 'Component' does not define the field, constructor or member 'Body'.

Check failure on line 313 in src/Fabulous/Component.fs

View workflow job for this annotation

GitHub Actions / pull_request

The type 'Component' does not define the field, constructor or member 'Body'.
| Some attr -> attr.Value :?> ComponentBody
| None -> failwith "Component widget must have a body"

let context =
match Array.tryFind (fun (attr: ScalarAttribute) -> attr.Key = Component.Context.Key) attrs with

Check failure on line 318 in src/Fabulous/Component.fs

View workflow job for this annotation

GitHub Actions / pull_request

The type 'Component' does not define the field, constructor or member 'Context'.

Check failure on line 318 in src/Fabulous/Component.fs

View workflow job for this annotation

GitHub Actions / pull_request

The type 'Component' does not define the field, constructor or member 'Context'.

Check failure on line 318 in src/Fabulous/Component.fs

View workflow job for this annotation

GitHub Actions / pull_request

The type 'Component' does not define the field, constructor or member 'Context'.
| Some attr -> attr.Value :?> ComponentContext
| None -> ComponentContext()

let comp = new Component(treeContext, body, context)
let node = comp.AttachView(view)

Check failure on line 323 in src/Fabulous/Component.fs

View workflow job for this annotation

GitHub Actions / pull_request

The type 'Component' does not define the field, constructor or member 'AttachView'.

Check failure on line 323 in src/Fabulous/Component.fs

View workflow job for this annotation

GitHub Actions / pull_request

The type 'Component' does not define the field, constructor or member 'AttachView'.

Check failure on line 323 in src/Fabulous/Component.fs

View workflow job for this annotation

GitHub Actions / pull_request

The type 'Component' does not define the field, constructor or member 'AttachView'.
node
CreateView =
fun (widget, treeContext, _) ->
match widget.ScalarAttributes with
Expand Down
15 changes: 14 additions & 1 deletion src/Fabulous/Memo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@ module Memo =
// to pass it to reconciler later on
node.MemoizedWidget <- Some memoizedWidget
struct (node, view)
AttachView = fun (_widget, _context, _parentNode, _view) -> failwith "Memo widget cannot be attached" }
AttachView =
fun (widget, context, parentNode, view) ->
let memoData = getMemoData widget

let memoizedWidget = memoData.CreateWidget memoData.KeyData

let memoizedDef = WidgetDefinitionStore.get memoizedWidget.Key

let node = memoizedDef.AttachView(memoizedWidget, context, parentNode, view)

// store widget that was used to produce this node
// to pass it to reconciler later on
node.MemoizedWidget <- Some memoizedWidget
node }

WidgetDefinitionStore.set MemoWidgetKey widgetDefinition