forked from staylor/react-helmet-async
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelmetData.js
48 lines (42 loc) · 1.14 KB
/
HelmetData.js
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import mapStateOnServer from './server';
const instances = [];
export function clearInstances() {
instances.length = 0;
}
export default class HelmetData {
instances = [];
value = {
setHelmet: serverState => {
this.context.helmet = serverState;
},
helmetInstances: {
get: () => (this.canUseDOM ? instances : this.instances),
add: instance => {
(this.canUseDOM ? instances : this.instances).push(instance);
},
remove: instance => {
const index = (this.canUseDOM ? instances : this.instances).indexOf(instance);
(this.canUseDOM ? instances : this.instances).splice(index, 1);
},
},
};
constructor(context, canUseDOM = typeof document !== 'undefined') {
this.context = context;
this.canUseDOM = canUseDOM;
if (!canUseDOM) {
context.helmet = mapStateOnServer({
baseTag: [],
bodyAttributes: {},
encodeSpecialCharacters: true,
htmlAttributes: {},
linkTags: [],
metaTags: [],
noscriptTags: [],
scriptTags: [],
styleTags: [],
title: '',
titleAttributes: {},
});
}
}
}