Skip to content

Commit

Permalink
Merge pull request #213 from PrefectHQ/pixi-app-refactor
Browse files Browse the repository at this point in the history
Revert to using an in process pixi application
  • Loading branch information
pleek91 authored Sep 28, 2023
2 parents d1f2714 + 69b0b38 commit 1928614
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 114 deletions.
213 changes: 128 additions & 85 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"vue-router": "^4.0.12"
},
"dependencies": {
"@pixi/webworker": "7.3.1",
"date-fns": "2.30.0"
"date-fns": "2.30.0",
"pixi.js": "^7.3.1"
}
}
17 changes: 6 additions & 11 deletions src/components/RunGraph.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue'
import { RunGraphConfig } from '@/models/RunGraph'
import { createApplication } from '@/objects/application'
import { WorkerMessage, worker } from '@/workers/runGraph'
defineProps<{
Expand All @@ -13,10 +14,12 @@
const canvas = ref<HTMLCanvasElement>()
worker.onmessage = onMessage
function onMessage({ data }: MessageEvent<WorkerMessage>): void {
switch (data.type) {
case 'hello-world':
console.log(data.type)
case 'pong':
console.log('pong')
return
default:
const exhaustive: never = data.type
Expand All @@ -31,15 +34,7 @@
const view = canvas.value.transferControlToOffscreen()
worker.postMessage({
type: 'application',
options: {
view,
background: '#1099bb',
},
}, [view])
worker.onmessage = onMessage
createApplication(view)
if (process.env.NODE_ENV === 'development') {
(globalThis as any).__PIXI_STAGE__ = canvas.value
Expand Down
10 changes: 10 additions & 0 deletions src/objects/application.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Application } from 'pixi.js'

export let application: Application

export function createApplication(view: OffscreenCanvas): void {
application = new Application({
view,
background: '#1099bb',
})
}
6 changes: 2 additions & 4 deletions src/workers/runGraph.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { IApplicationOptions } from '@pixi/webworker'
// eslint-disable-next-line import/default
import RunGraphWorker from '@/workers/runGraph.worker?worker'

export type ClientMessage = ClientApplicationInitializationMessage
export type WorkerMessage = WorkerHelloWorldMessage

export type ClientApplicationInitializationMessage = {
type: 'application',
options: Partial<IApplicationOptions>,
type: 'ping',
}

export type WorkerHelloWorldMessage = {
type: 'hello-world',
type: 'pong',
}

export interface IRunGraphWorker extends Omit<Worker, 'postMessage'> {
Expand Down
Loading

0 comments on commit 1928614

Please sign in to comment.