Skip to content

Commit da8b198

Browse files
authored
Merge pull request #60 from waterbird-i/addHash
feat: 优化 rjvId 生成方式,添加随机字符串增加唯一性
2 parents c06a8da + 6d85757 commit da8b198

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

src/js/index.js

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ReactJsonView extends React.PureComponent {
3131
}
3232

3333
// reference id for this instance
34-
rjvId = Date.now().toString()
34+
rjvId = Date.now().toString() + Math.random().toString(36).slice(2)
3535

3636
// all acceptable props and default values
3737
static defaultProps = {
@@ -205,46 +205,39 @@ class ReactJsonView extends React.PureComponent {
205205
}
206206

207207
updateSrc = () => {
208-
const {
209-
name,
210-
namespace,
211-
new_value,
212-
existing_value,
213-
variable_removed,
214-
updated_src,
215-
type
216-
} = ObjectAttributes.get(this.rjvId, 'action', 'variable-update')
208+
const { name, namespace, newValue, existingValue, updatedSrc, type } =
209+
ObjectAttributes.get(this.rjvId, 'action', 'variable-update')
217210
const { onEdit, onDelete, onAdd } = this.props
218211

219212
const { src } = this.state
220213

221214
let result
222215

223-
const on_edit_payload = {
224-
existing_src: src,
225-
new_value,
226-
updated_src,
216+
const onEditPayload = {
217+
existingSrc: src,
218+
newValue,
219+
updatedSrc,
227220
name,
228221
namespace,
229-
existing_value
222+
existingValue
230223
}
231224

232225
switch (type) {
233226
case 'variable-added':
234-
result = onAdd(on_edit_payload)
227+
result = onAdd(onEditPayload)
235228
break
236229
case 'variable-edited':
237-
result = onEdit(on_edit_payload)
230+
result = onEdit(onEditPayload)
238231
break
239232
case 'variable-removed':
240-
result = onDelete(on_edit_payload)
233+
result = onDelete(onEditPayload)
241234
break
242235
}
243236

244237
if (result !== false) {
245-
ObjectAttributes.set(this.rjvId, 'global', 'src', updated_src)
238+
ObjectAttributes.set(this.rjvId, 'global', 'src', updatedSrc)
246239
this.setState({
247-
src: updated_src
240+
src: updatedSrc
248241
})
249242
} else {
250243
this.setState({

0 commit comments

Comments
 (0)