Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

[wip] support for previous state #25

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ export function notifyObservers(payload) {
const {
id,
event,
props
props,
prevProps
} = payload

const {
Expand Down Expand Up @@ -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 => {
Expand All @@ -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: {
Expand Down
15 changes: 12 additions & 3 deletions src/components/core/NotifyObservers.react.js
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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
};
}

Expand All @@ -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,
Expand All @@ -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
}));
}
}

Expand Down