Skip to content

Commit 43eea51

Browse files
committed
fix: update observer observe param to type and and attributeName to attributeFilter
1 parent 1a8e388 commit 43eea51

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

src/index.js

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,43 @@
1-
import observer from '@cocreate/observer';
1+
import observer from "@cocreate/observer";
22

33
function init() {
4-
let elements = document.querySelectorAll("[background-color='random']");
5-
initElements(elements);
4+
let elements = document.querySelectorAll("[background-color='random']");
5+
initElements(elements);
66
}
77

88
function initElements(elements) {
9-
for (let el of elements) {
10-
el.style.backgroundColor = randomColor();
11-
}
9+
for (let el of elements) {
10+
el.style.backgroundColor = randomColor();
11+
}
1212
}
1313

1414
export function randomColor() {
15-
let defaultSaturation = 75;
16-
let defaultLightness = 58;
17-
let defaultAlpha = 1;
18-
let hash = Math.floor(Math.random() * (360));
19-
return 'hsla(' + hash + ', ' + defaultSaturation + '%, ' + defaultLightness + '%, ' + defaultAlpha + ')';
15+
let defaultSaturation = 75;
16+
let defaultLightness = 58;
17+
let defaultAlpha = 1;
18+
let hash = Math.floor(Math.random() * 360);
19+
return (
20+
"hsla(" +
21+
hash +
22+
", " +
23+
defaultSaturation +
24+
"%, " +
25+
defaultLightness +
26+
"%, " +
27+
defaultAlpha +
28+
")"
29+
);
2030
}
2131

2232
observer.init({
23-
name: 'CoCreateRandomColor',
24-
observe: ['addedNodes'],
25-
selector: '[background-color="random"]',
26-
callback: mutation => {
27-
init(mutation.target);
28-
}
33+
name: "CoCreateRandomColor",
34+
types: ["addedNodes"],
35+
selector: '[background-color="random"]',
36+
callback: (mutation) => {
37+
init(mutation.target);
38+
}
2939
});
3040

31-
3241
init();
3342

34-
3543
export default { randomColor };

0 commit comments

Comments
 (0)