Skip to content

Commit 11189d4

Browse files
authored
Merge pull request #877 from Patternslib/pat-push-append
feat(pat push): Added the option to append the fetched content at the…
2 parents b29aa9d + 6e3c6dc commit 11189d4

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

src/pat/push/documentation.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ When an element is equipped with class="pat-push" and a push ID it will listen t
77
data-pat-push="push-id: message_counter; url: /message-counter">
88
Messages <sup class="counter digit-1">1</sup>
99
</a>
10+
11+
If you add the `mode: append` option, the fetched content will be appended to the element.

src/pat/push/index-push-messages.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<li>A <strong>new</strong> message</li>

src/pat/push/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,18 @@ <h2>push-id: message_counter2</h2>
4242
>
4343
messages <sup class="counter digit-1">1</sup>
4444
</div>
45+
46+
<h2>push-id: message_incoming; mode: append</h2>
47+
<div>
48+
If a message is sent through RabbitMQ on the "patternslib" exchange on the
49+
push_marker topic containing the message "message_incoming" the list below
50+
will be updated.
51+
<ul
52+
class="pat-push"
53+
data-pat-push="push-id: message_incoming; url: index-push-messages.html; mode: append"
54+
>
55+
<li>Old message</li>
56+
</ul>
57+
</div>
4558
</body>
4659
</html>

src/pat/push/push.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const logger = logging.getLogger("push");
88
export const parser = new Parser("push");
99
parser.addArgument("url", null);
1010
parser.addArgument("push-id", null);
11+
parser.addArgument("mode", "replace");
1112

1213
export default Base.extend({
1314
name: "push",
@@ -32,7 +33,11 @@ export default Base.extend({
3233
try {
3334
const response = await fetch(this.options.url);
3435
const data = await response.text();
35-
this.el.innerHTML = data;
36+
if (this.options.mode === "append") {
37+
this.el.insertAdjacentHTML("beforeend", data);
38+
} else {
39+
this.el.innerHTML = data;
40+
}
3641
} catch (e) {
3742
logger.error(
3843
`Could not fetch from ${this.options.url} on push-id ${this.options.pushId}.`

0 commit comments

Comments
 (0)