4

Interpreted languages such as PHP allow a separate file, often called config.php, to contain string constants such as server names. This facilitates deployment, as the config file is simply not uploaded when the code is updated - the server names, e.g. for REST transactions, are typically different in the deployment environment.

In Dart, since it is compiled, this approach does not work. If there are server name constants which are referred to in the HTML via {{ }}, it seems the code must be recompiled before deployment.

Is there a way to specify string constants in such a way to avoid this recompilation requirement?

Peter B
  • 603
  • 1
  • 8
  • 18
  • 1
    I suspect that the answer at present is "you can't", but it's being discussed only last week - see [this post on the dartlang group](https://groups.google.com/a/dartlang.org/d/msg/misc/5rM931f5XOk/FTaXdqnF4BAJ). – Chris Buckett Jan 24 '13 at 22:02

2 Answers2

1

There are a couple of options I can think of:

One trick is to put configuration in a map keyed by hostname. At runtime, look up the configuration from the map, using window.location as a key. This will allow configuration to be baked into the Dart source, yet still allow different values to be specified for different environments.

If you want to be able to change your configuration after compilation, you can embed it as JSON within the HTML source, or load it via an HTTP request. (This isn't using a constant as asked, however, by definition it's not possible to change a constant after compile time)

Greg Lowe
  • 15,430
  • 2
  • 30
  • 33
0

Ok, so short answer is "You can't" - at the moment. But the Dart team are aware of this limitation, and are discussing it in dartlang as per the comment above.

Peter B
  • 603
  • 1
  • 8
  • 18