martyjs / marty

A Javascript library for state management in React applications
http://martyjs.org
MIT License
1.09k stars 76 forks source link

Trying to listen to something that isn't a store #233

Closed sporto closed 9 years ago

sporto commented 9 years ago

I'm using ES6 and declaring my store like:

export default class LibrariesStore extends Marty.Store {
  ...
}

Then in my component I import the store and try to use it in a container:

import librariesStore from '../../stores/libraries.es6';

export default Marty.createContainer(Main, {
  listenTo: librariesStore,
  ...
})

In the browser I see:

Warning: Trying to listen to something that isn't a store" function LibrariesStore()

So I see I'm importing the LibrariesStore class. But there is no instance created anywhere. So something seems to be missing here, where is the store instance supposed to be instantiated?

sporto commented 9 years ago

Oh, found this http://martyjs.org/guides/es6/index.html Closing

SudoPlz commented 9 years ago

The link is dead and I have the same problem... What is the solution? (Note I don't use es6)

sporto commented 9 years ago

Back in Marty 0.9 you had to register stores before using them:

 class LibrariesStore extends Marty.Store {
  ...
}

export default Marty.register(LibrariesStore)

Then

import librariesStore from '../../stores/libraries.es6';

export default Marty.createContainer(Main, {
  listenTo: librariesStore,
  ...
})

But Marty 0.10 is quite different

SudoPlz commented 9 years ago

Thank you... What I was doing wrong is, I had listenTo: "librariesStore", (string) in my code instead of listenTo: librariesStore, (object). I thought that Marty kept track of our stores and I just had to provide its name (the one I set as its id). I was wrong... Now all seems to work.