Skip to content

Commit

Permalink
Inline motioncomplete listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
thetarnav committed Jan 4, 2024
1 parent ffaf3c0 commit ba9005f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/presence.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
type Accessor,
} from "solid-js"

import {onCompleteExit} from "./primitives.js"
import type {Options} from "./types.js"

export type PresenceContextState = {
Expand Down Expand Up @@ -57,7 +56,7 @@ export const Presence: FlowComponent<{
batch(() => {
setMount(false)
;(mountedStates.get(el)?.getOptions() as Options).exit
? onCompleteExit(el, done)
? el.addEventListener("motioncomplete", done)
: done()
})
},
Expand Down
6 changes: 1 addition & 5 deletions src/primitives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import {Accessor, createEffect, onCleanup, useContext} from "solid-js"
import {PresenceContext, PresenceContextState} from "./presence.jsx"
import {Options} from "./types.js"

export function onCompleteExit(el: Element, fn: VoidFunction): void {
el.addEventListener("motioncomplete", fn)
}

/** @internal */
export function createAndBindMotionState(
el: () => Element,
Expand Down Expand Up @@ -35,7 +31,7 @@ export function createAndBindMotionState(
onCleanup(() => {
if (presence_state && options().exit) {
state.setActive("exit", true)
onCompleteExit(el_ref, unmount)
el_ref.addEventListener("motioncomplete", unmount)
} else unmount()
})
})
Expand Down

0 comments on commit ba9005f

Please sign in to comment.