Skip to content

Commit

Permalink
fixed: Initial route handling
Browse files Browse the repository at this point in the history
  • Loading branch information
GianlucaGuarini committed Oct 27, 2023
1 parent 352a3c9 commit 238ac34
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/components/route-hoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,28 @@ export const routeHoc = ({ slots, attributes }) => {
this.afterPlaceholder,
this.beforePlaceholder.nextSibling,
)

if (state.route) this.mountSlot()
},
update(context) {
this.context = context
if (this.state.route) this.slot.update({}, context)
},
mountSlot(context) {
mountSlot() {
const { route } = this.state
this.beforePlaceholder.parentNode.insertBefore(
this.el,
this.beforePlaceholder.nextSibling,
)
this.callLifecycleProperty('onBeforeMount', route)
this.slot.mount(
this.el,
{
slots,
},
context,
this.context,
)
this.callLifecycleProperty('onMounted', route)
},
clearDOM(includeBoundaries) {
clearDOMBetweenNodes(
Expand All @@ -100,22 +105,23 @@ export const routeHoc = ({ slots, attributes }) => {
this.stream.end()
},
onBeforeRoute(path) {
if (this.state.route && !match(path, this.state.pathToRegexp)) {
const { route } = this.state

if (route && !match(path, this.state.pathToRegexp)) {
this.callLifecycleProperty('onBeforeUnmount', route)
this.slot.unmount({}, this.context, true)
this.clearDOM(false)
this.state.route = null
this.callLifecycleProperty('onUnmounted', route)
this.callLifecycleProperty('onUnmounted', this.state.route)
}
},
onRoute(route) {
this.callLifecycleProperty('onBeforeMount', route)
this.state.route = route
this.mountSlot(this.context)
this.callLifecycleProperty('onMounted', route)
this.mountSlot()
},
callLifecycleProperty(method, ...params) {
const attr = getAttribute(attributes, method)

if (attr) attr(...params)
},
}
Expand Down

0 comments on commit 238ac34

Please sign in to comment.