In elm you can pass a flag to an elm application like so:
Html / JS
<div id="elm"></div>
<script>
var app = Elm.Main.init({
node: document.getElementById('elm'),
flags: Date.now()
});
</script>
The elm app then gets the parameters on init:
init : Int -> ( Model, Cmd Msg )
init currentTime =
...
I've been through the fable documentation and to me it's not clear how I can achieve the same thing.
I see there is an option Program.runWith to send parameters on the init function, but I can't find documentation and I can't see from the compiled javascript how I should call the main function from the html file.
With fable, I want to be able to do something like this in the html file, but not sure what "Program.Run.." would be:
<body>
<div id="elmish-app" class="elmish-app"></div>
<script src="bundle.js"></script>
<script>
Program.Run({time: Date.now()});
</script>
</body>
Thanks
Just building off of the earlier answer from Maxime Mangel, I've took the hacky approach, but adapated it a little bit to make use of local storage. I'm sharing this is an alternative for anyone else that needs to find a way to pass in Args to a Fable-Elmish App that are set/collected prior to the start.
In the App.fs (last file run/compiled):
This pulls from the Local Storage Values set in Browser prior to the App Initialization, so then you can have these set in the JS however, you'd like.
within index.html:
You could of-course adapt this however you wanted to pull in the values/variables that are set in local storage. I needed these 'dynamic' initial arguments for parameterizing a Subscription that I want to start on the Program Run and am using this for a demo I'm working on for using SignalR in Fable-Elmish, and I will likely adapt this to prompt for these on loading the page.
However, the point here is that you can do whatever you want to get the values, as long as they're set in the Local Storage prior to the start of the App! I find this a relatively 'cleaner hack', but am still a beginner with Fable-Elmish, and there is likely a better approach.
[Just want to highlight for further clarity that these will be a part of the Initial Model]