-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Claro Now Fully Supports Modules Exporting Static Values Initialized …
…on Program Startup! This is a massive development as it eliminates a large portion of the use cases that dependency injection frameworks get used for! Now, a module can simply declare that it statically exports a static value, and the entire program can use this singleton, deeply-immutable, non-reassignable value anywhere in the program. As a strong argument for the power of this functionality, I've included an update of the Buggy Buggies demo server that takes advantage of this new functionality to allow the use of a *single* statically initialized `HttpClient<BuggyBuggies>` instance throughout the entire server lifetime, whereas prior to this it was impossible for a Claro Server to maintain any state whatsoever, so clients had to be continuously re-initialized on the fly. To take this example even further, to demonstrate how Claro's static values can eliminate the need for any dependency injection framework, I could use Bazel to select a static value provider at build time based on some flag like `--dev` or `--prod`. See: https://bazel.build/docs/configurable-attributes.
- Loading branch information
1 parent
5052d29
commit 6557728
Showing
11 changed files
with
75 additions
and
46 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
5 changes: 3 additions & 2 deletions
5
...claro_programs/demo_server/buggy_buggies/buggy_buggies_service/buggy_buggies_client.claro
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
|
||
function getClient(url: string) -> HttpClient<BuggyBuggies> { | ||
return http::getHttpClient(url); | ||
provider static_HTTP_CLIENT() -> HttpClient<BuggyBuggies> { | ||
# This now only needs to happen once throughout the entire program. | ||
return http::getHttpClient("https://buggy-buggies.gigalixirapp.com"); | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
7 changes: 1 addition & 6 deletions
7
...o/claro_programs/demo_server/buggy_buggies/endpoint_handlers/start_new_game_handler.claro
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,5 @@ | ||
|
||
graph function startNewGameHandler(handle: string) -> future<string> { | ||
root joinRes <- Utils::handleBuggyResponseAsHtmlStrParts(@moveBuggyResponse)[0]; | ||
node moveBuggyResponse <- | ||
BuggyBuggiesClient::hostGame( | ||
# TODO(steving) Migrate to using a singleton client once Claro's Modules can export static (singleton) values. | ||
BuggyBuggiesClient::getClient("https://buggy-buggies.gigalixirapp.com"), | ||
handle | ||
); | ||
node moveBuggyResponse <- BuggyBuggies::hostGame(BuggyBuggies::HTTP_CLIENT, handle); | ||
} |
This file contains 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
This file contains 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
This file contains 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