Skip to content

Commit

Permalink
Merge pull request #68 from /issues/65
Browse files Browse the repository at this point in the history
fix: application extends parent injection (#65)
  • Loading branch information
hairyf authored Oct 28, 2023
2 parents 91d512f + f330dc5 commit b4e9f1b
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vue3-pixi-monorepo",
"type": "module",
"version": "0.8.3",
"version": "0.8.4",
"private": true,
"packageManager": "[email protected]",
"description": "Vue createRenderer for PixiJS",
Expand Down
2 changes: 1 addition & 1 deletion packages/vue3-pixi-projection/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vue3-pixi-projection",
"type": "module",
"version": "0.8.3",
"version": "0.8.4",
"description": "Vue createRenderer for PixiJS",
"license": "MIT",
"homepage": "https://github.com/hairyf/vue3-pixi#readme",
Expand Down
2 changes: 1 addition & 1 deletion packages/vue3-pixi-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vue3-pixi-ui",
"type": "module",
"version": "0.8.3",
"version": "0.8.4",
"description": "Vue createRenderer for PixiJS",
"license": "MIT",
"homepage": "https://github.com/hairyf/vue3-pixi#readme",
Expand Down
2 changes: 1 addition & 1 deletion packages/vue3-pixi/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vue3-pixi",
"type": "module",
"version": "0.8.3",
"version": "0.8.4",
"description": "Vue createRenderer for PixiJS",
"license": "MIT",
"homepage": "https://github.com/hairyf/vue3-pixi#readme",
Expand Down
8 changes: 7 additions & 1 deletion packages/vue3-pixi/src/components/application/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/* eslint-disable vue/one-component-per-file */
import { defineComponent, h, markRaw, onMounted, onUnmounted, ref, renderSlot, warn, watch } from 'vue-demi'
import { defineComponent, getCurrentInstance, h, markRaw, onMounted, onUnmounted, ref, renderSlot, warn, watch } from 'vue-demi'
import { throttle } from '@antfu/utils'
import { Application as _Application } from 'pixi.js'
import type { ColorSource, Container } from 'pixi.js'
import type { App, PropType } from 'vue-demi'
import { createApp } from '../../renderer'
import { appInjectKey } from '../../composables'
import { inheritParent } from '../../utils'

export interface ApplicationInst {
canvas: HTMLCanvasElement
Expand Down Expand Up @@ -36,8 +37,10 @@ export const Application = defineComponent({
resizeTo: Object as PropType<HTMLElement | Window | undefined>,
},
setup(props, { slots, expose }) {
const { appContext } = getCurrentInstance()!
const canvas = ref<HTMLCanvasElement>()
const pixiApp = ref()

let app: App<Container> | undefined

function mount() {
Expand All @@ -62,6 +65,9 @@ export const Application = defineComponent({
app = createApp({
render: () => renderSlot(slots, 'default'),
})

inheritParent(app, appContext)

app.provide(appInjectKey, pixiApp)
app.mount(pixiApp.value.stage)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vue3-pixi/src/components/external/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type { App, PropType } from 'vue-demi'
import { createApp, defineComponent, getCurrentInstance, h, inject, onMounted, onUnmounted, ref } from 'vue-demi'
import { appInjectKey } from '../../composables'
import { inheritParent } from './utils'
import { inheritParent } from '../../utils'

export const External = defineComponent({
props: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { App, AppContext } from 'vue-demi'

export function inheritParent(app: App<Element>, appContext?: AppContext) {
export function inheritParent(app: App<any>, appContext?: AppContext) {
const parent = appContext?.app
if (parent) {
app.config.globalProperties = parent.config.globalProperties
Expand Down

1 comment on commit b4e9f1b

@vercel
Copy link

@vercel vercel bot commented on b4e9f1b Oct 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

vue3-pixi – ./

vue3-pixi-git-main-tuimao.vercel.app
vue3-pixi-tuimao.vercel.app
vue3-pixi.vercel.app

Please sign in to comment.