All files / src/action/pattern objectPattern.js

100% Statements 9/9
100% Branches 0/0
100% Functions 6/6
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34                  13x       15x 2x 2x         15x 15x       15x 15x       17x      
// @flow
 
import type {Pattern, Action, ObjectActionType} from '../types';
 
type ObjectAction = Action<ObjectActionType>;
 
export default class ObjectPattern implements Pattern<ObjectAction> {
  actions: Array<ObjectAction>;
  constructor() {
    this.actions = [];
  }
 
  mergeMultiMapUpdate() {
    this.actions = [this.actions.reduce((result: Object, action: ObjectAction) => {
      result.payload.value = {...result.payload.value, ...action.payload.value};
      return result;
    })];
  }
 
  addAction = (action: ObjectAction) => {
    this.actions.push(action);
    this.mergeAction();
  }
 
  mergeAction = (): Array<ObjectAction> => {
    this.mergeMultiMapUpdate();
    return this.actions;
  }
 
  getActions = (): Array<ObjectAction> => {
    return this.actions;
  }
}