Skip to content

Commit 1cfe598

Browse files
Push once and prepend
1 parent 112ccde commit 1cfe598

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/index.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,24 @@ function setFilledSlots(currentNode, slots, {slot}) {
231231
*/
232232
function processPushes(tree, content, {push}) {
233233
match.call(tree, {tag: push}, pushNode => {
234+
if (!pushNode.attrs || !pushNode.attrs.name) {
235+
throw new Error(`[components] Push <${push}> tag must have an attribute "name".`);
236+
}
237+
234238
if (!content[pushNode.attrs.name]) {
235239
content[pushNode.attrs.name] = [];
236240
}
237241

238-
content[pushNode.attrs.name].push(pushNode.content);
242+
const pushContent = render(pushNode.content);
243+
244+
if (typeof pushNode.attrs.once === 'undefined' || !content[pushNode.attrs.name].includes(pushContent)) {
245+
if (typeof pushNode.attrs.prepend === 'undefined') {
246+
content[pushNode.attrs.name].push(pushContent);
247+
} else {
248+
content[pushNode.attrs.name].unshift(pushContent);
249+
}
250+
}
251+
239252
pushNode.tag = false;
240253
pushNode.content = null;
241254

0 commit comments

Comments
 (0)