Search code examples
javascriptreactjsmartyjs

State null in component


I'm having an issue with creating a component using react and martyjs. I'm sure it is a typo or something but I just can't seem to find it. Although I have a state mixin in the component the state is not being populated and it doesn't look like getState is even being called in the mixin.

Mixin.es6

var StateMixin = Marty.createStateMixin({
  listenTo: VideoStore,
  getState: function() {
    return {
      items: VideoStore.list(),
      currentItem: VideoStore.select(),
    }
  }
});

State.es6

var VideoStore = Marty.createStore({
  displayName: "Store",
  handlers: {
    list: Events.List,
    render: Events.Render
  },
  getInitialState: function(){
    return {  };
  },
  list: function(){
    return this.fetch({
      id: 'list',
      locally: function(){
        if(this.hasAlreadyFetched('list') )
          return this.state.items;
      },
      remotely: function(){
        return  DissolveStateSource.list();
      }
    });
  },
  select: function(){},
  render: function(){}
});

Component.es6

$( ()=>
React.render(
  <VideosTable/>,
  $("#container")[0]
));

var VideosTable = React.createClass(
{
  mixins: StateMixin,
  render: function() {
    var body = this.state.list.when({  //state is null here
      pending: function(){
        return <span className="ball"></span>;
      },
      failed: function(error){
        return <div className="error">error.message</div>;
      },
      done: function(videos){
        return <div>Videos</div>;
      }
    });

    return <h2>hello</h2>;
  }
});

Any idea what I'm doing wrong?

Edit: I've added a js bin thing here

http://jsbin.com/lekegicumo/2/edit?html,js,console,output


Solution

  • The problem ended up being that the order of inclusion of JavaScript files was incorrect. Swapping some around fixed the issue.