estrattonbailey / operator

1.8kb drop-in "PJAX" solution for fluid, smooth transitions between pages.
90 stars 11 forks source link

Route lifecycle #23

Open bojanvidanovic opened 3 years ago

bojanvidanovic commented 3 years ago

Hi,

I think it would be very useful if the route handler could have an asynchronous lifecycle out of the box.

Greate little lib, by the way, thanks.

bojanvidanovic commented 3 years ago

At the moment the only way seems to use some ugly logical methods, like:

{
  path: '/blog/:post',
  handler () {
    let loaded = false;

    app.on('after', () => {
      if (!loaded) {
         loaded = true;
         Slider.init();
      }
    })
  }
}

But having something like: state.beforeLoad, state.afterLoad would come in very handy for manipulating DOM and destroying events.