Skip to content

Commit

Permalink
[desk-tool] Adjust FormBuilder to use patchChannel
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoerge committed Aug 31, 2017
1 parent 4386525 commit 40fe45c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion packages/@sanity/desk-tool/src/pane/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ function getToggleKeyState(event) {

export default withRouterHOC(class Editor extends React.PureComponent {
static propTypes = {
patchChannel: PropTypes.object,
draft: PropTypes.object,
published: PropTypes.object,
type: PropTypes.object.isRequired,
Expand Down Expand Up @@ -337,7 +338,8 @@ export default withRouterHOC(class Editor extends React.PureComponent {
isLoading,
isPublishing,
isUnpublishing,
isCreatingDraft
isCreatingDraft,
patchChannel
} = this.props

const {
Expand Down Expand Up @@ -411,6 +413,7 @@ export default withRouterHOC(class Editor extends React.PureComponent {
</div>
<form className={styles.editor} onSubmit={preventDefault} id="Sanity_Default_DeskTool_Editor_ScrollContainer">
<FormBuilder
patchChannel={patchChannel}
value={draft || published || {_type: type.name}}
type={type}
onChange={this.handleChange}
Expand Down
4 changes: 3 additions & 1 deletion packages/@sanity/desk-tool/src/pane/EditorWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export default class EditorPane extends React.Component {
}

state = INITIAL_STATE
patchChannel = FormBuilder.createPatchChannel()

setup(documentId) {
this.dispose()
Expand Down Expand Up @@ -100,7 +101,7 @@ export default class EditorPane extends React.Component {
}
// Broadcast incoming patches to input components that applies patches on their own
// Note: This is *experimental*
FormBuilder.receivePatches({
this.patchChannel.receivePatches({
patches: event.patches,
snapshot: event.document
})
Expand Down Expand Up @@ -257,6 +258,7 @@ export default class EditorPane extends React.Component {

return (
<Editor
patchChannel={this.patchChannel}
type={schema.get(typeName)}
published={published.snapshot}
draft={draft.snapshot}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export default function SanityFormBuilder(props) {
resolvePreviewComponent={SanityPreview}
resolveValidationComponent={ValidationList}
/>)

}

SanityFormBuilder.createPatchChannel = FormBuilder.createPatchChannel

export {inputResolver, defaultConfig}

0 comments on commit 40fe45c

Please sign in to comment.