Structuring the store of a localized react / redux app

柔情痞子 提交于 2019-12-05 22:00:17

Super late to this party, but in case you're still curious.

I think your first implementation is definitely superior. A for loop over 3 items is not a taxing transaction, and you can (and should) factor that out into a helper function:

var forEachLanguage = function(state, dataType, callback){
    var languages_data = state[dataType];
    for(language_index in languages_data){
        var data = languages_data[language_index];
        callback(data);
    }
}

//Example for deleting item 2 from articles
forEachLanguage(state, 'articles', function(data){
    delete data[2];
});

Furthermore, if you're concerned about repeated lookups getting needlessly expensive (though realistically, I don't see this being a problem), you can use Reselect to cache your lookups and make re-usable lookup functions that incorporate locale.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!