diff --git a/src/actions/index.js b/src/actions/index.js index 510124e..238d174 100644 --- a/src/actions/index.js +++ b/src/actions/index.js @@ -158,7 +158,8 @@ export function notifyObservers(payload) { const { id, event, - props + props, + prevProps } = payload const { @@ -359,6 +360,25 @@ export function notifyObservers(payload) { value: view(propLens, layout) }; }); + payload.prevInputs = inputs.map(inputObject => { + if (id === inputObject.id && prevProps) { + return { + id: id, + property: inputObject.property, + value: prevProps[inputObject.property] + }; + } else { + const propLens = lensPath( + concat(paths[inputObject.id], + ['props', inputObject.property] + )); + return { + id: inputObject.id, + property: inputObject.property, + value: view(propLens, layout) + }; + } + }); } if (state.length > 0) { payload.state = state.map(stateObject => { @@ -372,8 +392,28 @@ export function notifyObservers(payload) { value: view(propLens, layout) }; }); + payload.prevState = state.map(stateObject => { + if (id === stateObject.id && prevProps) { + return { + id: id, + property: stateObject.property, + value: prevProps[stateObject.property] + }; + } else { + const propLens = lensPath( + concat(paths[stateObject.id], + ['props', stateObject.property] + )); + return { + id: stateObject.id, + property: stateObject.property, + value: view(propLens, layout) + }; + } + }); } + promises.push(fetch(`${urlBase(config)}_dash-update-component`, { method: 'POST', headers: { diff --git a/src/components/core/NotifyObservers.react.js b/src/components/core/NotifyObservers.react.js index 492b9e7..566f265 100644 --- a/src/components/core/NotifyObservers.react.js +++ b/src/components/core/NotifyObservers.react.js @@ -1,5 +1,5 @@ import {connect} from 'react-redux'; -import {isEmpty} from 'ramda'; +import {append, isEmpty, lensPath, view} from 'ramda'; import {notifyObservers, updateProps} from '../../actions'; import React, {PropTypes} from 'react'; @@ -11,7 +11,8 @@ import React, {PropTypes} from 'react'; function mapStateToProps (state) { return { dependencies: state.dependenciesRequest.content, - paths: state.paths + paths: state.paths, + layout: state.layout }; } @@ -33,6 +34,10 @@ function mergeProps(stateProps, dispatchProps, ownProps) { }, setProps: function setProps(newProps) { + const itempath = stateProps.paths[ownProps.id]; + const propPath = append('props', itempath); + const prevProps = view(lensPath(propPath), stateProps.layout); + const payload = { props: newProps, id: ownProps.id, @@ -43,7 +48,11 @@ function mergeProps(stateProps, dispatchProps, ownProps) { dispatch(updateProps(payload)); // Update output components that depend on this input - dispatch(notifyObservers({id: ownProps.id, props: newProps})); + dispatch(notifyObservers({ + id: ownProps.id, + props: newProps, + prevProps + })); } }