// @flow import type {Pattern, Action, ConnectActionType} from '../types'; import {uniqBy} from 'lodash'; type ConnectAction = Action; export default class ConnectPattern implements Pattern { actions: Array; constructor() { this.actions = []; } addAction = (action: ConnectAction) => { this.actions.push(action); this.mergeAction(); } mergeConnectAndDisconnectAndDelete = () => { this.actions = uniqBy([...this.actions].reverse(), action => { const {key, id, path, value} = action.payload; return `${key}.${id}.${path}.${value.id}`; }).reverse(); } mergeAction = (): Array => { this.mergeConnectAndDisconnectAndDelete(); return this.actions; } getActions = (): Array => { return this.actions; } }