Skip to content

Some performance optimizations.... #1248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 31 additions & 27 deletions src/pat/validation/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ class Pattern extends BasePattern {
);

this.initialize_inputs();
$(this.el).on("pat-update", () => {
$(this.el).on("pat-update", (e) => {
if (e.detail.pattern === "validation") {
// Don't reinitialize the inputs after a validation change.
return;
}
this.initialize_inputs();
});

Expand All @@ -78,32 +82,32 @@ class Pattern extends BasePattern {
...this.el.querySelectorAll(this.options.disableSelector),
];

for (const [cnt, input] of this.inputs.entries()) {
// Cancelable debouncer.
const debouncer = utils.debounce((e) => {
logger.debug("Checking input for event", input, e);
this.check_input({ input: input, event: e });
}, this.options.delay);

events.add_event_listener(
input,
"input",
`pat-validation--input-${input.name}--${cnt}--validator`,
(e) => debouncer(e)
);
events.add_event_listener(
input,
"change",
`pat-validation--change-${input.name}--${cnt}--validator`,
(e) => debouncer(e)
);
events.add_event_listener(
input,
"blur",
`pat-validation--blur-${input.name}--${cnt}--validator`,
(e) => debouncer(e)
);
}
// Cancelable debouncer.
const debouncer = utils.debounce((e) => {
const input = e.target;
logger.debug("Checking input for event", input, e);
this.check_input({ input: input, event: e });
}, this.options.delay);

events.add_event_listener(
this.el,
"input",
`pat-validation--input--validator`,
(e) => dom.is_input(e.target) && debouncer(e)
);
events.add_event_listener(
this.el,
"change",
`pat-validation--change--validator`,
(e) => dom.is_input(e.target) && debouncer(e)
);
events.add_event_listener(
this.el,
"blur",
`pat-validation--blur--validator`,
(e) => dom.is_input(e.target) && debouncer(e)
);

}

check_input({ input, event, stop = false }) {
Expand Down
Loading