From: Eduardo San Martin Morote Date: Thu, 15 Jul 2021 10:46:03 +0000 (+0200) Subject: chore: more playground testing X-Git-Tag: v2.0.0-rc.0~73 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7285ecb3904b65226204e7f66b7e74b490c47562;p=thirdparty%2Fvuejs%2Fpinia.git chore: more playground testing --- diff --git a/index.html b/index.html index b4cd94ab..5d58b5e6 100644 --- a/index.html +++ b/index.html @@ -4,9 +4,16 @@ 🍍 Pinia playground + + +
+ diff --git a/package.json b/package.json index 1f78d3ab..e9b0e799 100644 --- a/package.json +++ b/package.json @@ -69,6 +69,7 @@ "@rollup/plugin-replace": "^3.0.0", "@sucrase/jest-plugin": "^2.1.0", "@types/jest": "^26.0.24", + "@types/lodash.kebabcase": "^4.1.6", "@types/node": "^16.0.1", "@vue/server-renderer": "^3.1.5", "@vue/test-utils": "^2.0.0-rc.10", @@ -81,6 +82,7 @@ "jest": "^26.6.3", "jest-mock-warn": "^1.1.0", "lint-staged": "^11.0.1", + "lodash.kebabcase": "^4.1.1", "pascalcase": "^1.0.0", "prettier": "^2.3.2", "rimraf": "^3.0.2", @@ -91,6 +93,7 @@ "vite": "^2.4.1", "vitepress": "^0.15.6", "vue": "^3.1.5", + "vue-router": "^4.0.10", "yorkie": "^2.0.0" }, "dependencies": { diff --git a/playground/src/App.vue b/playground/src/App.vue index 07db57d7..6af39d74 100644 --- a/playground/src/App.vue +++ b/playground/src/App.vue @@ -1,27 +1,34 @@ diff --git a/playground/src/components/TestCounterStore.vue b/playground/src/components/TestCounterStore.vue deleted file mode 100644 index d0cfa65e..00000000 --- a/playground/src/components/TestCounterStore.vue +++ /dev/null @@ -1,26 +0,0 @@ - - - diff --git a/playground/src/main.ts b/playground/src/main.ts index bfb1990d..914ca520 100644 --- a/playground/src/main.ts +++ b/playground/src/main.ts @@ -1,6 +1,7 @@ import { createApp } from 'vue' import App from './App.vue' import { createPinia } from '../../src' +import { router } from './router' const pinia = createPinia() @@ -49,4 +50,4 @@ if (import.meta.hot) { // TODO: HMR for plugins -createApp(App).use(pinia).mount('#app') +createApp(App).use(router).use(pinia).mount('#app') diff --git a/playground/src/router.ts b/playground/src/router.ts new file mode 100644 index 00000000..8fdc6ee0 --- /dev/null +++ b/playground/src/router.ts @@ -0,0 +1,23 @@ +import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router' +import kebabcase from 'lodash.kebabcase' + +const viewModules = import.meta.glob('./views/*.vue') + +const nameFromPath = (path: string) => path.replace(/^.*\/(\w+)\.vue$/, '$1') + +const pages: RouteRecordRaw[] = Object.keys(viewModules).map((path) => { + const name = nameFromPath(path) + return { + name, + path: name === '404' ? '/:patchMatch(.*)*' : '/' + kebabcase(name), + component: viewModules[path], + meta: { + hide: name === '404', + }, + } +}) + +export const router = createRouter({ + history: createWebHistory(), + routes: [...pages], +}) diff --git a/playground/src/stores/counter.ts b/playground/src/stores/counter.ts index 4941ba03..8c7d9bc3 100644 --- a/playground/src/stores/counter.ts +++ b/playground/src/stores/counter.ts @@ -6,7 +6,7 @@ export const useCounter = defineStore({ id: 'counter', state: () => ({ - n: 8, + n: 0, incrementedTimes: 0, decrementedTimes: 0, numbers: [] as number[], @@ -76,19 +76,19 @@ if (import.meta.hot) { import.meta.hot.data.pinia || oldUseStore._pinia if (!pinia) { - console.warn(`Missing the pinia instance for "${oldUseStore.$id}".`) - return import.meta.hot.invalidate() + // this store is still not used + return } // preserve the pinia instance across loads import.meta.hot.data.pinia = pinia - console.log('got data', newStore) + // console.log('got data', newStore) for (const exportName in newStore) { const useStore = newStore[exportName] - console.log('checking for', exportName) + // console.log('checking for', exportName) if (isUseStore(useStore) && pinia._s.has(useStore.$id)) { - console.log('Accepting update for', useStore.$id) + // console.log('Accepting update for', useStore.$id) const id = useStore.$id if (id !== oldUseStore.$id) { @@ -101,17 +101,9 @@ if (import.meta.hot) { const existingStore: Store = pinia._s.get(id)! if (!existingStore) { console.log(`skipping hmr because store doesn't exist yet`) - // TODO: replace the useCounter var??? return } useStore(pinia, existingStore) - // remove the existing store from the cache to force a new one - // pinia._s.delete(id) - // this adds any new state to pinia and then runs the `hydrate` function - // which, by default, will reuse the existing state in pinia - // const newStore = useStore(pinia) - // console.log('going there', newStore._hmrPayload) - // pinia._s.set(id, existingStore) } } }) diff --git a/playground/src/test.ts b/playground/src/test.ts new file mode 100644 index 00000000..f1ea7842 --- /dev/null +++ b/playground/src/test.ts @@ -0,0 +1 @@ +export const ha = 3 diff --git a/playground/src/views/404.vue b/playground/src/views/404.vue new file mode 100644 index 00000000..3951a3e5 --- /dev/null +++ b/playground/src/views/404.vue @@ -0,0 +1,22 @@ + + + diff --git a/playground/src/views/About.vue b/playground/src/views/About.vue new file mode 100644 index 00000000..9ebb4d77 --- /dev/null +++ b/playground/src/views/About.vue @@ -0,0 +1,5 @@ + diff --git a/playground/src/components/TestStore.vue b/playground/src/views/AllStores.vue similarity index 100% rename from playground/src/components/TestStore.vue rename to playground/src/views/AllStores.vue diff --git a/playground/src/views/CounterStore.vue b/playground/src/views/CounterStore.vue new file mode 100644 index 00000000..60b5da96 --- /dev/null +++ b/playground/src/views/CounterStore.vue @@ -0,0 +1,58 @@ + + + diff --git a/yarn.lock b/yarn.lock index bcc45823..7d3e7077 100644 --- a/yarn.lock +++ b/yarn.lock @@ -923,6 +923,18 @@ resolved "https://registry.yarnpkg.com/@types/linkify-it/-/linkify-it-3.0.2.tgz#fd2cd2edbaa7eaac7e7f3c1748b52a19143846c9" integrity sha512-HZQYqbiFVWufzCwexrvh694SOim8z2d+xJl5UNamcvQFejLY/2YUtzXHYi3cHdI7PMlS8ejH2slRAOJQ32aNbA== +"@types/lodash.kebabcase@^4.1.6": + version "4.1.6" + resolved "https://registry.yarnpkg.com/@types/lodash.kebabcase/-/lodash.kebabcase-4.1.6.tgz#07b07aeca6c0647836de46f87a3cdfff72166c8e" + integrity sha512-+RAD9pCAa8kuVyCYTeDNiwBXwD/0u0p+hos3NSqD+tXTjJextbfF3farfYB+ssAKgEssoewXEtBsfwBpsI7gsA== + dependencies: + "@types/lodash" "*" + +"@types/lodash@*": + version "4.14.171" + resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.171.tgz#f01b3a5fe3499e34b622c362a46a609fdb23573b" + integrity sha512-7eQ2xYLLI/LsicL2nejW9Wyko3lcpN6O/z0ZLHrEQsg280zIdCv1t/0m6UtBjUHokCGBQ3gYTbHzDkZ1xOBwwg== + "@types/markdown-it@^12.0.1": version "12.0.3" resolved "https://registry.yarnpkg.com/@types/markdown-it/-/markdown-it-12.0.3.tgz#60a09363bebbd780fac815442b47d80f1a17bef1" @@ -1078,7 +1090,7 @@ "@vue/compiler-dom" "npm:@knightly/vue__compiler-dom@3.1.4-knightly-3-2.202107080810" "@vue/shared" "npm:@knightly/vue__shared@3.1.4-knightly-3-2.202107080810" -"@vue/devtools-api@^6.0.0-beta.15": +"@vue/devtools-api@^6.0.0-beta.14", "@vue/devtools-api@^6.0.0-beta.15": version "6.0.0-beta.15" resolved "https://registry.yarnpkg.com/@vue/devtools-api/-/devtools-api-6.0.0-beta.15.tgz#ad7cb384e062f165bcf9c83732125bffbc2ad83d" integrity sha512-quBx4Jjpexo6KDiNUGFr/zF/2A4srKM9S9v2uHgMXSU//hjgq1eGzqkIFql8T9gfX5ZaVOUzYBP3jIdIR3PKIA== @@ -3865,6 +3877,11 @@ lodash.ismatch@^4.4.0: resolved "https://registry.yarnpkg.com/lodash.ismatch/-/lodash.ismatch-4.4.0.tgz#756cb5150ca3ba6f11085a78849645f188f85f37" integrity sha1-dWy1FQyjum8RCFp4hJZF8Yj4Xzc= +lodash.kebabcase@^4.1.1: + version "4.1.1" + resolved "https://registry.yarnpkg.com/lodash.kebabcase/-/lodash.kebabcase-4.1.1.tgz#8489b1cb0d29ff88195cceca448ff6d6cc295c36" + integrity sha1-hImxyw0p/4gZXM7KRI/21swpXDY= + lodash@^4.17.15, lodash@^4.7.0, lodash@~4.17.15: version "4.17.21" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" @@ -5782,6 +5799,13 @@ vue-demi@*: resolved "https://registry.yarnpkg.com/vue-demi/-/vue-demi-0.10.0.tgz#e21cad49e4aee210093de658684f0ba49ae404f1" integrity sha512-SlVtIkcCVwbSVAiWTk3ixcDF6bRjgPP5nKGjSx4HXmieEUDi2oVQJUQxoFmEOV21js7TKvclzEUhInDEkg0NDQ== +vue-router@^4.0.10: + version "4.0.10" + resolved "https://registry.yarnpkg.com/vue-router/-/vue-router-4.0.10.tgz#ec8fda032949b2a31d3273170f8f376e86eb52ac" + integrity sha512-YbPf6QnZpyyWfnk7CUt2Bme+vo7TLfg1nGZNkvYqKYh4vLaFw6Gn8bPGdmt5m4qrGnKoXLqc4htAsd3dIukICA== + dependencies: + "@vue/devtools-api" "^6.0.0-beta.14" + vue@^3.1.1, "vue@npm:@knightly/vue@3-2": version "3.1.4-knightly-3-2.202107080810" resolved "https://registry.yarnpkg.com/@knightly/vue/-/vue-3.1.4-knightly-3-2.202107080810.tgz#ab5818365805d003238df3dce739b5d720663954"