return (dispatch, getState) => { const spaceMetrics = getState().metrics.filter(m => m.space === item.space) const existingReadableIds = spaceMetrics.map(m => m.readableId) let newItem = Object.assign({}, item, e.metric.create(existingReadableIds)) dispatch({ type: 'ADD_METRIC', item: newItem }) }
constructor(dispatch: Function, getState: Function, graphFilters: object) { this.dispatch = dispatch this.getState = getState this.id = Date.now() this.spaceId = graphFilters.spaceId if (this.spaceId === undefined && graphFilters.metricId) { const metric = e.metric.get(getState().metrics, graphFilters.metricId) this.spaceId = metric && metric.space } this.useGuesstimateForm = graphFilters.useGuesstimateForm || false this.orderedMetricIds = this._orderedMetricIds(graphFilters) this.orderedMetricPropagations = this.orderedMetricIds.map(id => (new MetricPropagation(id, this.id))) this.currentStep = 0 const remainingPropagationSteps = this.orderedMetricPropagations.map(p => p.remainingSimulations.length) this.totalSteps = _.sum(remainingPropagationSteps) }
function buildNewMetric(startMetric, metrics, location) { const metricId = metrics.find(m => isAtLocation(m.location, location)) || e.metric.create(metrics.map(m => m.readableId)) return {...startMetric, ..._.pick(metricId, ['id', 'readableId']), location} }
function registerGraphChange(dispatch, getState, metricId) { const metric = engine.metric.get(getState().metrics, metricId) const spaceId = _.get(metric, 'space') spaceId && dispatch(spaceActions.registerGraphChange(spaceId)); }
function findSpaceId(getState, metricId) { const metric = e.metric.get(getState().metrics, metricId) return _.get(metric, 'space') }