Skip to content

Commit e2ef9f6

Browse files
tmorehousejacobmllr95
authored andcommitted
chore(docs): minor docs updates (closes bootstrap-vue#3262) (bootstrap-vue#3263)
* chore(docs): minor docs updates * Update README.md * Update warn.js * add warn to $bvToast when not accessing through `this.$bvToast` * Update bv-modal.js * Update bv-toast.js * Update bv-toast.js * Update bv-modal.js
1 parent 10d4c4d commit e2ef9f6

File tree

5 files changed

+31
-12
lines changed

5 files changed

+31
-12
lines changed

src/components/modal/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,11 @@ Example Confirm Message boxes
880880
method to generate VNodes. This can also be done for the modal title (by passing VNodes to the
881881
`title` option), OK button text (via the `okTitle` option), and the CANCEL button text (via the
882882
`cancelTitle` option).
883+
- The `this.$bvModal` injection is only available when using the full BootstrapVue plugin or the
884+
Modal plugin. It is not available if importing just the `b-modal` component.
885+
- A new `$bvModal` injection (mixin) is created for each Vue virtual machine (i.e. each instantiated
886+
component), and is not usable via direct access to the `Vue.prototype`, as it needs access to the
887+
instance's `this` and `$root` contexts.
883888

884889
## Listening to modal changes via \$root events
885890

src/components/modal/helpers/bv-modal.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ import {
1515
defineProperties,
1616
readonlyDescriptor
1717
} from '../../../utils/object'
18-
import { warnNotClient, warnNoPromiseSupport } from '../../../utils/warn'
18+
import { warn, warnNotClient, warnNoPromiseSupport } from '../../../utils/warn'
1919

2020
// --- Constants ---
2121

2222
const PROP_NAME = '$bvModal'
23+
const PROP_NAME_PRIV = '_bv__modal'
2324

2425
// Base modal props that are allowed
2526
// Some may be ignored or overridden on some message boxes
@@ -269,7 +270,7 @@ const install = _Vue => {
269270
beforeCreate() {
270271
// Because we need access to `$root` for `$emits`, and VM for parenting,
271272
// we have to create a fresh instance of `BvModal` for each VM
272-
this._bv__modal = new BvModal(this)
273+
this[PROP_NAME_PRIV] = new BvModal(this)
273274
}
274275
})
275276

@@ -278,7 +279,11 @@ const install = _Vue => {
278279
if (!_Vue.prototype.hasOwnProperty(PROP_NAME)) {
279280
defineProperty(_Vue.prototype, PROP_NAME, {
280281
get() {
281-
return this._bv__modal
282+
/* istanbul ignore next */
283+
if (!this || !this[PROP_NAME_PRIV]) {
284+
warn(`'${PROP_NAME}' must be accessed from a Vue instance 'this' context`)
285+
}
286+
return this[PROP_NAME_PRIV]
282287
}
283288
})
284289
}

src/components/toast/README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ BootstrapVue uses [PortalVue](https://portal-vue.linusb.org/) to transport toast
7272

7373
## Toasts on demand
7474

75-
Generate a dynamic toast from anywhere in your app via the `this.$bvToast` Vue instance injection,
76-
without the need to place a [`<b-toast>`](#b-toast-component) component in your app.
75+
Generate a dynamic toast from anywhere in your app via the `this.$bvToast` Vue component _instance_
76+
injection, without the need to place a [`<b-toast>`](#b-toast-component) component in your app.
7777

7878
Use the `this.$bvToast.toast()` method to generate on demand toasts. The method accepts two
7979
arguments:
@@ -120,9 +120,13 @@ exception of `static`, and `visible`) in <samp>camelCase</samp> name format inst
120120
Once a toast which was generated using `this.$bvToast.toast()` has been hidden, it will
121121
automatically be destroyed and removed from the document.
122122

123-
**Note:** The `this.$bvToast` injection is only available when useing the full `BootstrapVue`
124-
plugin or the `Toast` plugin. It is not available if importing just the `b-toast` or `b-toaster`
125-
components.
123+
**Notes:**
124+
125+
- The `this.$bvToast` injection is only available when using the full `BootstrapVue` plugin or the
126+
`Toast` plugin. It is not available if importing just the `b-toast` or `b-toaster` components.
127+
- A new `$bvToast` injection (mixin) is created for each Vue virtual machine (i.e. each instantiated
128+
component), and is not usable via direct access to the `Vue.prototype`, as it needs access to the
129+
instance's `this` and `$root` contexts.
126130

127131
## Options
128132

src/components/toast/helpers/bv-toast.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ import {
1515
omit,
1616
readonlyDescriptor
1717
} from '../../../utils/object'
18-
import { warnNotClient } from '../../../utils/warn'
18+
import { warn, warnNotClient } from '../../../utils/warn'
1919
import BToast, { props as toastProps } from '../toast'
2020

2121
// --- Constants ---
2222

2323
const PROP_NAME = '$bvToast'
24+
const PROP_NAME_PRIV = '_bv__toast'
2425

2526
// Base toast props that are allowed
2627
// Some may be ignored or overridden on some message boxes
@@ -194,7 +195,7 @@ const install = _Vue => {
194195
beforeCreate() {
195196
// Because we need access to `$root` for `$emits`, and VM for parenting,
196197
// we have to create a fresh instance of `BvToast` for each VM
197-
this._bv__toast = new BvToast(this)
198+
this[PROP_NAME_PRIV] = new BvToast(this)
198199
}
199200
})
200201

@@ -203,7 +204,11 @@ const install = _Vue => {
203204
if (!_Vue.prototype.hasOwnProperty(PROP_NAME)) {
204205
defineProperty(_Vue.prototype, PROP_NAME, {
205206
get() {
206-
return this._bv__toast
207+
/* istanbul ignore next */
208+
if (!this || !this[PROP_NAME_PRIV]) {
209+
warn(`'${PROP_NAME}' must be accessed from a Vue instance 'this' context`)
210+
}
211+
return this[PROP_NAME_PRIV]
207212
}
208213
})
209214
}

src/utils/warn.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { isBrowser, hasPromiseSupport, hasMutationObserverSupport, getNoWarn } f
44
* Log a warning message to the console with BootstrapVue formatting
55
* @param {string} message
66
*/
7-
const warn = message => /* istanbul ignore next */ {
7+
export const warn = message => /* istanbul ignore next */ {
88
if (!getNoWarn()) {
99
console.warn(`[BootstrapVue warn]: ${message}`)
1010
}

0 commit comments

Comments
 (0)