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

🐝: decouple annotation classes in renderer #269

Closed
wants to merge 2 commits into from

Conversation

bachbui
Copy link
Contributor

@bachbui bachbui commented Oct 28, 2019

Currently there is logic in the Commonmark Renderer that checks for specific annotation classes in the rendering logic. We should decouple this, as this means this renderer will only work with specific Sources. Instead, the renderer should expose its own types or interfaces for annotations rather than using the annotation classes from a source directly. This fix resolves the immediate issue instead of fleshing out the aforementioned feature, which can be done at a later date.

 - @atjson/editor@0.21.9-dev.0
 - @atjson/offset-inspector@0.21.9-dev.0
 - @atjson/renderer-commonmark@0.21.9-dev.0
@@ -233,6 +233,22 @@ function getNumberOfRequiredBackticks(text: string) {
}, 1);
}

function isBold(annotation?: any) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Type predicates may be very helpful here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, that's what I was looking for. But now I'm not sure if this is the right approach. If we theoretically had access to document.schema.Bold then it would be better to rely on that.

@tim-evans
Copy link
Collaborator

@tim-evans
Copy link
Collaborator

I chatted with @bachbui briefly, but it has occurred to me that we could rewrite this for more maximal reuse:

function is<T extends AnnotationConstructor>(
  AnnotationClass: T,
  annotation: Annotation<any>
): annotation is InstanceType<T> {
  let OtherClass = annotation.constructor as AnnotationConstructor;
  return annotation.type === AnnotationClass.type &&
   OtherClass.vendorPrefix === AnnotationClass.vendorPrefix;
}

@tim-evans
Copy link
Collaborator

This can be closed by the new is function that I've merged 🎉

@tim-evans tim-evans closed this Feb 25, 2020
@tim-evans tim-evans deleted the fix/decouple-annotations branch March 11, 2020 19:05
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.

2 participants