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

Props are handled too simply #77

Open
lsphillips opened this issue Jun 13, 2021 · 1 comment
Open

Props are handled too simply #77

lsphillips opened this issue Jun 13, 2021 · 1 comment

Comments

@lsphillips
Copy link

lsphillips commented Jun 13, 2021

Currently this plugin takes the props and just makes them data of the root component, this is fine, but a bit simple for my needs. As an example, I use the props to deliver functional objects to the micro frontend that hide implementation detail of the shell e.g. a logger or an identity provider.

These function objects don't change and have no need to be reactive. Furthermore in Vue 3, due to how reactivity works, objects with methods on its prototype simply just break. It makes more sense for objects like these to be provided as props, or better yet as injectables (using provide).

Is it possible that we can introduce a new option for complex cases like these, e.g.

singleSpaVue({
    handleProps (props)
    {
        return {
            provide () {
                 return {
                     logger : props.logger
                 };
            },
            data () {
                return {
                    locale : props.locale
                };
            }
        };
    }
})

The plugin will take the result of this function and simply merge it into the application options that will be passed into Vue. If a handleProps function is not provided it will behave as normal.

The update lifecycle method would need to be a little smarter too by using vm.$data to derive the data keys that are actually reactive and only update those.

I'm happy to submit a PR, I just wanted my thought process to be validated before I dive into the code.

@joeldenning
Copy link
Member

joeldenning commented Jun 17, 2021

Hi @lsphillips, I'm open to this change, as I don't see a reason to forbid transformation/processing of the single-spa props. The handleProps name matches the pattern set by handleInstance, which is good. I am happy to review a PR implementing it. Please submit a documentation PR for it, as well. The file to modify for the documentation is https://github.com/single-spa/single-spa.js.org/blob/master/website/versioned_docs/version-5.x/ecosystem-vue.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants