Skip to content

Simplify #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Oct 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.psci
.psci_modules
.pulp-cache/
.psc-ide-port
npm-debug.log
node_modules/
bower_components/
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2016 Eric Thul
Copyright (c) 2016-2017 Eric Thul

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
Expand Down
10 changes: 8 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@
"!src/**/*"
],
"dependencies": {
"purescript-profunctor-lenses": "^3.2.0",
"purescript-react": "^3.0.0"
"purescript-react": "^3.0.0",
"purescript-record": "athanclark/purescript-record#850360dbfa1bf765a19b3ec207a706622fa47ac7",
"purescript-monoid": "^3.1.0",
"purescript-strings": "^3.3.1",
"purescript-nullable": "^3.0.0"
},
"resolutions": {
"purescript-record": "850360dbfa1bf765a19b3ec207a706622fa47ac7"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"pscid": "PATH=$PURESCRIPT_0_11_PATH:$PATH pscid"
},
"devDependencies": {
"pscid": "^1.12.1"
"pscid": "^2.0.2"
}
}
136 changes: 8 additions & 128 deletions src/React/Redux.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,138 +4,18 @@ var Redux = require('redux');

var ReactRedux = require('react-redux');

function startsWithActionType(actionForeign) {
var index = actionForeign.type.indexOf('@@PURESCRIPT_REACT_REDUX');

return index === 0;
}

function makeActionForeign(action) {
var constructorName = action.constructor && action.constructor.name ? action.constructor.name : 'UnknownConstructorName';

var actionForeign = {
type: '@@PURESCRIPT_REACT_REDUX/' + constructorName,
action: action
};

return actionForeign;
}

exports.createStore_ = function createStore_(reducer, state, enhancer){
return function(){
function reducerForeign(stateReducerForeign, actionForeign){
var result = startsWithActionType(actionForeign) ? reducer(actionForeign.action)(stateReducerForeign) : stateReducerForeign;

return result;
}

function enhancerForeign(createStoreForeign){
return function(reducerEnhancerForeign, stateEnhancerForeign){
function createStore(reducerCreateStore){
return function(stateCreateStore){
return function(){
var result = createStoreForeign(reducerCreateStore, stateCreateStore);

return result;
};
};
}

return enhancer(createStore)(reducerEnhancerForeign)(stateEnhancerForeign)();
};
}

return Redux.createStore(reducerForeign, state, enhancerForeign);
};
exports.reduxCreateStore = function reduxCreateStore(reducer, state, enhancer){
return Redux.createStore(reducer, state, enhancer);
};

exports.connect_ = function connect_(Tuple, mapStateToProps, reactClass){
function mapStateToPropsForeign(state, props) {
var statePropsTuple = Tuple(state)(props);

var result = mapStateToProps(statePropsTuple);

return result;
}

return ReactRedux.connect(mapStateToPropsForeign)(reactClass);
exports.reduxApplyMiddleware = function reduxApplyMiddleware(middleware){
return Redux.applyMiddleware.apply(Redux, middleware);
};

exports.dispatch_ = function dispatch_(thisForeign, action){
return function(){
var actionForeign = makeActionForeign(action);

var actionForeignResult = thisForeign.props.dispatch(actionForeign);

return actionForeignResult.action;
};
exports.reduxConnect = function reduxConnect(mapStateToProps, mapDispatchToProps, mergeProps, options){
return ReactRedux.connect(mapStateToProps, mapDispatchToProps, mergeProps, options);
};

exports.applyMiddleware = function applyMiddleware(middlewares){
var middlewaresForeign = middlewares.map(function(middleware){
return function(middlewareAPIForeign){
function getState(){
return middlewareAPIForeign.getState();
}

function dispatch(action){
return function(){
var actionForeignResult = makeActionForeign(action);

var result = middlewareAPIForeign.dispatch(actionForeignResult);

return result;
};
}

var cont = middleware({ getState: getState, dispatch: dispatch })

return function(nextForeign){
return function(actionForeign){

function next(action){
return function(){
var actionForeignResult = makeActionForeign(action);

var result = nextForeign(actionForeignResult);

return result;
};
}

var action = actionForeign.action;

var result = cont(next)(action)();

return result;
};
};
}
});

var middlewareEnhancerForeign = Redux.applyMiddleware.apply(Redux, middlewaresForeign);

var result = exports.fromEnhancerForeign(middlewareEnhancerForeign);

return result;
};

exports.fromEnhancerForeign = function fromEnhancerForeign(enhancerForeign){
return function(createStore){
return function(reducerForeign){
return function(stateForeign){
return function(){
function createStoreForeign(reducer, state){
var result = createStore(reducer)(state)();

return result;
};

return enhancerForeign(createStoreForeign)(reducerForeign, stateForeign);
};
};
};
};
}
exports.reduxConnect_ = exports.reduxConnect;

exports.providerClass = ReactRedux.Provider;
exports.reduxProviderClass = ReactRedux.Provider;
Loading