Skip to content

Commit

Permalink
improve elementStruct usage
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislav-atr committed Oct 7, 2022
1 parent ade2862 commit 04e1d2e
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/scriptlets/trusted-click-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,14 @@ export function trustedClickElement(source, selectors, extraMatch = '', delay =
* Elements stubs should not be removed from array to keep track
* of their order and clicked 'state'
*/
const elementStruct = {
element: undefined,
clicked: false,
const createElementObj = (element) => {
return {
element,
clicked: false,
};
};
const elementsSequence = Array(selectorsSequence.length).fill(elementStruct);

const elementsSequence = Array(selectorsSequence.length).fill(createElementObj());

const clickElementsBySequence = () => {
for (let i = 0; i < elementsSequence.length; i += 1) {
Expand All @@ -164,7 +167,7 @@ export function trustedClickElement(source, selectors, extraMatch = '', delay =

const handleElement = (element, i) => {
// eslint-disable-next-line prefer-object-spread
const elementObj = Object.assign({}, elementStruct, { element });
const elementObj = createElementObj(element);
elementsSequence[i] = elementObj;

if (canClick) {
Expand Down

0 comments on commit 04e1d2e

Please sign in to comment.