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

Use a single JS entrypoint modeled after Blacklight #1503

Merged
merged 3 commits into from
Aug 14, 2024
Merged

Conversation

thatbudakguy
Copy link
Member

@thatbudakguy thatbudakguy commented Aug 13, 2024

This is prep work for #1443, pulled out of #1467.

Prior to this PR, we bundled Geoblacklight's JS separately from the generated app's JS. This was done because we have to manage the registration of all of the stimulus controllers and then call all the initializer functions that make up the GBL core before the app's JS runs, so they are available.

After this PR, Geoblacklight's JS is more extendable & interoperable due to borrowing a paradigm from Blacklight. You can now do:

import "@geoblacklight/frontend"

which is all that's needed to register the controllers and ensure everything is set up. You can also do:

import Geoblacklight from "@geoblacklight/frontend"
Geoblacklight.onLoad(() => console.log('my thing'))

to run arbitrary code after Geoblacklight is set up, just like Blacklight's onLoad hook. This hook also fires whether or not you're using Turbo. Individual controllers and modules can still be imported, e.g. if you wanted to subclass them:

import { LeafletViewerController } from "@geoblacklight/frontend"
class MyNewViewerController extends LeafletViewerController {
  // ...
}

Because of this, the application now only needs a single unified JS entrypoint, where we import Geoblacklight and then add any other JS we want. The whole thing is bundled into a single file by Vite.

Copy link

github-actions bot commented Aug 13, 2024

Demo app download link: https://github.com/geoblacklight/geoblacklight/actions/runs/10377343913/artifacts/1808660691

  1. Download demo app and unzip file
  2. Change into app directory
    • run docker compose pull
    • run docker compose up
  3. Open in browser

@thatbudakguy thatbudakguy marked this pull request as ready for review August 13, 2024 21:22
@ewlarson ewlarson self-requested a review August 14, 2024 15:28
Copy link
Member

@ewlarson ewlarson left a comment

Choose a reason for hiding this comment

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

🥇 // Very clean, nice work!

@ewlarson ewlarson merged commit 0b0f38c into main Aug 14, 2024
11 checks passed
@ewlarson ewlarson deleted the js-entrypoint branch August 14, 2024 15:30
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