UNPKG

cluedin-widget

Version:

This is the project for creating and managing widgets in CluedIn.

66 lines (61 loc) 2.46 kB
const constants = require( '../constants' ); const initialState = { allFollowers: [], isDoingFollowingRequest: false, shouldAddFollowerEntityId: void 0, shouldRemoveFollowerEntityId: void 0 }; module.exports = function update( state = initialState, action = {} ) { switch( action.type ) { case constants.follow.RECEIVE_ALL_FOLLOW: return Object.assign( {}, { allFollowers: action.data.followers, isDoingFollowingRequest: false, shouldAddFollowerEntityId: void 0, shouldRemoveFollowerEntityId: void 0 } ); case constants.follow.REQUEST_FOLLOW: return Object.assign( {}, { allFollowers: state.allFollowers, isDoingFollowingRequest: true, shouldAddFollowerEntityId: void 0, shouldRemoveFollowerEntityId: void 0 } ); case constants.follow.REQUEST_UNFOLLOW: return Object.assign( {}, { allFollowers: state.allFollowers, isDoingFollowingRequest: true, shouldAddFollowerEntityId: void 0, shouldRemoveFollowerEntityId: void 0 } ); case constants.follow.RECEIVE_UNFOLLOW: state.allFollowers = state.allFollowers.filter( ( f ) => { return f.Entity.EntityId !== action.data.entity.id } ); return Object.assign( {}, { allFollowers: state.allFollowers.slice(), isDoingFollowingRequest: false, shouldAddFollowerEntityId: void 0, shouldRemoveFollowerEntityId: action.data.entity.id } ); case constants.follow.RECEIVE_FOLLOW: state.allFollowers.push( { Count: 0, Entities: [], Entity: { Count: 0, EntityId: action.data.entity.id, EntityName: action.data.entity.name, EntityType: action.data.entity.data.entityType } } ); return Object.assign( {}, { allFollowers: state.allFollowers.slice(), isDoingFollowingRequest: false, shouldAddFollowerEntityId: action.data.entity.id, shouldRemoveFollowerEntityId: void 0 } ); default : return state; } };