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

Add new ImportMapScriptElement #845

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Add new ImportMapScriptElement #845

wants to merge 1 commit into from

Conversation

sylr
Copy link
Contributor

@sylr sylr commented Jul 14, 2024

ImportMapScriptElement renders a json importmap which allows to tell browsers how to resolve javascript dependencies.

Copy link
Contributor

@garrettladley garrettladley left a comment

Choose a reason for hiding this comment

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

good stuff @sylr


// NewImportMapScriptElement creates a new ImportMapScriptElement.
// The data must be a valid JSON string.
func NewImportMapScriptElement(id string, data string) ImportMapScriptElement {
Copy link
Contributor

@garrettladley garrettladley Jul 27, 2024

Choose a reason for hiding this comment

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

to stick with the convention in jsonscript.go, the signature of this would be ImportMapScript(...) ImportMapScriptElement.

also, there is no indication that this function panics in the signature. if a function might panic, it is usually best practice to name the function Must[original func name].

however, dealing with the panicing is probably a moot point as this logic should likely be handled in Render.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed the function name as suggested.

Copy link
Contributor

@garrettladley garrettladley Jul 27, 2024

Choose a reason for hiding this comment

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

is this not just a special case of a JSONScript where type="importmap" and data is of type ImportMap? if so, we should simply reuse the logic 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.

The purpose of ImportMapScriptElement is to avoid Marshaling JSON data every render.

@sylr sylr force-pushed the importmap branch 4 times, most recently from 8b755e7 to 0b13b72 Compare January 16, 2025 21:20
ImportMapScriptElement renders a json importmap which allows to tell browsers how to resolve javascript dependencies.

Signed-off-by: Sylvain Rabot <[email protected]>
@sylr sylr marked this pull request as ready for review January 16, 2025 21:34
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