Skip to content

Commit

Permalink
♻️ Rename hook
Browse files Browse the repository at this point in the history
  • Loading branch information
ftes committed Sep 4, 2022
1 parent 646c126 commit 821d0f1
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 14 deletions.
4 changes: 2 additions & 2 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import "phoenix_html"
import {Socket} from "phoenix"
import {LiveSocket} from "phoenix_live_view"
import topbar from "../vendor/topbar"
import StoreView from "./hooks/StoreView"
import PushHookEvent from "./hooks/PushHookEvent"
import XReactCombobox from "./react/ComboboxWebcomponent"

customElements.define('x-react-combobox', XReactCombobox)
Expand All @@ -33,7 +33,7 @@ let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("
let liveSocket = new LiveSocket("/live", Socket, {
params: {_csrf_token: csrfToken},
hooks: {
StoreView,
PushHookEvent,
},
})

Expand Down
7 changes: 7 additions & 0 deletions assets/js/hooks/PushHookEvent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const PushEventHook = {
mounted() {
this.el.__pushHookEvent = this.__view.pushHookEvent?.bind(this.__view)
}
}

export default PushEventHook;
7 changes: 0 additions & 7 deletions assets/js/hooks/StoreView.js

This file was deleted.

5 changes: 1 addition & 4 deletions assets/js/react/ComboboxWebcomponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import Combobox from "./Combobox"
export default class ComboboxWebcomponent extends HTMLElement {
connectedCallback() {
const mountPoint = document.createElement('div')
// https://github.com/tailwindlabs/headlessui/issues/835
// Shadow DOM not supported (yet) -> lost click events
// this.attachShadow({ mode: 'closed' })
this.appendChild(mountPoint)
this.__reactRoot = ReactDOM.createRoot(mountPoint)
this.render()
Expand All @@ -24,7 +21,7 @@ export default class ComboboxWebcomponent extends HTMLElement {
const onSelect = ({ value }) => {
const target = this.attributes["phx-target"]?.value
function onReply() {}
this.__view.pushHookEvent(target, "select", { value }, onReply)
this.__pushHookEvent(target, "select", { value }, onReply)
}

this.__reactRoot.render(
Expand Down
2 changes: 1 addition & 1 deletion lib/phoenix_headlessui_web/live/home.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defmodule PhoenixHeadlessuiWeb.HomeLive do
@impl true
def render(assigns) do
~H"""
<x-react-combobox phx-hook="StoreView" phx-update="ignore" id="react-combobox" options={Jason.encode!(@options)} value={@selected} />
<x-react-combobox phx-hook="PushHookEvent" phx-update="ignore" id="react-combobox" options={Jason.encode!(@options)} value={@selected} />
"""
end

Expand Down

0 comments on commit 821d0f1

Please sign in to comment.