Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
wax-prosemirror
Manage
Activity
Members
Labels
Plan
Issues
34
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
2
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wax
wax-prosemirror
Commits
44533f9a
Commit
44533f9a
authored
4 years ago
by
chris
Browse files
Options
Downloads
Patches
Plain Diff
replace useEffect with useCallback
parent
456b433f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!137
Fix wax view rerender
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
wax-prosemirror-core/src/WaxView.js
+40
-31
40 additions, 31 deletions
wax-prosemirror-core/src/WaxView.js
with
40 additions
and
31 deletions
wax-prosemirror-core/src/WaxView.js
+
40
−
31
View file @
44533f9a
import
React
,
{
useEffect
,
useRef
,
useContext
}
from
'
react
'
;
import
React
,
{
useEffect
,
useRef
,
useContext
,
useCallback
}
from
'
react
'
;
import
applyDevTools
from
'
prosemirror-dev-tools
'
;
import
{
EditorState
}
from
'
prosemirror-state
'
;
...
...
@@ -17,37 +17,46 @@ export default props => {
let
view
;
const
context
=
useContext
(
WaxContext
);
useEffect
(()
=>
{
view
=
new
EditorView
(
{
mount
:
editorRef
.
current
},
{
editable
:
()
=>
!
readonly
,
state
:
EditorState
.
create
(
options
),
dispatchTransaction
,
user
,
handleDOMEvents
:
{
blur
:
onBlur
?
view
=>
{
onBlur
(
view
.
state
.
doc
.
content
);
}
:
null
,
},
transformPasted
:
slice
=>
{
return
transformPasted
(
slice
,
view
);
const
setEditorRef
=
useCallback
(
node
=>
{
if
(
editorRef
.
current
)
{
// this is where you do cleanup if you have to. the editorRef.current will
// still point to the old ref, the old node. so you have some time here to
// clean up the unmount if you need to.
}
if
(
node
)
{
view
=
new
EditorView
(
{
mount
:
node
},
{
editable
:
()
=>
!
readonly
,
state
:
EditorState
.
create
(
options
),
dispatchTransaction
,
user
,
handleDOMEvents
:
{
blur
:
onBlur
?
view
=>
{
onBlur
(
view
.
state
.
doc
.
content
);
}
:
null
,
},
transformPasted
:
slice
=>
{
return
transformPasted
(
slice
,
view
);
},
},
},
);
);
context
.
updateView
(
{
main
:
view
,
},
'
main
'
,
);
if
(
debug
)
applyDevTools
(
view
);
if
(
autoFocus
)
view
.
focus
();
context
.
updateView
(
{
main
:
view
,
},
'
main
'
,
);
if
(
debug
)
applyDevTools
(
view
);
if
(
autoFocus
)
view
.
focus
();
return
()
=>
view
.
destroy
();
return
()
=>
view
.
destroy
();
}
editorRef
.
current
=
node
;
},
[]);
const
dispatchTransaction
=
transaction
=>
{
...
...
@@ -59,7 +68,7 @@ export default props => {
const
state
=
view
.
state
.
apply
(
tr
);
view
.
updateState
(
state
);
/*when a transaction comes from a view other than
/*
when a transaction comes from a view other than
main don't keep updating the view ,as this is
the central point of each transaction
*/
...
...
@@ -75,7 +84,7 @@ export default props => {
props
.
onChange
(
state
.
doc
.
content
);
};
const
editor
=
<
div
ref
=
{
e
ditorRef
}
/>
;
const
editor
=
<
div
ref
=
{
setE
ditorRef
}
/>
;
return
props
.
children
({
editor
,
});
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment