Skip to content
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

Deprecate unused evented utility #3125

Merged
merged 7 commits into from
Oct 31, 2021
Merged
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
18 changes: 18 additions & 0 deletions js/src/common/utils/evented.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
/**
* The `evented` mixin provides methods allowing an object to trigger events,
* running externally registered event handlers.
*
* @deprecated v1.2, to be removed in v2.0
*/

import fireDebugWarning from '../helpers/fireDebugWarning';

const deprecatedNotice =
'The `evented` util is deprecated and will be removed in Flarum 2.0. For more info, please see https://github.com/flarum/core/issues/2547';

export default {
/**
* Arrays of registered event handlers, grouped by the event name.
Expand All @@ -19,6 +27,8 @@ export default {
* @protected
*/
getHandlers(event) {
fireDebugWarning(deprecatedNotice);

this.handlers = this.handlers || {};

this.handlers[event] = this.handlers[event] || [];
Expand All @@ -34,6 +44,8 @@ export default {
* @public
*/
trigger(event, ...args) {
fireDebugWarning(deprecatedNotice);

this.getHandlers(event).forEach((handler) => handler.apply(this, args));
},

Expand All @@ -44,6 +56,8 @@ export default {
* @param {function} handler The function to handle the event.
*/
on(event, handler) {
fireDebugWarning(deprecatedNotice);

this.getHandlers(event).push(handler);
},

Expand All @@ -55,6 +69,8 @@ export default {
* @param {function} handler The function to handle the event.
*/
one(event, handler) {
fireDebugWarning(deprecatedNotice);

const wrapper = function () {
handler.apply(this, arguments);

Expand All @@ -71,6 +87,8 @@ export default {
* @param {function} handler The function that handles the event.
*/
off(event, handler) {
fireDebugWarning(deprecatedNotice);

const handlers = this.getHandlers(event);
const index = handlers.indexOf(handler);

Expand Down