From d92a4b9a5a66d51747eda54f1391cd6ea744d190 Mon Sep 17 00:00:00 2001 From: Natalia Tepluhina Date: Sun, 8 Aug 2021 14:09:16 +0300 Subject: [PATCH 1/9] Extended watching multiple sources explanation (#1156) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: added example for watching multiple sources * feat: added nextTick example * fix: reverted formatting * Update src/guide/reactivity-computed-watchers.md Co-authored-by: Thorsten Lünborg * Update src/guide/reactivity-computed-watchers.md Co-authored-by: skirtle <65301168+skirtles-code@users.noreply.github.com> * Update src/guide/reactivity-computed-watchers.md Co-authored-by: skirtle <65301168+skirtles-code@users.noreply.github.com> Co-authored-by: Thorsten Lünborg Co-authored-by: skirtle <65301168+skirtles-code@users.noreply.github.com> --- src/guide/reactivity-computed-watchers.md | 57 ++++++++++++++++++----- 1 file changed, 46 insertions(+), 11 deletions(-) diff --git a/src/guide/reactivity-computed-watchers.md b/src/guide/reactivity-computed-watchers.md index fb68e6c6..0efa04f0 100644 --- a/src/guide/reactivity-computed-watchers.md +++ b/src/guide/reactivity-computed-watchers.md @@ -83,8 +83,10 @@ watchEffect(onInvalidate => { ```js const data = ref(null) -watchEffect(async (onInvalidate) => { - onInvalidate(() => {/* ... */}) // Promise の解決前にクリーンアップする関数を登録 +watchEffect(async onInvalidate => { + onInvalidate(() => { + /* ... */ + }) // Promise の解決前にクリーンアップする関数を登録 data.value = await fetchData(props.id) }) ``` @@ -101,19 +103,19 @@ Vue のリアクティブシステムは、無効になった変更をバッフ ``` @@ -211,6 +213,39 @@ firstName.value = 'John' // logs: ["John", ""] ["", ""] lastName.value = 'Smith' // logs: ["John", "Smith"] ["John", ""] ``` +However, if you are changing both watched sources simultaneously in the same method, the watcher will be executed only once: + +```js{9-13} +setup() { + const firstName = ref('') + const lastName = ref('') + + watch([firstName, lastName], (newValues, prevValues) => { + console.log(newValues, prevValues) + }) + + const changeValues = () => { + firstName.value = 'John' + lastName.value = 'Smith' + // logs: ["John", "Smith"] ["", ""] + } + + return { changeValues } +} +``` + +Note that multiple synchronous changes will only trigger the watcher once. + +It is possible to force the watcher to trigger after every change by using the setting `flush: 'sync'`, though that isn't usually recommended. Alternatively, [nextTick](/api/global-api.html#nexttick) can be used to wait for the watcher to run before making further changes. e.g.: + +```js +const changeValues = async () => { + firstName.value = 'John' // logs: ["John", ""] ["", ""] + await nextTick() + lastName.value = 'Smith' // logs: ["John", "Smith"] ["John", ""] +} +``` + ### リアクティブなオブジェクトの監視 ウォッチャを使って、リアクティブな配列やオブジェクトの値を比較するには、値だけのコピーを作っておく必要があります。 From e4326ec318912c9dab80be802aa0420177245bd4 Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 9 Aug 2021 15:54:34 -0400 Subject: [PATCH 2/9] 3.2 updates (#1157) --- src/.vuepress/config.js | 51 +++- src/api/computed-watch-api.md | 35 ++- src/api/directives.md | 84 +++++-- src/api/effect-scope.md | 59 +++++ src/api/global-api.md | 64 ++++- src/api/reactivity-api.md | 1 + src/api/sfc-script-setup.md | 292 ++++++++++++++++++++++ src/api/sfc-spec.md | 139 ++++++++++ src/api/sfc-style.md | 205 +++++++++++++++ src/api/sfc-tooling.md | 94 +++++++ src/guide/introduction.md | 12 +- src/guide/reactivity-computed-watchers.md | 49 ++-- src/guide/single-file-component.md | 196 ++++----------- src/guide/typescript-support.md | 2 +- src/guide/web-components.md | 243 ++++++++++++++++++ 15 files changed, 1327 insertions(+), 199 deletions(-) create mode 100644 src/api/effect-scope.md create mode 100644 src/api/sfc-script-setup.md create mode 100644 src/api/sfc-spec.md create mode 100644 src/api/sfc-style.md create mode 100644 src/api/sfc-tooling.md create mode 100644 src/guide/web-components.md diff --git a/src/.vuepress/config.js b/src/.vuepress/config.js index 2a756af2..67e2b171 100644 --- a/src/.vuepress/config.js +++ b/src/.vuepress/config.js @@ -80,6 +80,7 @@ const sidebar = { title: '高度な使い方', collapsable: false, children: [ + '/guide/web-components', { title: 'リアクティビティ', children: [ @@ -106,7 +107,12 @@ const sidebar = { { title: 'スケールアップ', collapsable: false, - children: ['/guide/routing', '/guide/state-management', '/guide/ssr', '/guide/security'] + children: [ + '/guide/routing', + '/guide/state-management', + '/guide/ssr', + '/guide/security' + ] }, { title: 'アクセシビリティ', @@ -148,10 +154,33 @@ const sidebar = { children: [ '/api/basic-reactivity', '/api/refs-api', - '/api/computed-watch-api' + '/api/computed-watch-api', + '/api/effect-scope', ] }, - '/api/composition-api' + '/api/composition-api', + { + title: 'Single File Components', + collapsable: false, + children: [ + { + title: 'Spec', + path: '/api/sfc-spec' + }, + { + title: 'Tooling', + path: '/api/sfc-tooling' + }, + { + title: ' @@ -521,7 +567,7 @@ export default { ``` -CSS モジュールの使い方について詳しくは、 [Vue Loader - CSS Modules](https://vue-loader.vuejs.org/guide/css-modules.html) を参照してください。 +CSS モジュールの使い方について詳しくは、[SFC Style Features: ` + + + This could be e.g. documentation for the component. + +``` + +## Language Blocks + +### `