[go: nahoru, domu]

Skip to content

Commit

Permalink
Added a verification to only update fields that are valid.
Browse files Browse the repository at this point in the history
  • Loading branch information
sebas5384 committed Dec 5, 2017
1 parent 78c4f2f commit f6737b4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/modules/editor/containers/NodeEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import isHotKey from 'is-hotkey'

import { getSelectedNode, updateNodeFields } from '../store'
import { deserializeFields, serializeFields } from '../lib/serializers'
import { fieldIsInvalid } from '../lib/helpers';

const Wrapper = styled.section``

Expand Down Expand Up @@ -143,6 +144,9 @@ const componentWillMount = function () {
const handleOnChange = ({ node, dispatch, setValue }) => ({ value }) => {
// Deserialize value to [ { name, type }, { name, type } ].
const fields = serializeFields(value.toJS())

// Avoid creating invalid types.
if (fields.some(fieldIsInvalid)) return setValue(value)

// Dispatch an action to save the unserialized value to node.fields[].
// @TODO [ASAP] Find better perfomance, for ex. debaunce the dispatching.
Expand Down
1 change: 1 addition & 0 deletions src/modules/editor/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const getModelFromRelation = ({ edges, nodeB }) => {
if (!edge) return
return edge.nodes[1]
}
export const typeToModel = type => type.replace(/[^A-Za-z_]*/g, '')

/*
* Initial State.
Expand Down

0 comments on commit f6737b4

Please sign in to comment.