refactor prosemirror conversion for understandability #779
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes
mapTokens
(renamed tomapTokensRecursive
)isToken
logic by removing redundant logicresolvePandocBlockCapsuleText
, resulting in redundant logic). It has two interrelated recursive parts. A "recursive array data mapping" part and a "recursive function output content mapping" part. Because of the recursive nature of this function, I feel justified in going full functional programmer on its refactor: I refactored into two separate functions that return functions:mapRecursiveArray
factors out the "recursive array data mapping" part, andmapTokenAndContentTokensRecursively
factors out the "recursive function output content mapping" part. It is still a difficult function to understand, but I've removed some redundancy and made how its parts depend on eachother more direct and explicit.mapTokensRecursive
I understood it better and was able to understand and significantly simplifyresolvePandocBlockCapsuleText
writeToken
to prefer Array.find over iterating through the array until the element is found.createHandlers
createHandler
which is nice because it can now early return instead of modifying a variable.TODO