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

✨ Feature – Allow interop with JS or TS #22

Closed
ryan-haskell opened this issue Jul 27, 2022 · 4 comments · Fixed by #54
Closed

✨ Feature – Allow interop with JS or TS #22

ryan-haskell opened this issue Jul 27, 2022 · 4 comments · Fixed by #54
Assignees
Labels
Feature Adding a new capability or user-facing feature

Comments

@ryan-haskell
Copy link
Contributor

Problem

Elm supports interop with JavaScript via flags, ports, and web components. It is not clear in the guide how working with those things is possible with Elm Land.

Solution

The high-level idea is to allow users to create an src/interop.js file in their project that looks like this:

export const flags = ({ env }) => {
  return {}
}

export const onReady = ({ env, app }) => {
  // Ports are available on `app.ports`
}

This is currently supported in JavaScript, but I need to explore how involved src/interop.ts would be. Mainly I'm interested in whether supporting Typescript will require extra configuration, build steps, or have serious performance impact.

@ryan-haskell ryan-haskell self-assigned this Jul 27, 2022
@ryan-haskell ryan-haskell added @elm-land/app Feature Adding a new capability or user-facing feature labels Jul 27, 2022
@jamesrweb
Copy link

jamesrweb commented Sep 15, 2022

Is there a way we could create something like an Environment.elm which exports a environment function for the build / server to pull in and then users can always remain within the ecosystem rather than creating a JS file? Basically what is already in place for Route and so on within the internals and in that way all environment settings, ports and so on is on the framework level to handle and users can remain in elm land 😉. In that way, for example with environment, it could just be passed to all pages as a normal param or as a separate argument as part of the init flow, WDYT?

update: better yet in the case of environment a simple .env in the root directory being parsed in by the CLI and then given to the initialiser method for pages could be a really nice feature. Then it's standardised and no new files other than that .env for environment (flags) would be required.

@ryan-haskell
Copy link
Contributor Author

Hey there 👋

100% agree on adding .env file support, that's a missing feature that will benefit everyone!

Elm Land will still use the elm-land.json and the src/interop.js files to provide environment variables via flags, and those same variables will be available for folks working with JS web components etc


If you're interested, you should definitely join the Discord channel and share more of your pain points there!

( I mostly use GitHub issues to track planned work, and am slower to see comments here )

@jamesrweb
Copy link

Hey there 👋

100% agree on adding .env file support, that's a missing feature that will benefit everyone!

Elm Land will still use the elm-land.json and the src/interop.js files to provide environment variables via flags, and those same variables will be available for folks working with JS web components etc


If you're interested, you should definitely join the Discord channel and share more of your pain points there!

( I mostly use GitHub issues to track planned work, and am slower to see comments here )

Thanks for the tip, I'll consider it!

As to your point about the interop JS file and to clarify how you would implement the environment variable parsing, is this your plan?

  • Parse dotenv file
  • Pass environment variables to interop JS as a function argument to the default export (making an assumption 😉)
  • Take return value of that function as the flags to be passed to all Elm page init functions

If that is the flow you had in mind, I still don't understand why the interop JS is required since we could just pass the environment variables into a record to all page init constructors.

I guess I also don't understand the point about web components, why would they need access to flags?

Perhaps it's just a big misunderstanding on my part 🙈!

@ryan-haskell ryan-haskell removed their assignment Oct 13, 2022
@ryan-haskell
Copy link
Contributor Author

Both TypeScript support and .env files have been added in #54 , and will be released with v0.18.0 🚀

@ryan-haskell ryan-haskell self-assigned this Dec 16, 2022
@ryan-haskell ryan-haskell linked a pull request Dec 16, 2022 that will close this issue
27 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Adding a new capability or user-facing feature
Development

Successfully merging a pull request may close this issue.

2 participants