Created
April 26, 2017 12:09
-
-
Save notgiorgi/8ecacde731fe86e0d02885c9cc05bd2f to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/habasoy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
'use strict'; | |
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | |
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | |
console.clear(); | |
function factory(UNREGISTER, actionTypes, UID, instance) { | |
var unregistrator = function unregistrator(state, _ref) { | |
var payload = _ref.payload; | |
return _extends({}, state, _defineProperty({}, payload[UID], undefined)); | |
}; | |
var handler = function handler(state, _ref2) { | |
var payload = _ref2.payload; | |
return _extends({}, state, _defineProperty({}, payload[UID], instance(state[ID], action))); | |
}; | |
var id = function id(state) { | |
return state; | |
}; | |
var handlers = actionTypes.reduce(function (acc, curr) { | |
acc[curr] = handler; | |
return acc; | |
}, { | |
unregistrator: unregistrator, | |
'undefined': id | |
}); | |
return function (state, action) { | |
if (state === undefined) state = {}; | |
return handlers[action.type](state, action); | |
}; | |
} | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">console.clear() | |
function factory(UNREGISTER, actionTypes, UID, instance) { | |
const unregistrator = (state, { payload }) => ({ | |
...state, | |
[payload[UID]]: undefined, | |
}) | |
const handler = (state, { payload }) => ({ | |
...state, | |
[payload[UID]]: instance(state[ID], action), | |
}) | |
const id = state => state | |
const handlers = actionTypes.reduce( | |
(acc, curr) => { | |
acc[curr] = handler | |
return acc | |
}, | |
{ | |
unregistrator, | |
'undefined': id, | |
} | |
) | |
return (state = {}, action) => handlers[action.type](state, action) | |
} | |
</script></body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | |
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | |
console.clear(); | |
function factory(UNREGISTER, actionTypes, UID, instance) { | |
var unregistrator = function unregistrator(state, _ref) { | |
var payload = _ref.payload; | |
return _extends({}, state, _defineProperty({}, payload[UID], undefined)); | |
}; | |
var handler = function handler(state, _ref2) { | |
var payload = _ref2.payload; | |
return _extends({}, state, _defineProperty({}, payload[UID], instance(state[ID], action))); | |
}; | |
var id = function id(state) { | |
return state; | |
}; | |
var handlers = actionTypes.reduce(function (acc, curr) { | |
acc[curr] = handler; | |
return acc; | |
}, { | |
unregistrator: unregistrator, | |
'undefined': id | |
}); | |
return function (state, action) { | |
if (state === undefined) state = {}; | |
return handlers[action.type](state, action); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment