Skip to content

Commit 1489bfe

Browse files
committed
Switch naming convention in MustacheView to async prefix
1 parent 38d8ccb commit 1489bfe

File tree

8 files changed

+16
-17
lines changed

8 files changed

+16
-17
lines changed

Diff for: spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationReactiveIntegrationTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public String layout(Model model) {
107107
@RequestMapping(path = "/sse", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
108108
public String sse(Model model) {
109109
model.addAttribute("time", new Date());
110-
model.addAttribute("flux.message",
110+
model.addAttribute("async.message",
111111
Flux.just("<span>Hello</span>", "<span>World</span>")
112112
.delayElements(Duration.ofMillis(10)));
113113
model.addAttribute("title", "Hello App");
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
{{#flux.message}}
1+
{{#async.message}}
22
event: message
33
{{#ssedata}}
44
<h2>Title</h2>
55
{{{.}}}
66
{{/ssedata}}
7-
{{/flux.message}}
7+
{{/async.message}}

Diff for: spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc

+3-3
Original file line numberDiff line numberDiff line change
@@ -3038,14 +3038,14 @@ There are some special features of the `MustacheView` that make it suitable for
30383038

30393039
===== Progressive Rendering
30403040

3041-
A model element of type `Publisher` will be left in the model (instead of expanding it before the view is rendered), if its name starts with "flux" or "mono" or "publisher". The `View` is then rendered and flushed to the HTTP response as soon as each element is published. Browsers are really good at rendering partially complete HTML, so the flux elements will most likely be visible to the user as soon as they are available. This is useful for rendering the "main" content of a page if it is a list or a table, for instance.
3041+
A model element of type `Publisher` will be left in the model (instead of expanding it before the view is rendered), if its name starts with "async." or "async:". The `View` is then rendered and flushed to the HTTP response as soon as each element is published. Browsers are really good at rendering partially complete HTML, so the flux elements will most likely be visible to the user as soon as they are available. This is useful for rendering the "main" content of a page if it is a list or a table, for instance.
30423042

30433043
===== Sserver Sent Event (SSE) Support
30443044

30453045
To render a `View` with content type `text/event-stream` you need a model element of type `Publisher`, and also a template that includes that element (probably starts and ends with it). There is a convenience Lambda (`ssedata`) added to the model for you that prepends every line with `data:` - you can use it if you wish to simplify the rendering of the data elements. Two new lines are added after each item in `{{#ssedata}}`. E.g. with an element called `flux.events` of type `Flux<Event>`:
30463046

30473047
```
3048-
{{#flux.events}}
3048+
{{#async.events}}
30493049
event: message
30503050
id: {{id}}
30513051
{{#ssedata}}
@@ -3054,7 +3054,7 @@ id: {{id}}
30543054
<span>Value: {{value}}<span>
30553055
</div>
30563056
{{/ssedata}}
3057-
{{/flux.events}}
3057+
{{/async.events}}
30583058
```
30593059

30603060
the output will be

Diff for: spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/result/view/MustacheView.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,7 @@ private Template compile(Resource resource) {
151151
protected Mono<Void> resolveAsyncAttributes(Map<String, Object> model) {
152152
Map<String, Object> result = new HashMap<>();
153153
for (String key : model.keySet()) {
154-
if (!key.startsWith("flux") && !key.startsWith("mono")
155-
&& !key.startsWith("publisher")) {
154+
if (!key.startsWith("async.") && !key.startsWith("async:")) {
156155
result.put(key, model.get(key));
157156
}
158157
else {

Diff for: spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/result/view/MustacheViewTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void viewResolvesPublisher() {
7575
view.setUrl(this.templateUrl + "/flux.html");
7676
view.setCharset(StandardCharsets.UTF_8.displayName());
7777
view.setApplicationContext(this.context);
78-
view.render(Collections.singletonMap("flux.value", Flux.just("World", "Spring")),
78+
view.render(Collections.singletonMap("async:value", Flux.just("World", "Spring")),
7979
MediaType.TEXT_HTML, this.exchange).block(Duration.ofSeconds(30));
8080
assertThat(this.exchange.getResponse().getBodyAsString()
8181
.block(Duration.ofSeconds(30))).isEqualTo("Hello\nWorld\nSpring\n");
@@ -90,7 +90,7 @@ public void viewResolvesSseManual() {
9090
view.setUrl(this.templateUrl + "/sse.html");
9191
view.setCharset(StandardCharsets.UTF_8.displayName());
9292
view.setApplicationContext(this.context);
93-
view.render(Collections.singletonMap("flux.value", Flux.just("World", "Spring")),
93+
view.render(Collections.singletonMap("async.value", Flux.just("World", "Spring")),
9494
MediaType.TEXT_EVENT_STREAM, this.exchange).block(Duration.ofSeconds(30));
9595
assertThat(this.exchange.getResponse().getBodyAsString()
9696
.block(Duration.ofSeconds(30))).isEqualTo(
@@ -106,7 +106,7 @@ public void viewResolvesSseData() {
106106
view.setUrl(this.templateUrl + "/ssedata.html");
107107
view.setCharset(StandardCharsets.UTF_8.displayName());
108108
view.setApplicationContext(this.context);
109-
view.render(Collections.singletonMap("flux.value", Flux.just("World", "Spring")),
109+
view.render(Collections.singletonMap("async.value", Flux.just("World", "Spring")),
110110
MediaType.TEXT_EVENT_STREAM, this.exchange)
111111
.block(Duration.ofSeconds(300));
112112
assertThat(this.exchange.getResponse().getBodyAsString()
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Hello
2-
{{#flux.value}}
2+
{{#async:value}}
33
{{.}}
4-
{{/flux.value}}
4+
{{/async:value}}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
{{#flux.value}}
1+
{{#async.value}}
22
event: message
33
data: {{.}}
44

55

6-
{{/flux.value}}
6+
{{/async.value}}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
{{#flux.value}}
1+
{{#async.value}}
22
event: message
33
{{#ssedata}}
44
{{.}}
55
{{/ssedata}}
6-
{{/flux.value}}
6+
{{/async.value}}

0 commit comments

Comments
 (0)