|
|
@@ -0,0 +1,21 @@
|
|
|
+import { useEntityStore } from "pinia-colada-plugin-normalizer"
|
|
|
+
|
|
|
+export default defineNuxtPlugin({
|
|
|
+ name: "normalize-plugin",
|
|
|
+
|
|
|
+ setup: (nuxtApp) => {
|
|
|
+ const entityStore = useEntityStore()
|
|
|
+
|
|
|
+ if (import.meta.server) {
|
|
|
+ nuxtApp.hook("app:rendered", ({ ssrContext }) => {
|
|
|
+ ssrContext.payload.normalizer = entityStore.toJSON()
|
|
|
+
|
|
|
+ // console.log("[normalize-plugin] [entityStore.toJSON]")
|
|
|
+ })
|
|
|
+ } else if (nuxtApp.payload && nuxtApp.payload.normalizer) {
|
|
|
+ entityStore.hydrate(nuxtApp.payload.normalizer)
|
|
|
+
|
|
|
+ // console.log("[normalize-plugin] [entityStore.hydrate]")
|
|
|
+ }
|
|
|
+ }
|
|
|
+})
|