-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwcs-microdata.js
41 lines (32 loc) · 1009 Bytes
/
wcs-microdata.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
import '../microtesia.js/lib/microtesia.js'
import { dedupeMixin } from '@open-wc/dedupe-mixin'
export const MicrodataMixin = dedupeMixin(
base =>
class extends base {
connectedCallback() {
if (super.connectedCallback) super.connectedCallback()
this.__updateMicrodata()
}
performUpdate() {
this.__updateMicrodata()
if (super.performUpdate) super.performUpdate()
}
__updateMicrodata() {
function filterProperty(property, value) {
if ((property === Array || property.type === Array) && !Array.isArray(value)) {
return [value]
} else {
return value
}
}
const microdata = parseMicrodata(this)[0]
for (const name in microdata) {
const value = microdata[name]
const property = this.constructor.properties[name]
if (property) {
this[name] = filterProperty(property, value)
}
}
}
}
)