You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Make a class for types that can be sent to & from ports with the representations that Elm uses
Write a runProgram variant that you can call from Javascript with flags, and provide a way to export to Javascript something you can call via .worker(flags) etc.
I'm thinking through how to actually implement ports now.
Elm allows ports to be defined in any module (as long as you say it is a port module). The compiler must make some kind of collection of these ports to attach to the ports object at program startup. We avoid that for effects managers, because we don't really need to know about effects managers until they are actually used (via a Cmd or Sub). We almost have the same luxury for ports, because a port (to be interesting) must eventually be used to generate a Cmd or Sub. However, by its very nature, the Javascript must subscribe to a port before we see the Cmd. (And, it could potentially send a message before we see the Sub).
So, I think we have to do one of several things.
We could force the programmer to actually list all the ports when calling program. This might not be a bad idea, really, but it would diverge from what Elm does.
We could have some kind of code-generation stage (mimicking what I expect the Elm compiler must be doing when it sees port module). But that seems awkward.
When we set up the ports object for Javascript to use, we can make it a Javascript Proxy, so we can write a function to construct the Javascript end of ports on the fly (and keep a reference). Then, when we see the port on the Purescript side, we can use the reference to see whether there already have been subscriptions etc. This probably could be made to work, but would have at least one disadvantage -- we wouldn't be able to reject any access to ports where the port doesn't exist, because we wouldn't know whether the port might exist in the future or not.
So, none of these are ideal. I think I like the Proxy idea best, but it's possible that requiring ports to be explicitly provided to program is wiser.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The needed steps are roughly:
runProgramvariant that you can call from Javascript with flags, and provide a way to export to Javascript something you can call via.worker(flags)etc.