Class Serialization with SSR in Nuxt - no more POJO error messages!

  Рет қаралды 3,555

Alexander Lichter

Alexander Lichter

Күн бұрын

Пікірлер: 48
@TheAlexLichter
@TheAlexLichter 8 ай бұрын
Are you a fan of classes in JavaScript?
@ReDestro69
@ReDestro69 8 ай бұрын
Not a fan of OOP in general😂
@CodeZakk
@CodeZakk 8 ай бұрын
Yes I use that if you use angular it uses classes everywhere. It makes your code more reusable and organized. ❤
@TheAlexLichter
@TheAlexLichter 8 ай бұрын
@ReDestro69 I actually like it for the back-end but if everything is composable and a bit more functional, that's my favorite 👌
@TheAlexLichter
@TheAlexLichter 8 ай бұрын
@CodeZakk Yes, I know in Angular you can't get around them :D Same for Web components. With regards to organization, especially in Vue, there are better patters IMO - see my 2nd latest video kzbin.info/www/bejne/n3zEdXl3rd99r9k 😊
@breezycodes
@breezycodes 8 ай бұрын
In Nestjs, yes... otherwise, no
@solay3985
@solay3985 8 ай бұрын
I'm surprised this is not mentioned at all in the docs. This is really good to know. We have some big pinia stores where we didn't use classes. Welp, time to do some refactoring...
@TheAlexLichter
@TheAlexLichter 8 ай бұрын
Oh it is mentioned - the link to the docs is in the video 😋 In Vue/Nuxt I mostly prefer composables over classes. But I'm very curious - why did you choose classes in your project? 😊
@solay3985
@solay3985 8 ай бұрын
Hm.. I can't find information about `definePayloadPlugin` there and think it should definitely be documented. We are using classes to encapsulate logic that is not necessarily vue-related (e.g. sharing classes across projects). We are a bit biased though, because we are used to OOP.
@TheAlexLichter
@TheAlexLichter 8 ай бұрын
It is mentioned in nuxt.com/docs/api/composables/use-nuxt-app#payload But right now, there is no difference between defineNuxtPlugin and definePayloadPlugin 👌 Ah, interesting! Good to know 👍
@luc122c
@luc122c 8 ай бұрын
I’ve seen this so many times dealing with Firebase Document references 😂 This is great, thank you! If only I’d have known earlier.
@TheAlexLichter
@TheAlexLichter 8 ай бұрын
No problem Luc! Hope it'll help for the future 😋
@Reagan_Dev
@Reagan_Dev 8 ай бұрын
I'm excited for the Nitro topics 🙌👏
@TheAlexLichter
@TheAlexLichter 8 ай бұрын
Me too! Anything specific you want to see covered 👀
@SKTTWkartrider
@SKTTWkartrider 8 ай бұрын
It's interesting to know how to handle custom payloads as `definePayloadPlugin` is not even documented on Nuxt website. Not sure whether there's a documentation PR for it.
@TheAlexLichter
@TheAlexLichter 8 ай бұрын
nuxt.com/docs/api/composables/use-nuxt-app#payload
@sania3631
@sania3631 8 ай бұрын
Thanks! As usual... great video.
@TheAlexLichter
@TheAlexLichter 8 ай бұрын
My pleasure! 😊
@voi__wood5508
@voi__wood5508 8 ай бұрын
great video, thank you for your excellent work
@TheAlexLichter
@TheAlexLichter 8 ай бұрын
You are welcome! 🙌
@cat_copilot
@cat_copilot 8 ай бұрын
Thanks for sharing this info
@TheAlexLichter
@TheAlexLichter 8 ай бұрын
You are welcome 👌
@productdevbook
@productdevbook 8 ай бұрын
Thank you
@TheAlexLichter
@TheAlexLichter 8 ай бұрын
No problem at all 😊
@qqlash
@qqlash 8 ай бұрын
Could you create a video about lazy importing external libraries? eg. I would like to use popper in my app, and want to load it lazy on demand and to have types?
@TheAlexLichter
@TheAlexLichter 8 ай бұрын
Will add it to the list, sure!
@MatheusPachecoPacheco-j2f
@MatheusPachecoPacheco-j2f 6 ай бұрын
"Using classes with Vue and Nuxt is not the most common approach" - Why is this not a common approach? I am experienced in Vue and recently started using nuxt. I like to use classes to encapsulate logic, such as a cart class in a pinia state to manipulate, additions, discount calculation, etc. What would be the best practices for working with classless (or with) nuxt? Ps.: Sorry for my English, I'm Brazilian
@TheAlexLichter
@TheAlexLichter 6 ай бұрын
Various reasons: A main point is that it is really tricky to work with Vue's reactivity and classes, which internally manage own state. Another one is that classes are not easily serializable as shown in the video. Insteado f a cart class for pinia, you can use state refs (or reactive if you want to) + functions, while still containing it in the same file ☺️ I personally never use classes in Nuxt, unless a library I have to use only provides classes.
@gruceing
@gruceing 7 ай бұрын
Does this work with useFetch? In transform?
@TheAlexLichter
@TheAlexLichter 7 ай бұрын
Yes, it does!
@beedav9236
@beedav9236 3 ай бұрын
I am experiencing these same problems when serializing types. How do you serialize a export type A = {}?
@TheAlexLichter
@TheAlexLichter 3 ай бұрын
Types do not exist during runtime and thus don’t need to be serialized 👀
@beedav9236
@beedav9236 3 ай бұрын
@@TheAlexLichter However, I am getting the same error when I use a type. It is the only type in a very small project I am trying out. I don't have any classes in the project.
@TheAlexLichter
@TheAlexLichter 3 ай бұрын
Can you provide a reproduction by any chance? Happy to have a look
@beedav9236
@beedav9236 3 ай бұрын
Yes, I just a little time to create some data to replicate the results from MongoDB. Where you want me to put the example?
@beedav9236
@beedav9236 3 ай бұрын
Could it be possible I am seeing this error because I am making axios.get() calls in my composables and returning the result as a type object? When I hover over the result returned from axios, I see that it is the type I defined for the object. I am not using the server/api but making axios calls directly in my composables and returning the response unchanged to the script in my component. I then save the state as const result like this useState('dataResult', () => responseFromAxios). If I then try to access this state in another part of the application as const myData = useState('dataResult') that was stored earlier, I get the error 'cannot stringify arbitrary non POJOs etc.....'
@виртуоз_ру
@виртуоз_ру 8 ай бұрын
Шляпа какая-то 🤣
@TheAlexLichter
@TheAlexLichter 8 ай бұрын
🤣🤣🤣
Nuxt 3.10 - Speed up your build time with sharedPrerenderData
13:14
Alexander Lichter
Рет қаралды 3,6 М.
What is BFF?! (With Nuxt, Nitro and h3)
26:05
Alexander Lichter
Рет қаралды 7 М.
Spongebob ate Michael Jackson 😱 #meme #spongebob #gmod
00:14
Mr. LoLo
Рет қаралды 10 МЛН
Is Vue the fastest when it comes to SSR?
15:16
Alexander Lichter
Рет қаралды 4,9 М.
BEWARE these Laravel attributes | Real World Laravel
19:10
Sam Lewis
Рет қаралды 4,4 М.
Java Future
15:37
Do Some Dev
Рет қаралды 237
🚨 Dependency warnings in a fresh Nuxt application?
15:49
Alexander Lichter
Рет қаралды 521
Highly secure instant touch transfer is here | Hard Reset
17:57
Are Front-end frameworks a security vulnerability by default?
11:51
Alexander Lichter
Рет қаралды 3,5 М.
Composition API vs. Options API - One API to Rule Them All?!
26:18
Alexander Lichter
Рет қаралды 4,4 М.
Route Rules in Nuxt - SSR, SSG, ISR and more
25:43
Alexander Lichter
Рет қаралды 3,5 М.
Loading Third Party Assets with Nuxt Scripts
15:47
Alexander Lichter
Рет қаралды 2,9 М.