From 683b29486a8efd03729e4f23665fece2f8fc8920 Mon Sep 17 00:00:00 2001 From: Christopher Turner Date: Sat, 21 Jan 2017 17:14:08 +1100 Subject: [PATCH 1/2] fixes #48 --- polymer-redux.js | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/polymer-redux.js b/polymer-redux.js index b220ee9..48b21d6 100644 --- a/polymer-redux.js +++ b/polymer-redux.js @@ -1,11 +1,11 @@ -(function(root, factory) { +(function(global, factory) { /* istanbul ignore next */ if (typeof exports === 'object' && typeof module === 'object') { module.exports = factory(); } else if (typeof define === 'function' && define.amd) { define(factory); } else { - root['PolymerRedux'] = factory(); + global['PolymerRedux'] = factory(); } })(this, function() { var warning = 'Polymer Redux: <%s>.%s has "notify" enabled, two-way bindings goes against Redux\'s paradigm'; @@ -173,12 +173,12 @@ // add behavior actions first, in reverse order so we keep priority if (Array.isArray(behaviors)) { for (var i = behaviors.length - 1; i >= 0; i--) { - Object.assign(actions, behaviors[i].actions); + objectAssign(actions, behaviors[i].actions); } } // element actions have priority - element._reduxActions = Object.assign(actions, element.actions); + element._reduxActions = objectAssign(actions, element.actions); } /** @@ -243,6 +243,37 @@ return Array.prototype.slice.call(args, 0); } + /** + * Object.assign() + * + * @param {Object} target + * @param {Object} [...obj] + * @return {Object} The target. + */ + function objectAssign(target) { + // use browser + if (typeof Object.assign === 'function') { + return Object.assign.apply(Object, arguments); + } + + var hasOwn = Object.prototype.hasOwnProperty; + var argc = arguments.length; + var obj; + + for (var i = 1; i < argc; ++i) { + obj = arguments[i]; + if (obj != null) { + for (var k in obj) { + if (hasOwn.call(obj, k)) { + target[k] = obj[k]; + } + } + } + } + + return target; + } + /** * Creates PolymerRedux behaviors from a given Redux store. * From 90d7333543ab5b4bb6a3a2c7e4cbc5a490425d82 Mon Sep 17 00:00:00 2001 From: Christopher Turner Date: Mon, 30 Jan 2017 13:45:58 +1100 Subject: [PATCH 2/2] more specs for object.assign issue. increases coverage --- test/polymer-redux.unit-spec.html | 42 ++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/test/polymer-redux.unit-spec.html b/test/polymer-redux.unit-spec.html index c593581..8a925db 100644 --- a/test/polymer-redux.unit-spec.html +++ b/test/polymer-redux.unit-spec.html @@ -256,7 +256,7 @@ this.store.dispatch = storeDispatch; }); - it.only('should dispatch actions from middleware', function() { + it('should dispatch actions from middleware', function() { var action = {}; var middleware = sinon.spy(function(dispatch) { dispatch(action); @@ -290,6 +290,46 @@ assert.strictEqual(this.returnedState, this.state); }); }); + + describe('polyfill Object.assign for IE11', function() { + var assign = Object.assign; + + before(function() { + Object.assign = undefined; + }); + + after(function() { + Object.assign = assign; + }); + + it('should not throw when Object.assign is undefined', function() { + var ready = this.behavior.ready; + assert.doesNotThrow(function() { + ready.apply({ + fire: function() {}, + actions: { + foo: function() {} + } + }); + }); + }); + + it('should only assign own props', function() { + var actions = {}; + actions.__proto__.foo = function() {}; + + var ready = this.behavior.ready.apply({ + fire: function() {}, + actions: actions + }); + }); + + it('should not assign nulls/undefineds', function() { + var ready = this.behavior.ready.apply({ + fire: function() {}, + }); + }); + }); }); });