0

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

4

3 回答 3

1

Mixin.es6对我来说似乎是一个错字。

更改getStategetInitialState

此外,在Component.es6

更改mixins: StateMixinmixins: [StateMixin]

于 2015-02-09T07:12:10.547 回答
0

问题最终是包含 JavaScript 文件的顺序不正确。交换一些解决了这个问题。

于 2015-02-20T15:31:47.280 回答
0

你在用反应 v0.1.13.0

这是使用“构造”初始化状态的新方法

constructor(props) {
    super(props);
    this.state = {count: props.initialCount};
  }

https://facebook.github.io/react/blog/2015/01/27/react-v0.13.0-beta-1.html

于 2016-01-31T04:15:57.210 回答