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

Store.registerModule({name: module}) module does not persist #1649

Closed
mjmnagy opened this issue Nov 20, 2019 · 2 comments
Closed

Store.registerModule({name: module}) module does not persist #1649

mjmnagy opened this issue Nov 20, 2019 · 2 comments

Comments

@mjmnagy
Copy link

@mjmnagy mjmnagy commented Nov 20, 2019

I am trying to make a component library that will be shared across several apps. Each app is internal to a larger global app and has their own domain.

hub.website.com

app.website.com

The component library uses Vuex to allow users to change their preferences(Ex: want to increase the button size or change it's color).

In my components library project i created the index.js file which is the main file

 //index.js
import * as vsComponents from './components'        // imports all the components
import storeModule from './store/components'        //Imports the store module which is mentioned below

const install = (Vue, options = {}) => {
      if (!options.store) {                             //Must pass the store from the larger component
    throw new Error('Please provide vuex store.')
  }

  //Register Store modules
  options.store.registerModule('components', storeModule) //Registers the module into the larger store

  // Use Components
  Object.values(vsComponents).forEach(vsComponent => { //Creates the components for vue to use
        Vue.use(vsComponent)
  })
}

if (typeof window !== 'undefined' && window.Vue) {    //No 100% sure i need this ??? - i would like it ssr so im thinking its not required (any help here would be awesome too)
      install(window.Vue)
}

export default install

export * from './components/index'                 //Allows you to individually import each component

I use the following command to create the component library and upload it to bitbucket "scripts":{"production": "vue-cli-service build --target lib --name sc src/index.js"} in which src/index.js is the file with the code pasted above.

In my nuxt application, i

  1. npm i bitbucket project
  2. Create a file components.js in the plugin folder
  3. Add the file to nuxt.config.js - i have played around with the ssr true/false

Here my components.js file

import components from 'components'         //Component library
import Vue from 'vue'

export default context => {
  Vue.use(components, { store: context.store })
}

The Funny part

On the initial load of the page, i can see the added state from the components library

<pre> {{ this.$store.state.components }} </pre>

When i refresh the page, the added state is now gone?!?!?!

TLDR Basically, i am importing a component lirbary as a plugin within nuxt. On the initial load, the plugin works as expect by injecting it's vuex module parameters into the nuxt's store. Upon subsequent loads, the vuex module is gone???

Essentially, all im trying to do is have the a basic store module held within the components library. This would keep everything consistent between apps and then add the module to the larger app store and be able to utilize/use it

@vue-bot

This comment has been minimized.

Copy link

@vue-bot vue-bot commented Nov 20, 2019

Hello, thank you for taking time filling this issue!

However, we kindly ask you to use our Issue Helper when creating new issues, in order to ensure every issue provides the necessary information for us to investigate. This explains why your issue has been automatically closed by me (your robot friend!).

I hope to see your helper-created issue very soon!

@vue-bot vue-bot closed this Nov 20, 2019
@mjmnagy

This comment has been minimized.

Copy link
Author

@mjmnagy mjmnagy commented Nov 20, 2019

stupid fucking @vue-bot

@mjmnagy mjmnagy changed the title Store module disappears Store.registerModule({name: module}) module does not persist Nov 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.