Javascript is required
Weekly Vue News Logo Weekly Vue News

Document is empty, overwrite this content with #empty slot in <ContentDoc>.

Weekly Vue News - #64 - Reactivity Transform

Migrated Issue
Expect missing links and broken styling, as this issue has been migrated from my previous newsletter service.

Hi ๐Ÿ‘‹

Last week published a new blog post about a polite newsletter signup that I have developed for my portfolio website based on Nuxt 3.

This week is quite busy and I'll not be able to work on cool stuff ๐Ÿซ 

Have a great week โ˜€๏ธ


Vue Tip: Reactivity Transform

โš ๏ธ Reactivity Transform is currently an experimental feature. It is disabled by default and requires explicit opt-in. It may also change before being finalized.

โ„น๏ธ Reactivity Transform is a Composition-API-specific feature and requires a build step.

One of the most confusing concepts in Vue 3 is the use of refs vs. reactive objects. It's easy to lose reactivity when destructuring reactive objects, while it can be cumbersome to use .value everywhere when using refs. Also, .value is easy to miss if not using a type system.

Vue Reactivity Transform is a new experimental compile-time transform that allows us to write code like this:

Image created with CodeSnap.dev

We no longer need to use .value. In fact, this makes our JS/TS code work the same way as in Vue templates where root-level refs are automatically unwrapped.

Every reactivity API that returns refs will have a $-prefixed macro equivalent. These APIs include:

  • ref -> $ref
  • computed -> $computed
  • shallowRef -> $shallowRef
  • customRef -> $customRef
  • toRef -> $toRef

The RFC defines some more compiler-macros:

  • Destructure objects or convert existing refs to reactive variables with $()
  • Destructuring defineProps() in <script setup> also creates reactive variables.
  • Retrieve the underlying refs from reactive variables with $$()

Read more about Reactivity Transform in the RFC.

Curated Vue Content

Building a Polite Newsletter Popup With Nuxt 3

In this article, I'll explain how I built a polite popup to ask people if they would like to subscribe to my newsletter using Nuxt 3.

๐Ÿคฉ Nuxt Movies

๐Ÿ‘‰๐Ÿป Movies app demo built using Nuxt 3, Vue 3, UnoCSS, Image Module, The Movie Database API and TypeScript.

๐Ÿฟ Live preview: https://movies.nuxt.space/

๐Ÿ“• Vue 3 + Pinia + Supabase Auth

๐Ÿ‘‰๐Ÿป This article will run through how to use Supabase Auth (email) in a Vue 3 app, using Pinia for state management.

๐Ÿ› ๏ธ Vue Macros

๐Ÿ‘‰๐Ÿป Explore and extend more macros and syntax sugar to Vue.

๐Ÿ‘‰๐Ÿป Supports both Vue 2 and Vue 3 out-of-the-box.

๐Ÿ‘‰๐Ÿป Full TypeScript / Volar support.

๐Ÿ‘‰๐Ÿป Supports Vite, Webpack, Vue CLI, Rollup, esbuild and more, powered by unplugin.

๐Ÿ“น Patterns of VueUse (Talk by Anthony Fu)

๐Ÿ‘‰๐Ÿป Patterns and best practices the team learnt during the two years building VueUse

๐Ÿ“น ViteConf recording of the Vite ecosystem

๐Ÿ‘‰๐Ÿป See all the tools that influenced, use, or are used by Vite.

JavaScript Tip: Function that throws an error if a required parameter is missing

Sometimes we need to ensure that a required parameter has been provided. This can be achieved by using default function parameters.

Default function parameters allow named parameters to be initialized with default values if no value or undefined is passed.

We can take the advantages of this ES6 feature and make a function which throws an error and assign it as default value for required parameters. So when no parameter is passed this function will be called and it will thrown an error.

Image created with CodeSnap.dev

Curated Web Development Content

๐Ÿ“• TypeScript: Type Guards

๐Ÿ‘‰๐Ÿป Robin shows how to check for user defined types by using so-called user-defined type guards.

๐Ÿ“• Write better error messages

๐Ÿ‘‰๐Ÿป "It explains what happened and why, provides reassurance, is empathetic, helps the user fix the issue and gives the user a way out."

๐Ÿ“• The Webโ€™s Next Transition

๐Ÿ‘‰๐Ÿป Kent takes a detailed look at the transition to new and improved architectures (progressively enhanced SPAs) for building web applications, and how changes to multi-page apps are coming about.

๐Ÿ‘‰๐Ÿป ~33 minutes read time ๐Ÿ˜ฎ

Quote of the Week

Weekly Vue News LogoWeekly newsletter that gives you high-quality tips and curated content about Vue & Nuxt.
I will never share any of your personal data.
ยฉ 2023 weekly-vue.news. All rights reserved.