Skip to content

Commit

Permalink
Solutions for #31 and #39
Browse files Browse the repository at this point in the history
  • Loading branch information
alfonsogarciacaro committed May 27, 2022
1 parent 4560f60 commit 6317d3a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/Lit/Hook.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module internal HookUtil =
let [<Literal>] HMR_CLASS_EXPR =
"""class extends $0 {
constructor() { super($3...) }
get name() { return $2; }
get __name() { return $2; }
get renderFn() { return $1.value; }
set renderFn(v) {
$1.value = v;
Expand Down Expand Up @@ -332,7 +332,7 @@ type HookDirective() =
#endif

abstract renderFn: JS.Function with get, set
abstract name: string
abstract __name: string

member this.requestUpdate() =
this.setValue(_hooks.render())
Expand Down Expand Up @@ -368,7 +368,7 @@ type HookDirective() =
token.Subscribe(fun info ->
_hooks.remove_css()
let updatedModule = info.NewModule
this.renderFn <- updatedModule?(this.name)?renderFn
this.renderFn <- updatedModule?(this.__name)?renderFn
) |> Some
#endif

Expand Down
10 changes: 7 additions & 3 deletions src/Lit/LitElement.fs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ type LitHookElement<'Props>(initProps: obj -> unit) =
do initProps(jsThis)

abstract renderFn: JS.Function with get, set
abstract name: string
abstract __name: string

member _.render() =
_hooks.render()
Expand All @@ -211,7 +211,7 @@ type LitHookElement<'Props>(initProps: obj -> unit) =
token.Subscribe(fun info ->
_hooks.remove_css()
let updatedModule = info.NewModule
let updatedExport = updatedModule?(this.name)
let updatedExport = updatedModule?(this.__name)
this.renderFn <- updatedExport?renderFn
updateStyleSheets info.Data this (updatedExport?styles)
)
Expand Down Expand Up @@ -244,7 +244,7 @@ type LitElementAttribute(name: string) =
failInit()

config.InitPromise
|> Promise.iter (fun _ ->
|> Promise.map (fun _ ->
let config = config :> LitConfig<obj>

let styles =
Expand Down Expand Up @@ -316,6 +316,10 @@ type LitElementAttribute(name: string) =
styles |> Option.iter (fun styles -> dummyFn?styles <- styles)
#endif
)
|> Promise.catchEnd (fun er ->
console.error(er)
)

box dummyFn :?> _

[<AutoOpen>]
Expand Down

0 comments on commit 6317d3a

Please sign in to comment.