Skip to content

Add new ImportMapScriptElement#845

Open
sylr wants to merge 1 commit intoa-h:mainfrom
sylr:importmap
Open

Add new ImportMapScriptElement#845
sylr wants to merge 1 commit intoa-h:mainfrom
sylr:importmap

Conversation

@sylr
Copy link
Copy Markdown
Contributor

@sylr sylr commented Jul 14, 2024

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

Copy link
Copy Markdown
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

Comment thread importmapscript.go Outdated

// NewImportMapScriptElement creates a new ImportMapScriptElement.
// The data must be a valid JSON string.
func NewImportMapScriptElement(id string, data string) ImportMapScriptElement {
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread importmapscript.go
Copy link
Copy Markdown
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
Copy Markdown
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 <sylvain@abstraction.fr>
@sylr sylr marked this pull request as ready for review January 16, 2025 21:34
@joerdav
Copy link
Copy Markdown
Collaborator

joerdav commented Jan 27, 2025

Your time and effort is much appreciated @sylr ! Thanks for putting time aside to contribute a feature.

Though, we have in our guidelines an ask to first open a discussion when implementing a feature that hasn't already been discussed: https://github.com/a-h/templ/blob/main/CONTRIBUTING.md#come-up-with-a-design-and-share-it

Definitely not saying that we won't merge your change, but it would bo good to just have a proposal issue in place so that we can ensure that it aligns with the goals of templ.

Thanks again for contributing!!

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