Skip to content
This repository has been archived by the owner on Oct 1, 2019. It is now read-only.

Commit

Permalink
Don't allow to create the same error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
artkravchenko authored and voidxnull committed Aug 21, 2016
1 parent 94596b4 commit 457f5c1
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/store/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import i from 'immutable';
import { find } from 'lodash';
import { LOCATION_CHANGE } from 'react-router-redux';

import { messages } from '../actions';
Expand All @@ -33,6 +34,13 @@ function removeDuplicate(state, action) {
}

export default function reducer(state = initialState, action) {
if (find([messages.ADD_ERROR, messages.ADD_MESSAGE], a => a === action.type)) {
const index = state.findIndex(item => item.message === action.message);
if (index !== -1) {
state = state.delete(index);
}
}

switch (action.type) {
case messages.ADD_ERROR: {
state = removeDuplicate(state, action);
Expand Down

0 comments on commit 457f5c1

Please sign in to comment.