Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Introduced ObservableMixin#decorate() and support for fire()'s return values #163

Merged
merged 5 commits into from
Jun 13, 2017

Conversation

Reinmar
Copy link
Member

@Reinmar Reinmar commented Jun 8, 2017

Suggested merge commit message (convention)

Feature: Introduced ObservableMixin#decorate() and support for setting EmitterMixin#fire()'s return value by listeners. Closes ckeditor/ckeditor5#4958.

@Reinmar Reinmar requested a review from pjasiun June 8, 2017 10:18
*
* @param {String} ...methodNames Names of the methods to decorate.
*/
decorate( ...methodNames ) {
Copy link

Choose a reason for hiding this comment

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

I would keep it simple: we don't expect many methods to be decorated at the same time, so I don't find it needed to add handling multiple methods at the same time by this function. Also, it would be a problem if we will want to add some parameters to it in the future.

Copy link
Member Author

Choose a reason for hiding this comment

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

I actually took that into consideration. I think that if we'd add options it would become an object anyway:

decorate( { name: 'foo', how: 'bar' } )

But perhaps you're right that support for decorating multiple methods at once is an overkill. I'll remove that.

@@ -135,6 +135,9 @@ const EmitterMixin = {
* the priority value the sooner the callback will be fired. Events having the same priority are called in the
* order they were added.
* @param {Object} [options.context] The object that represents `this` in the callback. Defaults to the object firing the event.
* @returns By default the method returns `undefined`. However, the return value can be changed by listeners
* through modification of the {@link module:utils/emitterinfo~EmitterInfo#return}'s value (the event info
* is the first param of every callback).
Copy link

@pjasiun pjasiun Jun 9, 2017

Choose a reason for hiding this comment

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

It should be docs for fire not for listenTo. However, a comment here and next to the on method about how callback can set the return value would be fine (most probably a link to the return property docs.

Copy link
Member Author

Choose a reason for hiding this comment

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

Haha. Good catch.

@Reinmar
Copy link
Member Author

Reinmar commented Jun 12, 2017

When working on tests for ckeditor5-core I stumbled upon a case where I tried to spy on command.execute and the command was created using new Command(). This got me an ugly error because command.execute did exist, but the originalMethod property inside observablemixin.js didn't. That's because I forgot to implement the execute() method.

To avoid such issues I'll make decorate() throw an error.

@Reinmar
Copy link
Member Author

Reinmar commented Jun 12, 2017

Back on review.

@Reinmar
Copy link
Member Author

Reinmar commented Jun 12, 2017

One last doubt – the decorate() method could be moved to EmitterMixin because it only requires the event system. It semantically makes more sense in ObservableMixin but it means that classes may need to start mixing it instead of EmitterMixin to get this functionality (it was a case for DataController).

@szymonkups szymonkups closed this Jun 13, 2017
@szymonkups szymonkups deleted the t/162 branch June 13, 2017 11:32
@szymonkups szymonkups restored the t/162 branch June 13, 2017 11:42
@szymonkups
Copy link
Contributor

Wrong button :D

@szymonkups szymonkups reopened this Jun 13, 2017
@szymonkups szymonkups merged commit 377c875 into master Jun 13, 2017
@szymonkups szymonkups deleted the t/162 branch June 13, 2017 11:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement ObservableMixin.decorate()
3 participants