Skip to content

Instantly share code, notes, and snippets.

@lanwin lanwin/index.html

Created Jun 7, 2016
Embed
What would you like to do?
Redux devtools extension with mori
<!DOCTYPE html>
<html>
<body>
<script src="/node_modules/redux/dist/redux.js" type="text/javascript"></script>
<script src="/node_modules/mori/mori.js" type="text/javascript"></script>
<script type="text/javascript">
"use strict";
function reducer(){
return mori.hashMap('key','value');
}
var store = Redux.createStore(reducer, null, window.devToolsExtension({
select:function(state){return mori.toJs(state);}
}));
store.dispatch({type:'test'});
console.log('state: ',store.getState());
</script>
</body>
</html>
@lanwin

This comment has been minimized.

Copy link
Owner Author

lanwin commented Jun 7, 2016

npm install mori
npm install redux
npm install http-server
.\node_modules.bin\htt-server

Mori uses its own data structures (here a hashMap). It would be nice if the devtools extension could get an selector function (as in my example obove) to transform the state before its getting display by the devtools extension.

@zalmoxisus

This comment has been minimized.

Copy link

zalmoxisus commented Jun 7, 2016

What do you think of passing instead a function for serialization like

    var store = Redux.createStore(reducer, window.devToolsExtension && window.devToolsExtension({
        serializeState: function(key, value){
            if (value && mori.isMap(value)) { return mori.toJs(value); }
            return value;
        }
    }));

It would allow to have mixed data in states (and for action payloads especially), and also to do better serialization (with mori.intoArray for example).

@lanwin

This comment has been minimized.

Copy link
Owner Author

lanwin commented Jun 8, 2016

Thanks for fixing it this fast!!!

I am not sure about that API. For what exactly this is called? The key value thing confuses me a little bit.

mori.toJs can convert an entire state tree to plain js even if not all objects are mori collections.

@lanwin

This comment has been minimized.

Copy link
Owner Author

lanwin commented Jun 8, 2016

Check it. Works like a charm 💃 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.