question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using window.store when creating a story

See original GitHub issue

Describe the bug When creating a story I am trying to use the window.store as the store (I include a script in preview-head.html which sets up window.store so it does exist in the iframe).

Basically I am working on a site that uses decoupled vue components built as libraries which communicate data through a global vuex store on the window, unfortunately this prevents mapActions working with storybook because the context of this.$store is wrong.

I have tried the following based of this issue and also this post:

storiesOf("Some component", module)
    .add("using global store", () => ({
        components: {
            ModuleName
        },
        template: "<module-name />",
        store: window.store
    }));

Unfortunately the context of window is wrong at this point, I also tried setting up the store in the config file with Vue.use(Vuex) but because I register the modules dynamically I couldn’t get this to work either as I register them against window.store when the module is loaded with the following script:

export default async (identifier, storeModule) => {
    const store = window.store;
    const exists = store.state[identifier];
    if (!window.components.registeredModules.includes(identifier)) {
        storeModule.namespaced = true;
        store.registerModule(identifier, storeModule, {
            preserveState: exists
        });
        window.components.registeredModules.push(identifier);
    }
};

To Reproduce Steps to reproduce the behavior:

  1. Try to use store: window.store when creating a story.
  2. Serve storybook.
  3. See context is wrong.

Expected behavior To be able to reference objects on the iframe window.

System:

  • OS: Ubuntu 18.10
  • Device: Desktop
  • Browser: Chrome
  • Framework: Vue
  • Version: 5.0.11

Additional context I am building the decoupled components as outlined here.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:21 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
backbone87commented, Jul 9, 2019

you could try the following decorator:

function waitForStore() {
  return () => ({
    data() {
      return { store: null };
    },
    async created() {
      this.store = await GET_WINDOW_STORE();
    },
    render(h) {
      if(!this.store) {
        return h('span', 'Waiting for store...');
      }

      return h('story', { store: this.store }); // this may not work, then try the following
      return h({ components: { story: this.$options.components.story }, template: '<story></story>', store: this.store });
    }
  })
}

storiesOf(...).addDecorator(waitForStore()).add(...);
0reactions
chopfitzroycommented, Sep 11, 2019

Hey @anipendakur,

No there is currently no new issue as I have not had time to revisit this, feel free to open a new issue and reference this one.

Cheers!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to tell a story with your store windows – Retail Design Blog
Creating a “story ” with your displays does not really mean making a visual that has a beginning, middle and end. What it...
Read more >
Window displays: weaving stories that enchant, attract and ...
An effective window display is not only about showcasing the products that a store sells, but also about weaving together various elements – ......
Read more >
Story : Windows Store - YouTube
Story is a powerful app with a very simple interface to create a slideshow video of your pictures.If you love pictures and want...
Read more >
Narrative Writer - Microsoft Apps
Download this easy-to-use text editor and write your story! Sign in for a free 14 day trial, then opt to subscribe for just...
Read more >
Bringing Minecraft: Story Mode to the Universal Windows ...
In December of 2015, Telltale Games brought Minecraft: Story Mode to the Windows Store. To make this possible, Telltale Games ported their ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found