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

Not seeing actions for MST Store #3

Open
NgoKnows opened this issue Oct 26, 2017 · 12 comments
Open

Not seeing actions for MST Store #3

NgoKnows opened this issue Oct 26, 2017 · 12 comments

Comments

@NgoKnows
Copy link

Under the actions pane, I'm seeing This observable does not have any actions associated. These are all singleton MST stores, so they are already instantiated. All of the stores are showing up as expected, just missing actions.

Let me know if I am missing anything.

import UiStore from 'stores/UiStore';
import NavigationStore from 'stores/NavigationStore';
import ReceivingStore from 'routes/receiving/ReceivingStore';
import CarriesStore from 'routes/carries/CarriesStore';

const { wiretap, inspect } = require('mobx-wiretap/mst');

wiretap('My App');

inspect('UiStore', UiStore);
inspect('NavigationStore', NavigationStore);
inspect('ReceivingStore', ReceivingStore);
inspect('CarriesStore', CarriesStore);
@Raathigesh
Copy link
Owner

This looks fine. Would you please be able to share a sample repo or may be some insight into how the store is structured ?

This is how wiretap detects the actions. https://github.com/Raathigesh/wiretap/blob/master/packages/lib/src/mobxStateTreeTracker.js#L95-L97

I'll also try to replicate the issue.

@NgoKnows
Copy link
Author

Here is what one of the stores looks like

import { types } from 'mobx-state-tree';
import debounce from 'lodash-es/debounce';

export const UiStore = types
  .model('UiStore', {
    windowDimensions: types.optional(
      types.model('WindowDimensions', {
        height: types.number,
        width: types.number
      }),
      {
        height: window.innerHeight,
        width: window.innerWidth
      }
    ),
    scrollPosition: window.scrollY
  })
  .views(self => ({
    get isMobileLayout() {
      return self.windowDimensions.width < 900;
    },

    get isDesktopLayout() {
      return self.windowDimensions.width >= 900;
    }
  }))
  .actions(self => ({
    setWindowDimensions() {
      self.windowDimensions = {
        height: window.innerHeight,
        width: window.innerWidth
      };
    },
    setScrollPosition() {
      self.scrollPosition = window.scrollY;
    }
  }))
  .actions(self => ({
    afterCreate() {
      window.addEventListener('resize', debounce(() => self.setWindowDimensions(), 100));
      window.addEventListener('scroll', debounce(() => self.setScrollPosition(), 150));
    }
  }));

// export as singleton
export default UiStore.create();

@NgoKnows
Copy link
Author

I'll try digging into it as well when I have a chance.

@Raathigesh
Copy link
Owner

The store looks fine and it should be working. I'll look into it as well. Would you be able to provide the MST version as well please?

@wbercx
Copy link

wbercx commented Oct 27, 2017

All I can find so far is that my action does not have a isMobxAction property, which is what isAction() is looking for.

@Raathigesh
Copy link
Owner

Raathigesh commented Oct 27, 2017 via email

@Raathigesh
Copy link
Owner

As it turns out isMobxAction() will not work consistently across all the versions. So there is not yet a proper way to identify the associated action of a model. MST does not provide a public API. I can think of an API for wiretap where the user provides the invocable actions as a string array.

inspect("Todo", todo, ['addTodo']);

This is not pretty and I really don't like to do this but it gets the job done.

Looking forward to your feedback on an api like this.

@Raathigesh
Copy link
Owner

With [email protected], you could pass in the actions manually as a third parameter to the inspect() method

inspect("Todo", todo, ['addTodo']);

This is a temporary workaround until there is a proper way to detect actions in MST.

@robinfehr
Copy link
Collaborator

mobx-state-tree now does expose a getMembers method that could be used to fix that.

@HaveF
Copy link

HaveF commented Jul 24, 2018

Here I provide a repo based on mweststrate's MST course

https://github.com/HaveF/wiretap-issue

image

@silouanwright
Copy link

I may also be getting this issue. All I see with MST, is the initial shape of the store data... but it doesn't update when actions are fired or anything.

@Raathigesh
Copy link
Owner

I'm no longer maintaining wiretap. Probably I should update the readme to reflect that. If you are interested in taking over the project, please do let me know.

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

6 participants