From b0efe5a918fa2a54666030effbbc2f9c55ba2b3f Mon Sep 17 00:00:00 2001 From: skirtle <65301168+skirtles-code@users.noreply.github.com> Date: Wed, 1 Feb 2023 18:49:41 +0000 Subject: [PATCH 01/10] Initial draft of a glossary page --- src/glossary/index.md | 318 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 318 insertions(+) create mode 100644 src/glossary/index.md diff --git a/src/glossary/index.md b/src/glossary/index.md new file mode 100644 index 0000000000..71fb6b4f89 --- /dev/null +++ b/src/glossary/index.md @@ -0,0 +1,318 @@ +# Glossary + +This glossary is intended to provide some rough guidance about the meanings of technical terms that are in common usage when talking about Vue. It is intended to be *descriptive* of how terms are commonly used, not a *prescriptive* specification of how they must be used. Some terms may have slightly different meanings or nuances depending on the surrounding context. + +[[TOC]] + +## compiler macro + +A *compiler macro* is special code that is processed by a compiler and converted into something else. They are effectively just a clever form of string replacement. + +Vue's [SFC](#single-file-component) compiler supports various macros, such as `defineProps()`, `defineEmits()` and `defineExpose()`. These macros are intentionally designed to look like normal JavaScript functions, but they aren't functions at all. These are special strings that the compiler detects and replaces with the real JavaScript code that will run in the browser. + +Macros have limitations on their use that don't apply to normal JavaScript code. For example, you might think that `const dp = defineProps` would allow you to create an alias for `defineProps`, but it'll actually result in an error. There are also limitations on what values can be passed to `defineProps()`, as the 'arguments' have to be processed by the compiler and not at runtime. + +These macros are conceptually similar to dynamic imports using `import()`. While `import()` looks a lot like a function call, it's actually special syntax that gets processed by the bundler as part of the build. Like with `defineProps()`, we can't create an alias using `const myImport = import`. There are also restrictions on exactly what syntax can be used to pass values to the 'function', so that the compiler can understand the values. + +## composable + +The term *composable* describes a common usage pattern in Vue. It isn't a separate feature of Vue, it's just a way of using the framework's Composition API. As with many patterns, there can be some disagreement about whether specific code qualifies for the label. + +* A composable is a function. +* The function name usually begins with `use` so that other developers know it's a composable. +* The function is typically expected to be called from inside a component's `setup()` function (or within a ` +``` + +```vue + +``` + +In some cases it may be necessary to use functions from the Composition API within the Options API, for example: + +```js +import { computed } from 'vue' + +export default { + data() { + return { + message: 'hello!' + } + }, + provide() { + return { + // explicitly provide a computed property + message: computed(() => this.message) + } + } +} +``` + +Even though `computed()` is part of the Composition API, the component above would usually be described as being an Options API component, not a Composition API component. + +## effect + +See [reactive effect](#reactive-effect) and [side effect](#side-effect). + +## fragment + +The term *fragment* refers to a VNode that is used as a parent for other VNodes, but which doesn't render any elements itself. + +The name comes from the similar concept of a [`DocumentFragment`](https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment) in the standard DOM. + +Fragments are used to support components with multiple root nodes. While such components might appear to have multiple roots, behind the scenes they actually use a fragment node as a single root, as a parent of the 'root' nodes. + +Fragments are also used by the template compiler as a way to wrap multiple dynamic nodes, e.g. those created via `v-for` or `v-if`. This allows for extra hints to be passed to the VDOM patching algorithm. Much of this is handled internally, but one place you'll encounter this directly is using a `key` on a `