Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat): Allow sharing of main app's context with toast app #290

Merged
merged 2 commits into from
Oct 18, 2021

Conversation

Maronato
Copy link
Owner

Description

When registering the plugin, it creates a new app instance wherein the toasts are created. That decouples your app's instance from the plugin's components and enables you to create instances in other contexts besides app.use.

However, as a consequence of this independence, the contexts of Vue Toastification's app and the main app are not shared, so it is not possible to access things like the following from within custom toast components:

  • global components such as RouterLink, NuxtLink, etc
  • global state and properties
  • custom directives
  • custom mixins
  • data from other plugins

This PR creates an opt-in fix for that, through a new plugin option shareAppContext that overrides the default toast context with the main app's.

More specifically, it overrides the following properties:

  • app._context.components
  • app._context.directives
  • app._context.mixins
  • app._context.provides
  • app.config.globalProperties

These should be enough for the majority of use cases. If it isn't, tweak it using the solution proposed in #162 (comment)

To enable the feature, do:

app.use(Toast, {
  shareAppContext: true,
})

Related Issue

#162

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@Maronato Maronato added the Type: Enhancement New feature or request label Oct 18, 2021
@codecov
Copy link

codecov bot commented Oct 18, 2021

Codecov Report

Merging #290 (bf64408) into next (e82c89b) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              next      #290   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           16        16           
  Lines          481       492   +11     
  Branches        98       101    +3     
=========================================
+ Hits           481       492   +11     
Impacted Files Coverage Δ
src/ts/propValidators.ts 100.00% <ø> (ø)
src/index.ts 100.00% <100.00%> (ø)
src/ts/interface.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e82c89b...bf64408. Read the comment docs.

src/ts/interface.ts Outdated Show resolved Hide resolved
@Maronato Maronato merged commit 736c2ba into next Oct 18, 2021
@Maronato Maronato deleted the shareAppContext branch October 18, 2021 20:43
@mrleblanc101
Copy link

Can we merge this in v1 too ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants