harlan-zw / nuxt-site-config

Unifying site config with powerful and flexible APIs, for module authors and users.
https://nuxtseo.com/site-config
61 stars 3 forks source link

feat!: implement singleton #7

Closed dargmuesli closed 6 months ago

dargmuesli commented 9 months ago

Description

BREAKING: useSiteConfig now has a value getter & setter which allows to use it anytime and access up-to-date variables inside.

Linked Issues

n/a

Additional context

See the test as an example for what's currently failing: using site-config, then updating it and checking for updates values through the site-config used before.

harlan-zw commented 9 months ago

This is a good solution to the issue but I'll need some time to think about if this is the best path forward.

Out of curiosity, can't you just call useSiteConfig when you need to access the data instead of storing it?

dargmuesli commented 9 months ago

Yes, that should work as well. It's just that I was very confused that useSiteConfig does not provide a ref while most other Vue composables do. I spent quite a bit of time figuring out why the site config I used did not contain the description I updated it with.

dargmuesli commented 9 months ago

And computed does not like to have getter and setter of different types...

dargmuesli commented 9 months ago

Ok, maybe a more understandable / real world use case would be:

updateSiteConfig({
  description: siteDescriptionProp.value,
})
defineOgImage({
  alt: ogImageAltProp.value,
  component: ogImageComponentProp.value,
})

The og image would not have the description available right without this PR.

See the build logs here: https://github.com/dargmuesli/vio/pull/67

harlan-zw commented 6 months ago

I think you have a valid issue that you're trying to solve in this PR, however, I don't think I can merge this as is as it would be a breaking change and I'd prefer to keep the existing API (it lets me expand it easier in the future).

I have made an issue to solve this at some point though: https://github.com/harlan-zw/nuxt-site-config/issues/11