Created
January 17, 2018 11:52
-
-
Save laat/c22817d5bf86e7c8aaafe9a53b918948 to your computer and use it in GitHub Desktop.
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
import { Middleware, Action } from 'redux'; | |
// Grabbed from: | |
// https://github.com/reactjs/redux/blob/master/src/utils/isPlainObject.js | |
function isPlainObject(obj: any) { | |
if (typeof obj !== 'object' || obj === null) return false | |
let proto = obj | |
while (Object.getPrototypeOf(proto) !== null) { | |
proto = Object.getPrototypeOf(proto) | |
} | |
return Object.getPrototypeOf(obj) === proto | |
} | |
// Workaround for: | |
// https://github.com/reactjs/redux/issues/2361 | |
const convertToPlainObject: Middleware = store => next => (action: any) => { | |
if (!isPlainObject(action) && typeof action === 'object') { | |
return Object.assign({}, action); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment