Super Embed Architecture #3
Replies: 1 comment 5 replies
-
The API is really nicely structured and I can already image how this can be used together with SuperEditor 👍 URL recognition and fetching of metadataIf a developer that wants to integrate SuperEmbed together with SuperEditor, I would expect that If we take Slack as an example, if the user writes a URL then Slack will only show the embed in the input field only if the URL is correct. Otherwise it just formats the text referring to the URL as a link and shows no embed. I'm assuming that Slack check if the URL comes from a supported embed source and fetches the metadata in one go, and then it decide whether to display the embed or not. Is this a valid concern or has it already been considered in the proposed design? |
Beta Was this translation helpful? Give feedback.
-
Super Embed is a drop-in solution, as well as a small toolkit. Both modalities need to be supported by the architecture.
The fundamental responsibilities of Super Embed are as follows:
Recognizing URLs
Adding new URLs must be trivial.
Multiple handlers for a single URL must be supported. For example, there might be a Medium-specific handler, and there might also be a generic "catch all" handler for blog-style URLs. Both of these handlers need to be able to live together.
Fetching and Parsing URLs
Each type of metadata parser should be implemented in its own object so that developers can utilize parsers at their own discretion.
The parsed data should be returned in a formally typed data structure that's specific to the data being parsed, e.g.,
MediumBlogPostMetadata
.Multiple types of errors are possible when fetching and parsing. Each error condition needs to be identified and well represented.
Displaying a UI
A polished, responsive, cross-platform UI must exist for each type of metadata.
The UI needs to provide an experience for loading, error conditions, and the expected metadata presentation.
Each metadata experience needs to be deployable without the other parts of the system. i.e., the developer can provide a pre-constructed metadata, without fetching the URL, and the UI will display as expected.
High-Level Structure
At a high level, Super Embed should process URLs as shown below.
The above process describes the drop-in solution. When designing the object structure, the individual component use-cases must be kept in mind, too, e.g., fetching/parsing without display and displaying without fetching/parsing.
Technical Guidance
Conceptual Usage
To help inform the construction of Super Embed, the following are pseudo-code examples for how a developer might utilize Super Embed.
URL Parsing and Display Resolution
To support URL parsers with overlapping applicability, a Chain of Responsibility should be used. The formal definition for a Chain of Responsibility is overly verbose. For our purposes, a Chain of Responsibility is a list of URL parsers. To parse a URL, the overall parser will go down this list, asking each individual parser to attempt to parse a URL. If a URL parser returns null, the overall parser goes to the next item in the list. This continues until a URL is parsed, or until there aren't any more parsers, indicating that we don't know how to parse this URL.
The
SuperUrlDisplays
should also use a Chain of Responsibility to map a givenmetadata
to an appropriateWidgetBuilder
, for the same reasons as theSuperUrlParsers
object.Super Embed should maintain default
const
lists of all parsers and displays that ship with the package. By default, when a developer instantiates aSuperUrlParsers
orSuperUrlDisplays
without any configuration, those objects should use the global default lists.SuperEmbed Widget
The
SuperEmbed
widget is the drop-in solution that immediately gives developers full parsing and display functionality.To provide fetching, parsing, display, a loading UI, and an error UI all in one, the
SuperEmbed
widget will operate on aSuperEmbedController
, which internally handles all of those responsibilities, and notifies clients of changes.Beta Was this translation helpful? Give feedback.
All reactions