Skip to content

Instantly share code, notes, and snippets.

View rijkvanzanten's full-sized avatar
💜
Building Directus

Rijk van Zanten rijkvanzanten

💜
Building Directus
View GitHub Profile
@rijkvanzanten
rijkvanzanten / socketMiddleware.js
Created October 19, 2016 15:11
Redux Action Middleware which forwards actions to the server via socket.io when `server: true` is set in action object
const createSocketMiddleware = function(socket, {eventName = 'action'} = {}) {
return ({dispatch}) => {
socket.on(eventName, dispatch);
return (next) => (action) => {
if(action.hasOwnProperty('server')) socket.emit(eventName, action);
return next(action);
};
};
};
@rijkvanzanten
rijkvanzanten / isObjectEqual.js
Created October 11, 2016 14:44
Function which checks if two objects are equal
function isEqual(obj1, obj2) {
const props1 = Object.getOwnPropertyNames(obj1);
const props2 = Object.getOwnPropertyNames(obj2);
if(props1.length != props2.length) {
return false;
}
for(let i = 0; i < props1.length; i++) {
const propName = props1[i];
if(obj1[propName] !== obj2[propName]) {