Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

Commit

Permalink
release(vue): v1.0.0-beta.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sheepbox8646 committed May 8, 2024
1 parent d02cd07 commit fb66152
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 37 deletions.
2 changes: 1 addition & 1 deletion packages/vue/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@newcar/vue",
"type": "module",
"version": "1.0.0-alpha.2",
"version": "1.0.0-beta.0",
"description": "The components and hooks of newcar",
"author": "BugDuck Team",
"license": "Apache-2.0",
Expand Down
12 changes: 0 additions & 12 deletions packages/vue/src/components/CarCanvas.vue

This file was deleted.

44 changes: 25 additions & 19 deletions packages/vue/src/hooks/useCarApp.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
// import type { App, Scene } from '@newcar/core'
// import { type Ref, onMounted, ref } from './hooks'
import type { App, CarEngine, Scene } from '@newcar/core'
import { type Ref, inject, onMounted, ref, watchEffect } from 'vue'

// export function useCarApp(scene: Scene) {
// const canvas: Ref<HTMLCanvasElement> = ref(null)
// let app: App
// onMounted(() => {
// if (typeof $carengine !== 'undefined') {
// app = $carengine.createApp(canvas.value)
// app.checkout(scene)
// }
// else {
// console.warn('[Newcar Warn] Newcar Plugin For Vue is not installed, please refer to')
// }
// })
// return {
// canvas,
// app,
// }
// }
export function useCarApp(scene: Scene) {
const canvas: Ref<HTMLCanvasElement> = ref(null)
let app: App
const engine = inject<CarEngine>('carengine')

const getApp = () => {
if (!app && engine) {
app = engine.createApp(canvas.value)
app.checkout(scene)
}
return app
}

watchEffect(() => {
if (engine)
getApp()
})

return {
canvas,
app,
}
}
4 changes: 1 addition & 3 deletions packages/vue/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
// import CarCanvas from './components/CarCanvas.vue'
// export * from './hooks/useCarApp'
export * from './hooks/useCarApp'
export { newcar } from './plugin'
// export { CarCanvas }
6 changes: 4 additions & 2 deletions packages/vue/src/plugin/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { CarEngine } from '@newcar/core'
import type { App } from 'vue'

export function newcar(wasm: string) {
async function install(app: { config: { globalProperties: { $carengine: CarEngine } } }, _options: any) {
app.config.globalProperties.$carengine = await new CarEngine().init(wasm)
async function install(app: App, _options: any) {
const engine = await new CarEngine().init(wasm)
app.provide<CarEngine>('carengine', engine)
}

return { install }
Expand Down

0 comments on commit fb66152

Please sign in to comment.