Refactoring Aim List – Many to Many – Store



Refactoring Aim List – Many to Many – Store

0 0


CubeEmpty


On Github Potato2009 / CubeEmpty

Refactoring Aim List

Separate the Model from the View Add State to the Page Make Component more easily to Use

Many to Many

One View bind Many Model Different View depend on One Model One View depend on Different State of One Model

The First Argument -- Pull Data or Driven by Data?

Driven by Data Style

init:function(){
    Dispatcher.on('clickBtnCompare.Foo',this.addSeries);
},
destroy:function(){
    Dispatcher.off('clickBtnCompare.Foo');
}
                        

Pull Data Style

clickBtnCompare:function(){
    AppCube.DataRepository.fetchNew(storeName).done(function(data){
        chart.addSeries(data);
    });
}
                        

How about add more one Action?

someTimes:function(){
    Dispatcher.on('clickBtnCompare.Foo',this.anotherAction);
}
                        

Provide fetch and notify API

N(View):1(Model) use notify

1(View):N(Model or State) use fetch

fetch:function(key,state,options){
    var store = this._store_list[key];
    return store.getState(state,options);
},
fetchNew:function(key,options){
    var store = this._store_list[key];
    return store.refreshData(options,true);
},
refresh:function(key,options){
    var store = this._store_list[key];
    store.refreshData(options).done(function(res){
        Dispatcher.trigger('refresh:'+key,res,'Component');
    });
}
                        

Store

Get different State form Origin Data Update Origin Data by params

The Second Argument -- the Origin Data after Update

One Request -- Just Update it Two Request at the same time?
var task = CustomTask.create(taskOptions);
var store = CustomStore.create({
    name:storeName,
    generator:function(options,taskOptions){
        var chart = Dispatcher.request('getParams',{},'Chart');
        var params = _.extend({},taskOptions.params,options,chart);
        //todo fetch params

        return {
            params: params
        }
    }
});
store.setData(task);
store.addState('table',function(res){
    return formatter(res);
 });
                        

Layout&Container&Component

THE END