React Reflux Store state 값 가져오기 Data Flow

// Component
class Plans extends React.Component {
  constructor(props){
    super(props);
    this.state = {
      params: props.params
    };
  }

  render() {
    return (
      <div className="plan-list-container">
        <PlanList { ...this.state } />
      </div>
    );
  }

}

 
// PlanList Component
class PlanList extends React.Component {

  constructor(props){
    super(props);

    this.state = {
      page_loading: false
    };

    PlanActions.setParams(props.params);
  }

 
// PlanActions
var PlanActions = Reflux.createActions([
  'setParams',
  'loadPlans',
  'loadPlansSuccess'
]);

PlanActions.loadPlans.preEmit = function(){
  PlanActions.loadPlansSuccess();
};

 
// Store
var PlanStore = Reflux.createStore({
  init() {
    this.listenToMany(PlanActions);
  },

  setParams(params) {
    this.params = params;
  },

  loadPlans() {
    this.trigger({ 
      loading: true
    });
  },

  loadPlansSuccess() {
    $.ajax({
        url: this.ajaxApi,
        dataType: 'json',
        data: {
          sku: this.params.sku
        },
        cache: true,
        success: function(data) {

좋은 웹페이지 즐겨찾기