Skip to content

Commit

Permalink
fix(tryMountTicker): tryMountTicker cannot be used outside of setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr.Mao committed May 9, 2023
1 parent 5798bba commit 1102e8b
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/composables/tryMountTicker.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
import type { MaybeRef } from '@vueuse/core'
import { tryOnBeforeUnmount, tryOnMounted } from '@vueuse/core'
import type { TickerCallback } from 'pixi.js'
import type { StageInst } from '../../dist'
import { useApplication } from './useApplication'

export function tryMountTicker(fn: TickerCallback<any>) {
const app = useApplication()
export function tryMountTicker(stageRef?: MaybeRef<StageInst>, fn?: TickerCallback<any>): () => void
export function tryMountTicker(fn?: TickerCallback<any>): () => void
export function tryMountTicker(...args: any[]): any {
let stageRef: MaybeRef<StageInst> | undefined
let fn: TickerCallback<any> = () => {}
if (typeof args[0] === 'function') {
fn = args[0]
}
else {
stageRef = args[0]
fn = args[1]
}

const app = useApplication(stageRef)

function insert() {
app.value?.ticker.add(fn)
Expand Down

0 comments on commit 1102e8b

Please sign in to comment.