martyjs / marty

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

Problem with registration #349

Open ciaoben opened 9 years ago

ciaoben commented 9 years ago

Hi, I am upgrading to 0.10 and I have a problem with registration:

my Application js:

var Application = Marty.createApplication(function () {
  this.register(require('./stores'));
  this.register(require('./actions'));
  this.register(require('./queries'));
  this.register(require('./sources'));
  this.router = require('./router');
});

my ./queries index.js:

module.exports = {
  appQueries: require('./appQueries'),
  settingsQueries: require('./settingsQueries')
};

But in my store:

module.exports = Marty.createStore({
  id: 'AppStore',
  handlers: {
    login: AppConstants.LOGIN,
    logout: AppConstants.LOGOUT,
    redirect_to_login: AppConstants.REDIRECT_TO_LOGIN,
    isLogged: AppConstants.IS_LOGGED,
  },
  getInitialState: function () {
    //AppQueries.isLogged();
    console.log("state test", this.app.appQueries.method());
  },
...

The console.log gives me "TypeError: Cannot read property 'method' of undefined".

What I am missing?

jhollingworth commented 9 years ago

So on the surface that looks fine. Could you do a console.log(Object.keys(this.app)) to see what is registered?

ciaoben commented 9 years ago

@jhollingworth

Here is the output:

["__isApplication", "__isCoreType", "__types", "req", "res"]

But if I print console.log(this.app); and inspect it with the Chrome dev tools:

oggi

jhollingworth commented 9 years ago

thats a bit spooky, and console.log(this.app.appQueries) returns undefined?

ciaoben commented 9 years ago

@jhollingworth yes

ciaoben commented 9 years ago

@jhollingworth

Here is my code, hope you can help me because I am stuck!

https://github.com/ciaoben/temp_debugging

I am upgrading from previous version, so there is a bit of mess, but the core should be fine!

ciaoben commented 9 years ago

@jhollingworth I've tried to put a console.log in my index.js, to see if it is executed before my store, but apparently it is not. What could it be? How can I force my index.js to execute first. I am using browserify

EDIT

It is definitevely this. I have put a console.log in my store's getInitialState, and one in the the index.js where I instantiate the app, and the the one in the store it is executed first.

But I cannot get, where is my mistake???