sdsweb / note

Note is a simple and easy to use widget for editing bits of text, live, in your WordPress front-end Customizer.
GNU General Public License v2.0
19 stars 5 forks source link

Not to call widget update() on every letter change? #14

Closed lumberman closed 8 years ago

lumberman commented 8 years ago

Hi there, You created amazing plugin.

I'm wondering why you do call Note widget update function on every letter change? It's very strange to see the content saved to the database even before user clicks "Save Changes" in the customizer.

Do you have any idea on how to change it to the way the standard Text Widget works: if you didn't click "Save Changes" in the customizer all your changes get replaced with the saved data from the database?

Thanks for your time.

scottsousa commented 8 years ago

Hi @pavot,

Thank you for the kind words on the plugin.

The note-widget-update event that you see being called is actually an event that we are triggering within Note (separate from core WordPress updating the widget). We are currently debounce()-ing that call every 300ms. Basically the callback function is called, but only after 300ms of inactivity when editing a Note Widget. This is to prevent note-widget-update from being called after every single character, while still sending the updates over to the Customizer in a timely manor to make sure changes can be saved for "faster" users.

Here is where we hooked the debounced callback to TinyMCE editor changes in the Previewer. This callback sends note-widget-update to the Customizer where we have a listener for that event in place.

When that event is sent, this logic is triggered which calls the core updateWidget() function. That core function submits an AJAX request to get the new/updated widget form, but it does not actually save widget data until the "Save Changes" button is clicked.

Effectively our Note Widget functions similarly to the standard Text Widget (there is a textarea that is updated in the widget form when content is edited within a Note Widget). However, since we are sending data from the Previewer to the Customizer, it is slightly different (reversed), but we're using core Customizer functionality where we can.

I just ran a test this morning to verify and widget content was not updated on the front-end (which I opened in a new tab) until I pressed "Save Changes".

I hope this clears things up a bit. Let me know if you have any other questions or if I am missing something.

Scott

scottsousa commented 8 years ago

Hi @pavot, I'll be closing this issue for now.

Thank you for your feedback, Scott