ckeditor / ckeditor4

The best enterprise-grade WYSIWYG editor. Fully customizable with countless features and plugins.
https://ckeditor.com/ckeditor-4
Other
5.79k stars 2.47k forks source link

CKEDITOR.event#fireOnce is fired multiple times #3012

Open Comandeer opened 5 years ago

Comandeer commented 5 years ago

Type of report

Bug

Provide detailed reproduction steps (if any)

  1. Open https://jsfiddle.net/Comandeer/7g3yq60o/
  2. Open console.
  3. Click the button below the editor several times.

Expected result

Actual result

Every click logs myEvent listener #<n>.

Other details

In fact current implementation of CKEDITOR.event#fireOnce is just incorrect. Instead of preventing the subsequent firing of the event, it just removes all listeners. So basically event is fired, yet there are no listeners to do any action. Adding new listener after fireOnce adds new array of listeners, allowing to omit whole mechanism.

f1ames commented 5 years ago

This behaviour is quite confusing IMHO. But it kind of works as described in the docs:

Fires an specific event in the object, releasing all listeners registered to that event. The same listeners are not called again on successive calls of it or of fire.

so listeners are released as @Comandeer described. And in the given example above, new listeners are attached every time so the same listeners are not called again. So for me it somehow seems that it was intended to work like this, but then it should not be called fireOnce. The method fireOnce should work as @Comandeer described above (firing same event only once for the given object).