Skip to content

Instantly share code, notes, and snippets.

@laat
Created January 17, 2018 11:52
Show Gist options
  • Save laat/c22817d5bf86e7c8aaafe9a53b918948 to your computer and use it in GitHub Desktop.
Save laat/c22817d5bf86e7c8aaafe9a53b918948 to your computer and use it in GitHub Desktop.
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