Normalization for initial value
See original GitHub issueDo you want to request a feature or report a bug?
feature
What’s the current behavior?
- Value is set on editor
- Only when the user types something into the editor, the
editor.normalizeNode
is called for that specific node (and it’s parent nodes) - Other nodes that have not been touched stay invalid until e.g. the text of that node is edited
Slate: 0.57.1 Browser: Chrome / Safari / Firefox / Edge OS: Mac / Windows / Linux / iOS / Android
What’s the expected behavior?
There are multiple solutions. I currently have 2 in mind:
- All nodes are normalized once after the value has been set initially
- A callback is exposed (e.g.
onValueUpdated
) where we could add some logic to runEditor.normalize(editor)
everytime the value has been updated from outside (e.g. coming from a DB)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:21
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Solved: Normalizing Data to Initial Value - JMP User Community
I have a data set that I am plotting against time, and I was wondering if there was a feature in JMP to...
Read more >Normalization Formula - WallStreetMojo
The equation for normalization is derived by initially deducting the minimum value from the variable to be normalized. Next, the minimum value deducts...
Read more >Normalization Formula: How To Use It on a Data Set - Indeed
How to use the normalization formula · 1. Calculate the range of the data set · 2. Subtract the minimum x value from...
Read more >How to Normalize Data Between 0 and 1 - Statology
To normalize the values in a dataset to be between 0 and 1, you can use the following formula: zi = (xi –...
Read more >Normalization - Codecademy
Min-max normalization is one of the most common ways to normalize data. For every feature, the minimum value of that feature gets transformed...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
After running into other issues with the above workarounds I finally ended up with this:
useEffect
hook to update the internal slate value with the incoming external valueNow here comes the magic part. Instead of just setting the external value on the internal state I use this:
The solution by @davidruisinger worked great, as I also was running into troubles when building a controlled slate component - when setting the external value to editor.children it skips normalisation.
However I improved it a little, because in his solution the component would always render twice (once with an initial value, and once, when the internal state is set after the useEffect runs).
You can avoid this by doing it in a useMemo.
Then I use this on my Slate Component.
hope this helps someone else.