Skip to content

Commit

Permalink
Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
hpehl committed May 6, 2024
1 parent 33ad3fd commit 555da38
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,6 @@ Elemento offers a very basic router. The router is minimal invasive and built ar
See the API documentation of [PlaceManager](https://hal.github.io/elemento/apidocs/org/jboss/elemento/router/PlaceManager.html) for more details.

```java
@Route("/time/:area/:location")
public static class TimePage implements Page {

@Override
Expand All @@ -481,13 +480,17 @@ public static class Application {
body().add(div().id("main"));
new PlaceManager()
.root(By.id("main"))
.register(place("/home")
.register(place("/time/:area/:location")
.loader((place, parameter) -> {
String area = parameter.get("area");
String location = parameter.get("location");
return fetch("https://worldtimeapi.org/api/timezone/" + area + "/" + location)
String url = "https://worldtimeapi.org/api/timezone/" + area + "/" + location;
return fetch(url)
.then(Response::json)
.then(json -> Promise.resolve(Js.<JsPropertyMap<String>>cast(json).get("datetime")));
.then(json -> {
JsPropertyMap<String> map = Js.cast(json);
return Promise.resolve(map.get("datetime"));
});
}), TimePage::new)
.start();
}
Expand Down
12 changes: 7 additions & 5 deletions router/src/demo/java/PlaceManagerDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.jboss.elemento.router.Parameter;
import org.jboss.elemento.router.Place;
import org.jboss.elemento.router.PlaceManager;
import org.jboss.elemento.router.Route;

import elemental2.dom.HTMLElement;
import elemental2.dom.Response;
Expand All @@ -41,7 +40,6 @@
public class PlaceManagerDemo {

// @start region = placeManager
@Route("/time/:area/:location")
public static class TimePage implements Page {

@Override
Expand All @@ -65,13 +63,17 @@ public void entryPoint() {
body().add(div().id("main"));
new PlaceManager()
.root(By.id("main"))
.register(place("/home")
.register(place("/time/:area/:location")
.loader((place, parameter) -> {
String area = parameter.get("area");
String location = parameter.get("location");
return fetch("https://worldtimeapi.org/api/timezone/" + area + "/" + location)
String url = "https://worldtimeapi.org/api/timezone/" + area + "/" + location;
return fetch(url)
.then(Response::json)
.then(json -> Promise.resolve(Js.<JsPropertyMap<String>>cast(json).get("datetime")));
.then(json -> {
JsPropertyMap<String> map = Js.cast(json);
return Promise.resolve(map.get("datetime"));
});
}), TimePage::new)
.start();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import static java.util.Collections.emptyMap;

/**
* The Parameter class is used to represent parameters in a route path. A parameter is a part of the path that starts with a
* The Parameter class is used to represent parameters and their values in a route path. A parameter is a part of the path that starts with a
* colon (e.g. ":id"). Parameters are used to retrieve values from a path.
*/
public class Parameter {
Expand Down

0 comments on commit 555da38

Please sign in to comment.