Conversation
boutell
left a comment
There was a problem hiding this comment.
Use area.getManager.
Provide an empty stub method in the base class of widgets so you don't have to do an if test and it is more self-documenting for widget developers. Also important to establish the pattern so that people can use extendMethods which would be thwarted if they had to check if it existed first.
In general though, this is great.
|
Took me a minute, but I think this is what you want. |
| self.apos.area.widgetManagers?.[item.type]; | ||
|
|
||
| let widgetOptions = {}; | ||
| if (manager && typeof manager.annotateWidgetForExternalFront === 'function') { |
There was a problem hiding this comment.
You don't need this if anymore. It's going to exist.
There was a problem hiding this comment.
By adding it to the base class we've made it part of the contract you can expect.
I guess you can still do if (manager).
There was a problem hiding this comment.
I thought I would have to error on the side of caution. Learning!
| }); | ||
| }, | ||
|
|
||
| annotateWidgetForExternalFront() { |
| }; | ||
| if (widgetOptions && Object.keys(widgetOptions).length > 0) { | ||
| const widgetOptions = await manager.annotateWidgetForExternalFront() || {}; | ||
| if (Object.keys(widgetOptions).length > 0) { |
There was a problem hiding this comment.
Why not always provide it, so people on the astro side don't have to drive defensively with ?.? An empty object isn't that expensive.
| // at least as an empty array. | ||
|
|
||
| annotateAreaForExternalFront(field, area) { | ||
| async annotateAreaForExternalFront(field, area) { |
There was a problem hiding this comment.
Does this really need to be async? It's a major performance hit when multiplied by every area and then every widget, and there's no async work being done to look up options. Also I don't think you changed anything where it's called, so there's probably just a promise showing up there?
My starting assumption is that this annotation work should not be async. It's meant to be very lightweight to minimize the impact of using an external frontend.
| const manager = self.apos.area.getManager?.(item.type) || | ||
| self.apos.area.widgetManagers?.[item.type]; | ||
|
|
||
| const widgetOptions = await manager.annotateWidgetForExternalFront() || {}; |
| }); | ||
| }, | ||
|
|
||
| annotateWidgetForExternalFront() { |
There was a problem hiding this comment.
Noticing this is already not async (and that's good), I think "async" in the area annotation method might have been a discarded early thought that hung around?
|
Based on the way "async" was hanging around in that method and "await" was being used even though it was called synchronously, my impression is that this probably hasn't been tested yet in an Astro project? |
|
After a bit of nonsense with getting apostrophe linked in, I removed the erroneous asyncs and confirmed that everything was functional in the starter-kit-astro-essentials with the improved |
|
|
||
| ### Fixes | ||
|
|
||
| * Resolve inline image URLs correctly when in edit mode and not in the default locale. |
There was a problem hiding this comment.
It looks like one of Miro's PRs got caught up in this PR somehow. But I'm going to ignore it because I know I approved it.
The merge-base changed after approval.
The merge-base changed after approval.
Summary
Summarize the changes briefly, including which issue/ticket this resolves. If it closes an existing Github issue, include "Closes #[issue number]"
This PR updates the
annotateAreaForExternalFront()method to acceptannotateWidgetForExternalFront()methods from any widget module. This will allow for individual widgets to pass options to an external frontend, like Astro.What are the specific steps to test this change?
For example:
starter-kit-astro-essentialsbackend add a project-level option to the image-widget.optionsfrom the frontmatter.What kind of change does this PR introduce?
(Check at least one)
Make sure the PR fulfills these requirements:
If adding a new feature without an already open issue, it's best to open a feature request issue first and wait for approval before working on it.
Other information: