Comments (11)
I'm 👍 for using shallowRef()
instead of reactive()
for pageContext
as well.
But it means that users will have to deconstruct the wrapper using .value
. Is that an acceptable DX? I'm not that familiar with what Vue users expect.
I guess ref()
is quite ubiquitous and I guess users are very well used to deconstruct with .value
, right?
from vike-vue.
I'm a little afraid about changing pageContext
usage.
Considering that the shape (object) does not change and that all properties that might be leftovers should be enumerable I would go with a simple cleanup like this: https://play.vuejs.org/#eNp9krFu4zAMhl+F0NIEMFwUd5ORFLgrMtwNl6LXreqgyrSjxJYEiU5TGH730nbdejA6ivwpfvzJVvzyPj03KDKxiToYTxCRGn8rram9CwQtBFSazBmhgyK4Gq5YfyWttNrZSOBViXfOEl7oYVJuP4tWLagMbhJ4yeDpOQGdQdslkGfQ2BwLYzGHbr3wF/8xlX7V3EDXN96/HFFTesK3uFpov04LF3ZKH1ar0xq2t9BKC2AKmIvTg4r7V3sfnMdAb4Nyu4VCVRHXYwVAjhUSLo34dHruJYzT038AqRhNaZeQkvkfXLC5Ht1mn/lBWPtKEfILoG0XLe241eZ6phSJoMi2FaZMj9FZXuFALYV2tTcVhr0nw7ZKwf6N80ihqsq9/h1iFBpMprg+oD4txI/x0sekuA8YMZxRis8cqVAijend/39MO0vWLm8qVn+TfMDoqqZnHGW/+SQYe6YbaP8Mh2hs+Rh3F0Ibp6F60GEJg14Kvsu7b0b/wv2R/pyWJ7p3TmoGfQ==
If you have an idea for a more optimized cleanup it would be nice.
Maybe like this, to reduce the number of updates on pageContextReactive
to only 1: https://play.vuejs.org/#eNp9UrFu4zAM/RVCSxPAda+4m9y4wF3R4W64FG23KIPr0I5SWRIkOk1h+N9LO3HiwSigReTj43skG/HbuXhfo0jEIuReOYKAVLt7aVTlrCdowGOWk9ojtFB4W8EV46+kkSa3JhC4rMQHawgP9Dwg03PRrIEsgdsI3hJYrSPIE2jaCDYJ1GaDhTK4gXY+wcUcQ+ml5hbaS+N3/AyMWr7tMKe4+80mtDB3YT3MNBIohne4WKMpaXsH19cK7lP4cTeHRhqAjthqjLUtZ4orAVQBY9Z4m4Xlh3ny1qGnz1nHtlLrOaRpCkWmA56YYOxldYKtuf/ZdodiN/xODrIQVGmmPERjMpa1uDnuirfEH8LK6YyQfwBNM7mQltssbkZIEQkKbLdQZbwL1vAB9LqlyG3llEa/dKR4HFLw9I+OpMi0th//+hj5GqMhnm8xf5+I78Khi0nx5DGg36MU5xxlvkQ6ph9f/rPaUbKym1oz+pvkM/Kq6k7jEfaHJ8uyR7he7d/+jJUpX8PjgdCEwVQntN9Bj5eCr/rhG+sXuT/jX8PuRPsFJwkbYA==
from vike-vue.
I think if we do this for pageContext
then we might as well do it for data
.
The main reason for using shallowRef()
instead of reactive()
for data
is performance, right?
Now, pageContext
actually contains data
at pageContext.data
and reactive()
is deep. So, from a performance perspective, I don't think it makes sense to use shallowRef()
for data
while using reactive()
for pageContext
?
from vike-vue.
For performance we can go with shallowReactive
for pageContext
.
But ignoring performance:
data
can change shape (object<->array) and this cannot be fixed- both
data
andpageContext
can end up with leftover properties
For pageContext
this can be fixed with cleanup (and performance boost by using shallowReactive
) keeping DX.
For data
this can only be fixed by replacing the object (and the only solution I can think of is using shallowRef
and breaking the DX in JS/TS but keeping it in templates.
from vike-vue.
I didn't know about shallowReactive()
... very neat. Maybe that's what we want for both data
and pageContext
then 🤔
data
can change shape (object<->array) and this cannot be fixed
IMO this isn't a hard requirement. I think it's ok to tell users:
Make sure
data
is an object. If you want to return a list then do this:- return productList + return { productList }
from vike-vue.
If we force data to be objects than cleanup + shallow reactive would solve the problems and keep DX (except the DX change induced by forcing data to be non-array object)
from vike-vue.
On my side, I'm 👍 for using shallowReactive()
+ cleanup for both pageContext
and data
. Also nice because we preserve the current DX (which already forces data to be an object anyways).
We can later see if we want to replace shallowReactive()
with shallowRef()
, depending on whether some user complains about our shallowReactive()
solution. (Because IMO using shallowReactive()
is a hack and the cleanest would be shallowRef()
.)
from vike-vue.
Different DX:
const a = shallowRef({ y: 1 })
a.value = { x: [ 2 ] } // reactive, you can change the whole content with whatever you want
a.value.x = [ 3 ] // not reactive
a.value.x.push(4) // not reactive
const b = shallowReactive({ x: 1 })
a.x = [ 2 ] // reactive, you cannot change the base (container) object
a.x.push(4) // not reactive
from vike-vue.
Yea. To me the crux of it is that users don't have to use .value
outside of <template>
if we go for shallowReactive()
.
from vike-vue.
If you have an idea for a more optimized cleanup it would be nice. Maybe like this, to reduce the number of updates on
pageContextReactive
to only 1
Neat idea, although one issue is that the undefined
keys will still be enumerable.
I don't expect objects to contain that many keys so I think we can go for the straightforward solution. If performance is an issue for some users we can then re-consider.
I went ahead and amended your PR, I hope it's ok and let me know if you disagree.
from vike-vue.
Looks very good to me, thank you
from vike-vue.
Related Issues (20)
- Wrong data in `useData` after client side navigation HOT 15
- Write docs for `vike-vue-pinia` and `vike-vue-query` HOT 1
- Sell vike-vue + JSX? HOT 1
- vikeVuePinia causes error HOT 4
- Dependency Dashboard
- Action Required: Fix Renovate Configuration
- Updating `lang` on client-side navigation
- Register plugins that don't use `app.use` HOT 5
- I can't get working examples HOT 3
- Improve DX of ClientOnly component HOT 3
- (Re-)introduce fine-grained head settings HOT 14
- Client side routing with catch all page throwing error HOT 4
- `clientOnly()` function instead of `<ClientOnly>` wrapper component HOT 29
- Progressive Rendering HOT 11
- Nuxt Comparison HOT 4
- Support for `teleports` with Vue SSR HOT 29
- Improve hooks? HOT 20
- Export Vike configuration at `/config`
- Release `vike-vue-{pinia,query}@0.1.0`? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vike-vue.