deptyped / vue-telegram

Telegram integration for Vue
https://vue-tg.pages.dev
MIT License
118 stars 6 forks source link

Add ability to manage event subscriptions manually #22

Closed hopleus closed 3 months ago

deptyped commented 3 months ago

What is your use case for this?

hopleus commented 3 months ago

What is your use case for this?

Hi. In the application, I use both a router and a BottomSheet. If everything is fine in the case of using the router, because onUnmount is launched when the page address is changed, then in the case of the BottomSheet I ran into the problem of superimposing click events on the MainButton (one MainButton for the page, the other for the BottomSheet).

P.S. BottomSheet I use this - https://github.com/Jannchie/vue-ios-sheet P.P.S I want to be able to control the MainButton click events myself :)

deptyped commented 3 months ago

Thank you. How about this API? Does it meet your needs?

import { useWebApp } from "vue-tg"

const { onEvent } = useWebApp()

const { unsubscribe } = onEvent(
  "mainButtonClicked",
  () => {
    /* main button handler */
  },
  {
    manual: true, // 1. Add option to disable auto-unsubscribe
  },
)

// 2. Manually unsubscribe later
unsubscribe()
hopleus commented 3 months ago

Thank you. How about this API? Does it meet your needs?

import { useWebApp } from "vue-tg"

const { onEvent } = useWebApp()

const { unsubscribe } = onEvent(
  "mainButtonClicked",
  () => {
    /* main button handler */
  },
  {
    manual: true, // 1. Add option to disable auto-unsubscribe
  },
)

// 2. Manually unsubscribe later
unsubscribe()

I think so