Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify build api code #572

Merged
merged 16 commits into from
Nov 15, 2021
Merged

Unify build api code #572

merged 16 commits into from
Nov 15, 2021

Conversation

pcardune
Copy link
Collaborator

This PR moves all the "api building" code to one place, CodeMirror-api.tsx, and moves the call site(s) for this code to the top of the component hierachry.

Previously, the imperative API that we exposed as a replacement for and augmentation of codemirror's apis, was tightly coupled to various react components and their internal state and event handlers. To get all the different bits and pieces together required a lot of plumbing between components to pass the relevant parts of the public API up through the hiearchy. Now the APIs are just a wrapper around the redux store and a codemirror editor... they do not have anything to do with react. Likewise, the react components now don't have to care or know anything about the public interface to the library.

There's still some more cleanup that I'd like to do before merging this, so leaving it in draft mode for now.

@coveralls
Copy link

coveralls commented Nov 11, 2021

Coverage Status

Coverage increased (+0.4%) to 71.707% when pulling 7e6f18b on pcardune/unify-buildAPI into 6d0f034 on master.

): Result<{ oldAst: AST; newAst: AST; newCode: string }, string> {
let oldAst: AST;
try {
oldAst = AST.from(language.parse(oldCode)); // parse the code (WITH annotations)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where the old annotate argument came in handy -- we just parsed without building any annotations, to make sure it was valid code. IIRC, the annotation process was pretty expensive. I saw noticeable jank when dealing with programs >400LOC.

@@ -135,36 +132,34 @@ const BlockEditor = ({ options = {}, ...props }: BlockEditorProps) => {
* When the editor mounts, (1) set change event handlers and AST,
* (2) set the focus, (3) set aria attributes, and (4) build the API
*/
const handleEditorDidMount = (editor: CodeMirrorFacade) => {
const handleEditorDidMount = (codemirror: CodeMirror.Editor) => {
const editor = new CodeMirrorFacade(codemirror);
setEditor(editor);
// TODO(Emmanuel): Try to set them in the component constructor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only place where we manually use CM's methods to attach handlers. It's ugly. I wasn't able to convince TypeScript that setting these in the constructor was a valid move. I suspect you'll have a better shot at figuring it out. :)

@pcardune pcardune marked this pull request as ready for review November 15, 2021 19:21
@pcardune
Copy link
Collaborator Author

Ok, I think this is ready to merge. Want to take a look at it @schanzer?

@schanzer schanzer merged commit cae2596 into master Nov 15, 2021
@schanzer schanzer deleted the pcardune/unify-buildAPI branch November 15, 2021 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants