Skip to content

Commit b64bfb2

Browse files
committed
feat: Refactor selector utility in index.js
- Update import statement to use the new queryElements utility from @cocreate/utils. - Replace instances of queryDocumentSelectorAll with queryElements, passing in the document, selector, and selector type. - Improve code readability and maintainability.
1 parent c33ba43 commit b64bfb2

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

Diff for: src/index.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/*globals CustomEvent, CoCreate*/
88
import observer from '@cocreate/observer';
99
import action from '@cocreate/actions';
10-
import { queryDocumentSelectorAll } from '@cocreate/utils';
10+
import { queryElements } from '@cocreate/utils';
1111

1212
// TODO: update to listen to document events, find closest action return
1313
function init() {
@@ -48,10 +48,10 @@ function selectShowHideEle(e) {
4848
if (value != '') {
4949
var show = opt.getAttribute('show');
5050
if (typeof show != 'undefined') {
51-
for (let el of queryDocumentSelectorAll(show))
51+
for (let el of queryElements({ element: document, selector: show, type: 'selector' }))
5252
el.setAttribute('hidden', '');
5353
if (opt.selected === true) {
54-
for (let el of queryDocumentSelectorAll(show))
54+
for (let el of queryElements({ element: document, selector: show, type: 'selector' }))
5555
el.removeAttribute('hidden');
5656
}
5757
}
@@ -74,12 +74,11 @@ function clickShowHideEle(e) {
7474

7575
show = radio.getAttribute('show');
7676

77-
for (let el of queryDocumentSelectorAll(show)) {
77+
for (let el of queryElements({ element: document, selector: show, type: 'selector' }))
7878
el.setAttribute('hidden', '');
79-
}
8079

8180
if (radio.checked) {
82-
for (let el of queryDocumentSelectorAll(show))
81+
for (let el of queryElements({ element: document, selector: show, type: 'selector' }))
8382
el.removeAttribute('hidden');
8483
}
8584
}
@@ -88,14 +87,14 @@ function clickShowHideEle(e) {
8887

8988
let updated_els = [];
9089

91-
for (let el of queryDocumentSelectorAll(show)) {
90+
for (let el of queryElements({ element: document, selector: show, type: 'selector' })) {
9291
if (el.hasAttribute('hidden')) {
9392
el.removeAttribute('hidden');
9493
updated_els.push(el);
9594
}
9695
}
9796

98-
for (let el of queryDocumentSelectorAll(hide)) {
97+
for (let el of queryElements({ element: document, selector: hide, type: 'selector' })) {
9998
let existEqual = false;
10099
for (let uel of updated_els) {
101100
if (el.isEqualNode(uel)) {

0 commit comments

Comments
 (0)