Skip to content

Commit aeb7b4f

Browse files
committed
[FIX] Issue #6
1 parent fe4cc56 commit aeb7b4f

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

src/components/JsonArray.js

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -186,25 +186,36 @@ class JsonArray extends Component {
186186
}
187187

188188
handleEditValue({ key, value }) {
189-
const { data, keyPath, deep } = this.state;
190-
// Update value
191-
const oldValue = data[key];
192-
data[key] = value;
193-
// Set state
194-
this.setState({
195-
data,
196-
});
197-
// Spread new update
198-
const { onUpdate, onDeltaUpdate } = this.props;
199-
onUpdate(keyPath[keyPath.length - 1], data);
200-
// Spread delta update
201-
onDeltaUpdate({
202-
type: UPDATE_DELTA_TYPE,
203-
keyPath,
204-
deep,
205-
key,
206-
newValue: value,
207-
oldValue,
189+
return new Promise((resolve, reject) => {
190+
const { beforeUpdateAction } = this.props;
191+
const { data, keyPath, deep } = this.state;
192+
193+
// Old value
194+
const oldValue = data[key];
195+
196+
// Before update action
197+
beforeUpdateAction(key, keyPath, deep, oldValue, value).then(() => {
198+
// Update value
199+
data[key] = value;
200+
// Set state
201+
this.setState({
202+
data,
203+
});
204+
// Spread new update
205+
const { onUpdate, onDeltaUpdate } = this.props;
206+
onUpdate(keyPath[keyPath.length - 1], data);
207+
// Spread delta update
208+
onDeltaUpdate({
209+
type: UPDATE_DELTA_TYPE,
210+
keyPath,
211+
deep,
212+
key,
213+
newValue: value,
214+
oldValue,
215+
});
216+
// Resolve
217+
resolve();
218+
}).catch(reject);
208219
});
209220
}
210221

src/components/JsonValue.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ const propTypes = {
3636
const defaultProps = {
3737
keyPath: [],
3838
deep: 0,
39-
handleUpdateValue: () => {
40-
},
39+
handleUpdateValue: () => Promise.resolve(),
4140
editButtonElement: <button>e</button>,
4241
cancelButtonElement: <button>c</button>,
4342
inputElement: <input />,

0 commit comments

Comments
 (0)