Skip to content

Conversation

@muhammedjafer
Copy link
Contributor

No description provided.

Copy link
Owner

@dasundev dasundev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll keep this PR open until someone else provides their opinion on it.

clearTimeout(timeout);
}
timeout = setTimeout(function() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is the best way to handle this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why??

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because you are using a timeout.

Copy link

@ghabriel25 ghabriel25 Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dasundev Just use lodash debounce

quill.on('text-change', _.debounce( () => {
    let value = quill.root.innerHTML;
    @this.set('value', value);
}, 1000));

lodash comes along with quill

@muhammedjafer
Copy link
Contributor Author

muhammedjafer commented May 1, 2024

i improved the code to use debouncing directly,

`quill.root.innerHTML = $wire.get('value');

function debounce(func, delay) {
    let timeout;
    return function() {
        clearTimeout(timeout);
        timeout = setTimeout(() => func.apply(this, arguments), delay);
    };
}

// Debounced function to handle text change
const handleTextChangeDebounced = debounce(() => {
    const value = quill.root.innerHTML;
    @this.set('value', value);
}, 1000);

quill.on('text-change', handleTextChangeDebounced);

quill.on('selection-change', () => {
    if (quill.hasFocus()) {
        handleTextChangeDebounced();
    }
});`

@muhammedjafer
Copy link
Contributor Author

i found another quill livewire package, they use debouncing also, and they even handle the image upload into their text editor, have a look =>>> https://github.com/joelwmale/livewire-quill/blob/master/resources/views/livewire/livewire-quill.blade.php

@Schrolli91
Copy link

Why not use the livewire own debounce?
https://livewire.laravel.com/docs/wire-model#customizing-the-debounce

This will send an request after time (n) no further inputs are made.
<input type="text" wire:model.live.debounce.250ms="title">

@muhammedjafer
Copy link
Contributor Author

.debounce.250ms

the problem with this package is not the .live of livewire, the quill editor fires an event by names of (text-change) each time the user types into the editor and with that the set method is used so each time the value will be set as the user types into the editor look at the code of the package:

quill.on('text-change', function () {
        let value = quill.root.innerHTML;
        @this.set('value', value);
    });

@Balerka
Copy link

Balerka commented Sep 11, 2024

// Создаем переменную для хранения таймера
let debounceTimer;

quill.on('text-change', function () {
    // Очищаем предыдущий таймер
    clearTimeout(debounceTimer);

    // Запускаем новый таймер с задержкой
    debounceTimer = setTimeout(function () {
        let value = quill.root.innerHTML;
        @this.set('value', value);
    }, 500); // задержка 500 мс (можно изменить при необходимости)
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants