Skip to content

Instantly share code, notes, and snippets.

@vincentfretin
Last active August 29, 2015 14:27
Show Gist options
  • Save vincentfretin/35bff3a9d138e9349c1b to your computer and use it in GitHub Desktop.
Save vincentfretin/35bff3a9d138e9349c1b to your computer and use it in GitHub Desktop.
Flatten redux and react-redux for react native playground
cd /tmp
npm install [email protected]
cat node_modules/redux/src/createStore.js node_modules/redux/src/utils/* > redux.js
sed -e 's@^export default @@' -e 's@^export @@' -e 's@^import.*@@' \
-e 's@`"${actionType.toString()}"`@actionType.toString()@' \
redux.js >redux_wo_import_export.js
cat << "EOF" >> redux_wo_import_export.js
// from https://github.com/gaearon/redux-thunk
function thunk({ dispatch, getState }) {
return next => action =>
typeof action === 'function' ?
action(dispatch, getState) :
next(action);
}
// from react-redux/node_modules/invariant/invariant.js
var invariant = function(condition, format, a, b, c, d, e, f) {
if (!condition) {
var error;
if (format === undefined) {
error = new Error(
'Minified exception occurred; use the non-minified dev environment ' +
'for the full error message and additional helpful warnings.'
);
} else {
var args = [a, b, c, d, e, f];
var argIndex = 0;
error = new Error(
'Invariant Violation: ' +
format.replace(/%s/g, function() { return args[argIndex++]; })
);
}
error.framesToPop = 1; // we don't care about invariant's own frame
throw error;
}
};
EOF
git clone [email protected]:rackt/react-redux.git # get git instead of the 0.9.0 release because the release is already transformed with webpack
cat react-redux/src/utils/shallowEqual.js react-redux/src/utils/wrapActionCreators.js react-redux/src/utils/createStoreShape.js react-redux/src/components/createProvider.js react-redux/src/components/createConnect.js react-redux/src/components/createAll.js > react-redux.js
echo "var React = require('react-native');" >>react-redux.js
cat react-redux/src/native.js >>react-redux.js
sed -e 's@^export default @@' -e 's@^export @@' -e 's@^import.*@@' -e 's@const @let @' -e 's@::[email protected](this)@' \
react-redux.js > react-redux_wo_import_export.js
cat redux_wo_import_export.js react-redux_wo_import_export.js > redux-native.js
# edit manually redux-native.js to remove static and put it at the end of the class (Provider.childContextTypes for instance)
# edit manually redux-native.js to transform all template literals to es5.
# OR transform with babel:
npm install babel-core
node -e "console.log(require('babel-core').transformFileSync('redux-native.js', {stage: 0}).code)" >redux-native-babel.js
# copy and paste redux-native-babel.js to react native playground
@vincentfretin
Copy link
Author

execute the script with:

bash flatten_redux.bash

and copy and paste the redux-native-babel.js file content to the top of index.ios.js file on React Native Playground.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment