-
Notifications
You must be signed in to change notification settings - Fork 4
/
censor.mjs
34 lines (28 loc) · 902 Bytes
/
censor.mjs
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
/**
* Use this to filter out any of Mithril's magic attributes while still keeping
* your interfaces as unrestrictive as possible.
*/
// Note: this avoids as much allocation and overhead as possible.
const hasOwn = {}.hasOwnProperty
const magic = [
"key", "oninit", "oncreate", "onbeforeupdate", "onupdate",
"onbeforeremove", "onremove",
]
export default function censor(attrs, extras) {
const excludeSet = new Set(magic)
if (extras != null) {
for (const item of extras) excludeSet.add(item)
}
for (let i = 0; i < exclude.length; i++) {
if (hasOwn.call(attrs, exclude[i])) {
const result = {}
for (const key in attrs) {
if (hasOwn.call(attrs, key) && !excludeSet.has(key)) {
result[key] = attrs[key]
}
}
return result
}
}
return attrs
}