From d75e55f003562e0243e6cc870960daf367fdc1fe Mon Sep 17 00:00:00 2001 From: Dan Popescu Date: Tue, 8 Aug 2017 11:12:45 +0300 Subject: [PATCH 1/3] close #6097: Allow defining optional inject dependency with default values Document changes in inject definition for feature #6097 --- src/v2/api/index.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/v2/api/index.md b/src/v2/api/index.md index bc9502b7e4..ed8d48a161 100644 --- a/src/v2/api/index.md +++ b/src/v2/api/index.md @@ -932,7 +932,7 @@ if (version === 2) { - **Type:** - **provide:** `Object | () => Object` - - **inject:** `Array | { [key: string]: string | Symbol }` + - **inject:** `Array | { [key: string]: string | Symbol | { name?: string | Symbol, default?: any } }` - **Details:** @@ -942,7 +942,8 @@ if (version === 2) { The `provide` option should be an object or a function that returns an object. This object contains the properties that are available for injection into its descendants. You can use ES2015 Symbols as keys in this object, but only in environments that natively support `Symbol` and `Reflect.ownKeys`. - The `inject` options should be either an Array of strings or an object where the keys stand for the local binding name, and the value being the key (string or Symbol) to search for in available injections. + The `inject` options should be either an Array of strings or an object where the keys stand for the local binding name, and the value is either the key (string or Symbol) to search for in available injections or an object where the `name` property is the key (string or Symbol) to search for in + available injections and the `default` property is used as fallback value. > Note: the `provide` and `inject` bindings are NOT reactive. This is intentional. However, if you pass down an observed object, properties on that object do remain reactive. From 608b120b447e21ee07d062ff55d33c8480b02b13 Mon Sep 17 00:00:00 2001 From: Chris Fritz Date: Wed, 9 Aug 2017 18:26:23 -0400 Subject: [PATCH 2/3] reformatted description of inject options --- src/v2/api/index.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/v2/api/index.md b/src/v2/api/index.md index ed8d48a161..338a343670 100644 --- a/src/v2/api/index.md +++ b/src/v2/api/index.md @@ -932,7 +932,7 @@ if (version === 2) { - **Type:** - **provide:** `Object | () => Object` - - **inject:** `Array | { [key: string]: string | Symbol | { name?: string | Symbol, default?: any } }` + - **inject:** `Array | Object` - **Details:** @@ -942,8 +942,13 @@ if (version === 2) { The `provide` option should be an object or a function that returns an object. This object contains the properties that are available for injection into its descendants. You can use ES2015 Symbols as keys in this object, but only in environments that natively support `Symbol` and `Reflect.ownKeys`. - The `inject` options should be either an Array of strings or an object where the keys stand for the local binding name, and the value is either the key (string or Symbol) to search for in available injections or an object where the `name` property is the key (string or Symbol) to search for in - available injections and the `default` property is used as fallback value. + The `inject` option should be either: + - An array of strings, or + - An object where the keys stand for the local binding name, and the value is either: + - the key (string or Symbol) to search for in available injections, or + - an object where: + - the `name` property is the key (string or Symbol) to search for in available injections, and + - the `default` property is used as fallback value > Note: the `provide` and `inject` bindings are NOT reactive. This is intentional. However, if you pass down an observed object, properties on that object do remain reactive. From 2600ab65d8300a003ba2c36316b4220938c49bda Mon Sep 17 00:00:00 2001 From: Chris Fritz Date: Wed, 9 Aug 2017 18:28:15 -0400 Subject: [PATCH 3/3] further clarification of inject options description --- src/v2/api/index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/v2/api/index.md b/src/v2/api/index.md index 338a343670..4c631601ef 100644 --- a/src/v2/api/index.md +++ b/src/v2/api/index.md @@ -943,8 +943,8 @@ if (version === 2) { The `provide` option should be an object or a function that returns an object. This object contains the properties that are available for injection into its descendants. You can use ES2015 Symbols as keys in this object, but only in environments that natively support `Symbol` and `Reflect.ownKeys`. The `inject` option should be either: - - An array of strings, or - - An object where the keys stand for the local binding name, and the value is either: + - an array of strings, or + - an object where the keys are the local binding name and the value is either: - the key (string or Symbol) to search for in available injections, or - an object where: - the `name` property is the key (string or Symbol) to search for in available injections, and