2

I want to evaluate some values that I read in from a config source, and bake those values into my WebSharper SPA. With these value I want to generate the SPA for each of my customers and use the SPA in a different mobile app for each customer.

When I try to do this, WebSharper expects me to decorate my module with the JavaScript attribute.

How can I provide configuration values without having to decorate my module?

Example:

type Config = { brandedUrl : Uri } // This is configurable depending on customer

module Configuration = // I don't want to decorate this module with JavaScript
  // Some code that reads a config file, yml maybe
  let get : Config = getConfig // extract vals from file

[<JavaScript>]
module Navbar =
  let navbar = divAttr [ img [ src Configuration.get.brandedUrl ] ] 
Mr. Mr.
  • 4,257
  • 3
  • 27
  • 42
  • So if it's not in the Javascript code, I assume it's read from the server. If so, then you could make an [] call. – Ray Jun 01 '16 at 20:27
  • @Ray It doesn't use RPC as it is an SPA although that wouldn't actually prevent that from being possible. I have an endpoint that injects json into the page and the websharper code can read the json and access the properties. I posted in answer now that I discovered a solution. Can detail it more if required, your feedback would be appreciated. Thanks :-) – Mr. Mr. Jun 15 '16 at 08:25

1 Answers1

0

Can be achieved using built in WebSharper functionality, demonstrated here: https://github.com/Kimserey/ConfigTest

Mr. Mr.
  • 4,257
  • 3
  • 27
  • 42