-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtitle.tsx
More file actions
31 lines (29 loc) · 1.01 KB
/
title.tsx
File metadata and controls
31 lines (29 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { createEffect, onCleanup } from 'solid-js';
import { createMutable } from 'solid-js/store';
const originalTitle = document.title;
const titleStack = createMutable([() => originalTitle]);
createEffect(() => {
/* console.debug('Updating title stack', titleStack); */
document.title = titleStack.map((x) => x()).join(' :: ');
});
interface TitleProps {
children: string;
}
export const Title = (props: TitleProps) => {
/* console.debug('Adding to title stack', props.children); */
const getTitle = () => props.children;
// titleStack is consumed in a reactive context, so this is valid
// eslint-disable-next-line solid/reactivity
titleStack.push(getTitle);
onCleanup(() => {
/* console.debug(`Removing from title stack`, props.children); */
const stackEntryIndex = titleStack.indexOf(getTitle);
if (stackEntryIndex === -1) {
throw new Error(
`Title stack entry for ${props.children} could not be found`,
);
}
titleStack.splice(stackEntryIndex, 1);
});
return <></>;
};