]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
docs: add mastering pinia link
authorEduardo San Martin Morote <posva13@gmail.com>
Wed, 15 May 2024 13:39:11 +0000 (15:39 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Wed, 15 May 2024 13:40:18 +0000 (15:40 +0200)
20 files changed:
packages/docs/.vitepress/theme/components/MasteringPiniaLink.vue [new file with mode: 0644]
packages/docs/.vitepress/theme/index.ts
packages/docs/core-concepts/actions.md
packages/docs/core-concepts/getters.md
packages/docs/core-concepts/index.md
packages/docs/core-concepts/outside-component-usage.md
packages/docs/core-concepts/plugins.md
packages/docs/core-concepts/state.md
packages/docs/introduction.md
packages/docs/ssr/index.md
packages/docs/ssr/nuxt.md
packages/docs/zh/core-concepts/actions.md
packages/docs/zh/core-concepts/getters.md
packages/docs/zh/core-concepts/index.md
packages/docs/zh/core-concepts/outside-component-usage.md
packages/docs/zh/core-concepts/plugins.md
packages/docs/zh/core-concepts/state.md
packages/docs/zh/introduction.md
packages/docs/zh/ssr/index.md
packages/docs/zh/ssr/nuxt.md

diff --git a/packages/docs/.vitepress/theme/components/MasteringPiniaLink.vue b/packages/docs/.vitepress/theme/components/MasteringPiniaLink.vue
new file mode 100644 (file)
index 0000000..5a934a2
--- /dev/null
@@ -0,0 +1,83 @@
+<script setup lang="ts">
+import { useData } from 'vitepress'
+
+const { site } = useData()
+const translations = {
+  'en-US':
+    'Master this and much more with the official video course by the author of Pinia',
+  'zh-CN': '通过 Pinia 作者的官方视频课程掌握更多内容',
+}
+defineProps<{ href: string; title: string }>()
+</script>
+
+<template>
+  <div class="mp">
+    <a
+      :href="href"
+      target="_blank"
+      rel="noopener"
+      :title="title"
+      class="no-icon"
+    >
+      <div class="text">
+        <slot>{{ translations[site.lang] }}</slot>
+      </div>
+    </a>
+  </div>
+</template>
+
+<style scoped>
+.mp {
+  margin-top: 20px;
+  background-color: var(--vp-code-block-bg);
+  padding: 1em 1.25em;
+  border-radius: 2px;
+  position: relative;
+  border-radius: 1em;
+  border: 2px solid var(--vp-c-bg-alt);
+  transition: border-color 0.5s;
+}
+.mp:hover {
+  border: 2px solid var(--vp-c-brand-1);
+}
+
+.mp a {
+  color: var(--c-text);
+  position: relative;
+  display: flex;
+  gap: 1em;
+  grid-template-columns: 1fr auto;
+  align-items: center;
+  justify-content: space-between;
+  padding-left: 36px;
+}
+.mp a .content {
+  flex-grow: 1;
+}
+.mp a:before {
+  content: '';
+  position: absolute;
+  display: block;
+  width: 30px;
+  height: 30px;
+  top: calc(50% - 15px);
+  left: -4px;
+  border-radius: 50%;
+  background-color: var(--vp-c-brand-1);
+}
+html.dark .mp a:after {
+  --play-icon-color: #000;
+}
+.mp a:after {
+  content: '';
+  position: absolute;
+  display: block;
+  width: 0;
+  height: 0;
+  top: calc(50% - 5px);
+  left: 8px;
+  border-top: 5px solid transparent;
+  border-bottom: 5px solid transparent;
+  border-left: 9px solid var(--play-icon-color, #fff);
+}
+</style>
index 760a11262449ec8c494f56aee76d62bdf642e015..374d96f9a2c9d4e073609c2177ffdec0daf41d22 100644 (file)
@@ -8,6 +8,7 @@ import './styles/vars.css'
 import './styles/playground-links.css'
 import VueSchoolLink from './components/VueSchoolLink.vue'
 import VueMasteryLogoLink from './components/VueMasteryLogoLink.vue'
+import MasteringPiniaLink from './components/MasteringPiniaLink.vue'
 // import VuejsdeConfBanner from './components/VuejsdeConfBanner.vue'
 import status from '../translation-status.json'
 
@@ -29,6 +30,7 @@ const theme: Theme = {
   enhanceApp({ app }) {
     app.component('VueSchoolLink', VueSchoolLink)
     app.component('VueMasteryLogoLink', VueMasteryLogoLink)
+    app.component('MasteringPiniaLink', MasteringPiniaLink)
   },
 }
 
index eb275a1a01e4f453149a66e950390543093403ba..3ca10b4fd33d2e15b5b64868d5c60f8212f624cf 100644 (file)
@@ -1,8 +1,13 @@
 # Actions
 
-<VueSchoolLink
+<!-- <VueSchoolLink
   href="https://vueschool.io/lessons/synchronous-and-asynchronous-actions-in-pinia"
   title="Learn all about actions in Pinia"
+/> -->
+
+<MasteringPiniaLink
+  href="https://masteringpinia.com/lessons/the-3-pillars-of-pinia-actions"
+  title="Learn all about actions in Pinia"
 />
 
 Actions are the equivalent of [methods](https://vuejs.org/api/options-state.html#methods) in components. They can be defined with the `actions` property in `defineStore()` and **they are perfect to define business logic**:
index 69e6f55909d34caf92a0e4a02198a76f6bc64c19..4942c7baa22df49afdc844656d50854c28dec4dc 100644 (file)
@@ -1,8 +1,13 @@
 # Getters
 
-<VueSchoolLink
+<!-- <VueSchoolLink
   href="https://vueschool.io/lessons/getters-in-pinia"
   title="Learn all about getters in Pinia"
+/> -->
+
+<MasteringPiniaLink
+  href="https://masteringpinia.com/lessons/the-3-pillars-of-pinia-getters"
+  title="Learn all about getters in Pinia"
 />
 
 Getters are exactly the equivalent of [computed values](https://vuejs.org/guide/essentials/computed.html) for the state of a Store. They can be defined with the `getters` property in `defineStore()`. They receive the `state` as the first parameter **to encourage** the usage of arrow function:
index 4bbe1f9ff1ffc6b97cd3ed7ec9d1388e9c6afb70..0d6dc7e913bbba5737d768685943d2e7e26f8901 100644 (file)
@@ -1,8 +1,13 @@
 # Defining a Store
 
-<VueSchoolLink
+<!-- <VueSchoolLink
   href="https://vueschool.io/lessons/define-your-first-pinia-store"
   title="Learn how to define and use stores in Pinia"
+/> -->
+
+<MasteringPiniaLink
+  href="https://masteringpinia.com/lessons/quick-start-with-pinia"
+  title="Get started with Pinia"
 />
 
 Before diving into core concepts, we need to know that a store is defined using `defineStore()` and that it requires a **unique** name, passed as the first argument:
index 7b5392d68d002df35593ab1b368c0a195b187812..2661586cdfe2b64cf8709843ba638ec26118f100 100644 (file)
@@ -1,5 +1,10 @@
 # Using a store outside of a component
 
+<MasteringPiniaLink
+  href="https://masteringpinia.com/lessons/how-does-usestore-work"
+  title="Using stores outside of components"
+/>
+
 Pinia stores rely on the `pinia` instance to share the same store instance across all calls. Most of the time, this works out of the box by just calling your `useStore()` function. For example, in `setup()`, you don't need to do anything else. But things are a bit different outside of a component.
 Behind the scenes, `useStore()` _injects_ the `pinia` instance you gave to your `app`. This means that if the `pinia` instance cannot be automatically injected, you have to manually provide it to the `useStore()` function.
 You can solve this differently depending on the kind of application you are writing.
index 680315dc1ad8b46b2dc3a57d37777d779db129ba..728e69da8194e18c4bb84068b1d7570a4673bdbb 100644 (file)
@@ -1,5 +1,10 @@
 # Plugins
 
+<MasteringPiniaLink
+  href="https://masteringpinia.com/lessons/What-is-a-pinia-plugin"
+  title="Learn all about Pinia plugins"
+/>
+
 Pinia stores can be fully extended thanks to a low level API. Here is a list of things you can do:
 
 - Add new properties to stores
index 3ce0538dc6bea57f640986815ed618dc87f08954..8c6052bc141f2a77370cda8d5c0c21dc8ec10bd8 100644 (file)
@@ -1,12 +1,13 @@
 # State
 
-<!--
-https://masteringpinia.com/lessons/the-3-pillars-of-pinia-state
- -->
-
-<VueSchoolLink
+<!-- <VueSchoolLink
   href="https://vueschool.io/lessons/access-state-from-a-pinia-store"
   title="Learn all about state in Pinia"
+/> -->
+
+<MasteringPiniaLink
+  href="https://masteringpinia.com/lessons/the-3-pillars-of-pinia-state"
+  title="Learn all about state in Pinia"
 />
 
 The state is, most of the time, the central part of your store. People often start by defining the state that represents their app. In Pinia the state is defined as a function that returns the initial state. This allows Pinia to work in both Server and Client Side.
index 7213ee392fc0d5bc1809630377a7a1e347ef55b1..bb77684c6bc1dba2924ab2879087d2882109368e 100644 (file)
@@ -1,8 +1,13 @@
 # Introduction
 
-<VueSchoolLink
+<!-- <VueSchoolLink
   href="https://vueschool.io/lessons/introduction-to-pinia"
   title="Get started with Pinia"
+/> -->
+
+<MasteringPiniaLink
+  href="https://masteringpinia.com/lessons/the-what-and-why-of-state-management-and-stores"
+  title="Create your own Pinia from scratch"
 />
 
 Pinia [started](https://github.com/vuejs/pinia/commit/06aeef54e2cad66696063c62829dac74e15fd19e) as an experiment to redesign what a Store for Vue could look like with the [Composition API](https://github.com/vuejs/composition-api) around November 2019. Since then, the initial principles have remained the same, but Pinia works for both Vue 2 and Vue 3 **and doesn't require you to use the composition API**. The API is the same for both except for _installation_ and _SSR_, and these docs are targeted to Vue 3 **with notes about Vue 2** whenever necessary so it can be read by Vue 2 and Vue 3 users!
index d8ed2e567d34b15ab8711c80747cd6c7db8f1e17..43f4e7772a64fcdb9a05675a86c036dc19b3c4c4 100644 (file)
@@ -1,5 +1,10 @@
 # Server Side Rendering (SSR)
 
+<MasteringPiniaLink
+  href="https://masteringpinia.com/lessons/ssr-friendly-state"
+  title="Learn about SSR best practices"
+/>
+
 :::tip
 If you are using **Nuxt.js,** you need to read [**these instructions**](./nuxt.md) instead.
 :::
index 8ff6e225d6f74b989c1db0b2f9b6d6022de5402e..67a54b417394c423fbbe524a4e05ce86cc964dea 100644 (file)
@@ -1,5 +1,10 @@
 # Nuxt.js
 
+<MasteringPiniaLink
+  href="https://masteringpinia.com/lessons/ssr-friendly-state"
+  title="Learn about SSR best practices"
+/>
+
 Using Pinia with [Nuxt](https://nuxt.com/) is easier since Nuxt takes care of a lot of things when it comes to _server side rendering_. For instance, **you don't need to care about serialization nor XSS attacks**. Pinia supports Nuxt Bridge and Nuxt 3. For bare Nuxt 2 support, [see below](#nuxt-2-without-bridge).
 
 ## Installation
index 12662ec18754c781d06de025ca6523f363b7f4fd..002ebb7e2057a595777a96aef92cb618a0d39793 100644 (file)
@@ -1,8 +1,13 @@
 # Action %{#actions}%
 
-<VueSchoolLink
+<!-- <VueSchoolLink
   href="https://vueschool.io/lessons/synchronous-and-asynchronous-actions-in-pinia"
   title="Learn all about actions in Pinia"
+/> -->
+
+<MasteringPiniaLink
+  href="https://masteringpinia.com/lessons/the-3-pillars-of-pinia-actions"
+  title="Learn all about actions in Pinia"
 />
 
 Action 相当于组件中的 [method](https://v3.vuejs.org/guide/data-methods.html#methods)。它们可以通过 `defineStore()` 中的 `actions` 属性来定义,**并且它们也是定义业务逻辑的完美选择。**
index db78160ed8db378ab2a6ef7d5980893392b83576..b5b7396cb18e60a10525e1988a5ac370926ca6d2 100644 (file)
@@ -1,8 +1,13 @@
 # Getter %{#getters}%
 
-<VueSchoolLink
+<!-- <VueSchoolLink
   href="https://vueschool.io/lessons/getters-in-pinia"
   title="Learn all about getters in Pinia"
+/> -->
+
+<MasteringPiniaLink
+  href="https://masteringpinia.com/lessons/the-3-pillars-of-pinia-getters"
+  title="Learn all about getters in Pinia"
 />
 
 Getter 完全等同于 store 的 state 的[计算值](https://cn.vuejs.org/guide/essentials/computed.html)。可以通过 `defineStore()` 中的 `getters` 属性来定义它们。**推荐**使用箭头函数,并且它将接收 `state` 作为第一个参数:
index 53cdcc03748addde2c6e4a54beec7f7e1f6ae68b..15b7e50e5f4cb402e15b3e34ad8647eed73af06b 100644 (file)
@@ -1,8 +1,13 @@
 # 定义 Store %{#defining-a-store}%
 
-<VueSchoolLink
+<!-- <VueSchoolLink
   href="https://vueschool.io/lessons/define-your-first-pinia-store"
   title="Learn how to define and use stores in Pinia"
+/> -->
+
+<MasteringPiniaLink
+  href="https://masteringpinia.com/lessons/quick-start-with-pinia"
+  title="Get started with Pinia"
 />
 
 在深入研究核心概念之前,我们得知道 Store 是用 `defineStore()` 定义的,它的第一个参数要求是一个**独一无二的**名字:
index 7986921ed3164af98873a493515a0e1910ebab9d..2a699743b8e1d90ed6b2d13b455edf64907ce367 100644 (file)
@@ -1,5 +1,10 @@
 # 在组件外使用 store %{#using-a-store-outside-of-a-component}%
 
+<MasteringPiniaLink
+  href="https://masteringpinia.com/lessons/how-does-usestore-work"
+  title="Using stores outside of components"
+/>
+
 Pinia store 依靠 `pinia` 实例在所有调用中共享同一个 store 实例。大多数时候,只需调用你定义的 `useStore()` 函数,完全开箱即用。例如,在 `setup()` 中,你不需要再做任何事情。但在组件之外,情况就有点不同了。
 实际上,`useStore()` 给你的 `app` 自动注入了 `pinia` 实例。这意味着,如果 `pinia` 实例不能自动注入,你必须手动提供给 `useStore()` 函数。
 你可以根据不同的应用,以不同的方式解决这个问题。
index 9d659cddcda18219937dd7b86b661f8729159461..0790b22013c78f5d5b11e5ef94096b9cf7a6b538 100644 (file)
@@ -1,5 +1,10 @@
 # 插件 %{#plugins}%
 
+<MasteringPiniaLink
+  href="https://masteringpinia.com/lessons/What-is-a-pinia-plugin"
+  title="Learn all about Pinia plugins"
+/>
+
 由于有了底层 API 的支持,Pinia store 现在完全支持扩展。以下是你可以扩展的内容:
 
 - 为 store 添加新的属性
index 43b1912da27cc4aa2f3d95733fc569ee65b7916a..08bb681b355b415848efd7e545d4535423e02eb8 100644 (file)
@@ -1,8 +1,13 @@
 # State %{#state}%
 
-<VueSchoolLink
+<!-- <VueSchoolLink
   href="https://vueschool.io/lessons/access-state-from-a-pinia-store"
   title="Learn all about state in Pinia"
+/> -->
+
+<MasteringPiniaLink
+  href="https://masteringpinia.com/lessons/the-3-pillars-of-pinia-state"
+  title="Learn all about state in Pinia"
 />
 
 在大多数情况下,state 都是你的 store 的核心。人们通常会先定义能代表他们 APP 的 state。在 Pinia 中,state 被定义为一个返回初始状态的函数。这使得 Pinia 可以同时支持服务端和客户端。
index 8e3c5d9f00b49f981e93ac0fd4051de23fd796e9..04d50bed6706912598d1c489dad840c7b64b909e 100644 (file)
@@ -1,8 +1,13 @@
 # 简介 %{#introduction}%
 
-<VueSchoolLink
+<!-- <VueSchoolLink
   href="https://vueschool.io/lessons/introduction-to-pinia"
   title="Get started with Pinia"
+/> -->
+
+<MasteringPiniaLink
+  href="https://masteringpinia.com/lessons/the-what-and-why-of-state-management-and-stores"
+  title="Create your own Pinia from scratch"
 />
 
 Pinia [起始](https://github.com/vuejs/pinia/commit/06aeef54e2cad66696063c62829dac74e15fd19e)于 2019 年 11 月左右的一次实验,其目的是设计一个拥有[组合式 API](https://github.com/vuejs/composition-api) 的 Vue 状态管理库。从那时起,我们就倾向于同时支持 Vue 2 和 Vue 3,并且不强制要求开发者使用组合式 API,我们的初心至今没有改变。除了**安装**和 **SSR** 两章之外,其余章节中提到的 API 均支持 Vue 2 和 Vue 3。虽然本文档主要是面向 Vue 3 的用户,但在必要时会标注出 Vue 2 的内容,因此 Vue 2 和 Vue 3 的用户都可以阅读本文档。
index d12d4fe0f23cfd8e3b43aba45b1c8971de0bd667..83d80e46a9b76f04fa7ce8b55399b1e364d91828 100644 (file)
@@ -1,5 +1,10 @@
 # 服务端渲染 (SSR) %{#server-side-rendering-ssr}%
 
+<MasteringPiniaLink
+  href="https://masteringpinia.com/lessons/ssr-friendly-state"
+  title="Learn about SSR best practices"
+/>
+
 :::tip
 如果你使用的是 **Nuxt.js**,你需要阅读的是[**这些说明文档**](./nuxt.md)。
 :::
index 9c5a7e4095842c567539b27f6e67e4ac91c4d292..7de0e91c7bdd53a4d376a86f175d28ff65057354 100644 (file)
@@ -1,5 +1,10 @@
 # Nuxt.js %{#nuxt-js}%
 
+<MasteringPiniaLink
+  href="https://masteringpinia.com/lessons/ssr-friendly-state"
+  title="Learn about SSR best practices"
+/>
+
 搭配 [Nuxt](https://nuxt.com/) 的 Pinia 更易用,因为 Nuxt 处理了很多与**服务器端渲染**有关的事情。例如,**你不需要关心序列化或 XSS 攻击**。Pinia 既支持 Nuxt Bridge 和 Nuxt 3,也支持纯 Nuxt 2,[见下文](#nuxt-2-without-bridge)。
 
 ## 安装 %{#installation}%