Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add some hooks of presentation slides lifetime #1550

Open
Sdju opened this issue Apr 18, 2024 · 0 comments
Open

Feat: Add some hooks of presentation slides lifetime #1550

Sdju opened this issue Apr 18, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@Sdju
Copy link
Contributor

Sdju commented Apr 18, 2024

Sometimes I need to reset a state for a slide after entering. And for now I use a composable onSlideEnter

function onSlideEnter(cb: () => void) {
  const instance = getCurrentInstance();
  const { currentSlideNo } = useNav();

  watch(currentSlideNo, (slideNo) => {
    if (slideNo === instance.setupState.$page) {
      cb()
    }
  }), {  immediate: true };
}

And similar for leaving:

function onSlideLeave(cb: () => void) {
  const instance = getCurrentInstance();
  const { currentSlideNo } = useNav();

  watch(() => currentSlideNo.value === instance.setupState.$page, (_, wasActive => {
    if (wasActive)
      cb()
  });
}

Computed to check: is a slide active?

const instance = getCurrentInstance();
const { currentSlideNo } = useNav();

const isSlideActive = computed(() => currentSlideNo.value === instance.setupState.$page)

Maybe it should be a part of useNav/useNavState or... "useCurrentSlide"

The code above isn't well tested. For now it just works for my cases. I think they can be usefull for others too. But maybe I just haven't found a better way to do it with the current API.

@Sdju Sdju added the enhancement New feature or request label Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant