diff --git a/package.json b/package.json index 25f300d5f4b..131bd110c91 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,7 @@ }, "homepage": "http://rackt.github.io/redux", "dependencies": { + "lodash": "^4.1.0", "loose-envify": "^1.1.0" }, "devDependencies": { diff --git a/src/combineReducers.js b/src/combineReducers.js index 9569f0cffec..84bdc28f18a 100644 --- a/src/combineReducers.js +++ b/src/combineReducers.js @@ -1,5 +1,5 @@ import { ActionTypes } from './createStore' -import isPlainObject from './utils/isPlainObject' +import isPlainObject from 'lodash/isPlainObject' import warning from './utils/warning' function getUndefinedStateErrorMessage(key, action) { diff --git a/src/createStore.js b/src/createStore.js index befa312882f..c422b51ad67 100644 --- a/src/createStore.js +++ b/src/createStore.js @@ -1,4 +1,4 @@ -import isPlainObject from './utils/isPlainObject' +import isPlainObject from 'lodash/isPlainObject' /** * These are private action types reserved by Redux. diff --git a/src/utils/isPlainObject.js b/src/utils/isPlainObject.js deleted file mode 100644 index 3921c3045c8..00000000000 --- a/src/utils/isPlainObject.js +++ /dev/null @@ -1,24 +0,0 @@ -var fnToString = (fn) => Function.prototype.toString.call(fn) -var objStringValue = fnToString(Object) - -/** - * @param {any} obj The object to inspect. - * @returns {boolean} True if the argument appears to be a plain object. - */ -export default function isPlainObject(obj) { - if (!obj || typeof obj !== 'object') { - return false - } - - var proto = typeof obj.constructor === 'function' ? Object.getPrototypeOf(obj) : Object.prototype - - if (proto === null) { - return true - } - - var constructor = proto.constructor - - return typeof constructor === 'function' - && constructor instanceof constructor - && fnToString(constructor) === objStringValue -} diff --git a/test/utils/isPlainObject.spec.js b/test/utils/isPlainObject.spec.js deleted file mode 100644 index 3314c5ff6e4..00000000000 --- a/test/utils/isPlainObject.spec.js +++ /dev/null @@ -1,22 +0,0 @@ -import expect from 'expect' -import isPlainObject from '../../src/utils/isPlainObject' -import vm from 'vm' - -describe('isPlainObject', () => { - it('returns true only if plain object', () => { - function Test() { - this.prop = 1 - } - - const sandbox = { fromAnotherRealm: false } - vm.runInNewContext('fromAnotherRealm = {}', sandbox) - - expect(isPlainObject(sandbox.fromAnotherRealm)).toBe(true) - expect(isPlainObject(new Test())).toBe(false) - expect(isPlainObject(new Date())).toBe(false) - expect(isPlainObject([ 1, 2, 3 ])).toBe(false) - expect(isPlainObject(null)).toBe(false) - expect(isPlainObject()).toBe(false) - expect(isPlainObject({ 'x': 1, 'y': 2 })).toBe(true) - }) -}) diff --git a/webpack.config.base.js b/webpack.config.base.js index 0dd203db37a..0d1b556c973 100644 --- a/webpack.config.base.js +++ b/webpack.config.base.js @@ -1,5 +1,7 @@ 'use strict'; +var webpack = require('webpack'); + module.exports = { module: { loaders: [ @@ -10,7 +12,7 @@ module.exports = { library: 'Redux', libraryTarget: 'umd' }, - resolve: { - extensions: ['', '.js'] - } + plugins: [ + new webpack.optimize.OccurenceOrderPlugin() + ] }; diff --git a/webpack.config.development.js b/webpack.config.development.js index e509d7cd245..3c0a1d97356 100644 --- a/webpack.config.development.js +++ b/webpack.config.development.js @@ -1,14 +1,13 @@ 'use strict'; +var _ = require('lodash'); var webpack = require('webpack'); var baseConfig = require('./webpack.config.base'); -var config = Object.create(baseConfig); -config.plugins = [ - new webpack.optimize.OccurenceOrderPlugin(), - new webpack.DefinePlugin({ - 'process.env.NODE_ENV': JSON.stringify('development') - }) -]; - -module.exports = config; +module.exports = _.merge({}, baseConfig, { + plugins: baseConfig.plugins.concat( + new webpack.DefinePlugin({ + 'process.env.NODE_ENV': '"development"' + }) + ) +}); diff --git a/webpack.config.production.js b/webpack.config.production.js index f4589cc06db..9cad002cd42 100644 --- a/webpack.config.production.js +++ b/webpack.config.production.js @@ -1,20 +1,22 @@ 'use strict'; +var _ = require('lodash'); var webpack = require('webpack'); var baseConfig = require('./webpack.config.base'); -var config = Object.create(baseConfig); -config.plugins = [ - new webpack.optimize.OccurenceOrderPlugin(), - new webpack.DefinePlugin({ - 'process.env.NODE_ENV': JSON.stringify('production') - }), - new webpack.optimize.UglifyJsPlugin({ - compressor: { - screw_ie8: true, - warnings: false - } - }) -]; - -module.exports = config; +module.exports = _.merge({}, baseConfig, { + plugins: baseConfig.plugins.concat( + new webpack.DefinePlugin({ + 'process.env.NODE_ENV': '"production"' + }), + new webpack.optimize.UglifyJsPlugin({ + compressor: { + pure_getters: true, + unsafe: true, + unsafe_comps: true, + screw_ie8: true, + warnings: false + } + }) + ) +});