Skip to content

Commit

Permalink
Merge pull request #49 from tur-nr/object-assign
Browse files Browse the repository at this point in the history
fixes #48
  • Loading branch information
tur-nr authored Jan 30, 2017
2 parents 3a05494 + 90d7333 commit fcf7088
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 5 deletions.
39 changes: 35 additions & 4 deletions polymer-redux.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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.
*
Expand Down
42 changes: 41 additions & 1 deletion test/polymer-redux.unit-spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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() {},
});
});
});
});
});
</script>
Expand Down

0 comments on commit fcf7088

Please sign in to comment.