From 41c7561bf9fb4403edbc33ac3aa5422fe4bff969 Mon Sep 17 00:00:00 2001 From: pimlie Date: Sat, 25 Apr 2020 12:32:57 +0200 Subject: [PATCH] initial work on v3 --- examples/next/index.js | 61 +++++++++++++++++++++++++++++++++- examples/package.json | 2 +- examples/vue-router/about.vue | 2 +- examples/vue-router/app.js | 54 +++++++++++++++++++++++++++--- examples/vue-router/index.html | 30 ++++++++++------- 5 files changed, 129 insertions(+), 20 deletions(-) diff --git a/examples/next/index.js b/examples/next/index.js index 6b59b25..77f3857 100644 --- a/examples/next/index.js +++ b/examples/next/index.js @@ -1,4 +1,63 @@ +import { markRaw, reactive, computed, onMounted } from 'vue' -export default { +const apps = {} +export function createMeta () { + const id = Symbol() + + const Meta = { + id, + + install(app) { + let watchersAdded = false + + app.mixin({ + created() { + if (this === this.$root) { + + watchersAdded = true + } + + if (!this.metaData) { + return + } + + let depth = 0 + let parent = this + while (parent) { + parent = parent.$parent + depth++ + + if (parent === this.$root) { + break + } + } + + const __meta = markRaw({ + depth + }) + console.log('CREATED', this, this.metaData, depth) + } + }) + + app.config.globalProperties.$meta = this + } + } + + apps[id] = Meta + + return Meta +} + +export function useMeta () { + onMounted(vmMounted) + + const metaData = reactive([]) + console.log(this) + + return metaData +} + +function vmMounted() { + console.log('MOUNTED', this, arguments) } diff --git a/examples/package.json b/examples/package.json index 4cf5989..156d8ac 100644 --- a/examples/package.json +++ b/examples/package.json @@ -23,7 +23,7 @@ "@babel/core": "^7.9.0", "@babel/node": "^7.8.7", "@babel/plugin-syntax-dynamic-import": "^7.8.3", - "@babel/preset-env": "^7.9.0", + "@babel/preset-env": "^7.9.5", "@vue/compiler-sfc": "^3.0.0-alpha.10", "@vue/server-renderer": "^3.0.0-alpha.10", "babel-loader": "^8.1.0", diff --git a/examples/vue-router/about.vue b/examples/vue-router/about.vue index fe2c414..b4f0fc2 100644 --- a/examples/vue-router/about.vue +++ b/examples/vue-router/about.vue @@ -22,7 +22,7 @@ export default { onMounted(() => console.log(route)) - return { metaUpdated, page: route.value.name } + return { metaUpdated, page: route.name } } } diff --git a/examples/vue-router/app.js b/examples/vue-router/app.js index 58c490d..a9cc7e3 100644 --- a/examples/vue-router/app.js +++ b/examples/vue-router/app.js @@ -1,21 +1,30 @@ -import { createApp, defineComponent, reactive, toRefs, h } from 'vue' +import { createApp, defineComponent, reactive, toRefs, h, onMounted } from 'vue' import VueMeta from 'vue-meta' import { createRouter, createWebHistory } from 'vue-router' import About from './about.vue' +import { createMeta, useMeta } from '../next' /*Vue.use(VueMeta, { refreshOnceOnNavigation: true })*/ +const meta = createMeta({ + +}) + let metaUpdated = 'no' const ChildComponent = defineComponent({ name: 'child-component', props: { page: String }, - template: `
-

You're looking at the {{ page }} page

-

Has metaInfo been updated due to navigation? {{ metaUpdated }}

+ template: ` + + Another Title + +
+

You're looking at the {{ page }} page

+

Has metaInfo been updated due to navigation? {{ metaUpdated }}

`, metaInfo () { return { @@ -28,13 +37,26 @@ const ChildComponent = defineComponent({ } } }, + created () { + console.log(this) + }, setup () { + const metaData = useMeta({ + }) + const state = reactive({ date: null, metaUpdated }) + + onMounted(function vmMounted() { + console.log('MOUNTED', this, arguments) + }) + + return { + metaData, ...toRefs(state) } }, @@ -68,8 +90,29 @@ const router = createRouter({ ] }) +const Metadata = { + template: ` + + + + + + + + ` +} + const App = { template: ` + + My Title + + + + +

vue-router

Home @@ -83,8 +126,9 @@ const App = { } const app = createApp(App) +app.component('metainfo', Metadata) app.use(router) - +app.use(meta) /* const { set, remove } = app.$meta().addApp('custom') diff --git a/examples/vue-router/index.html b/examples/vue-router/index.html index 7ae5a53..7d68002 100644 --- a/examples/vue-router/index.html +++ b/examples/vue-router/index.html @@ -1,13 +1,19 @@ - -← Examples index -
- - + + + + + + + ← Examples index +
+ + +