After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 664897 - WithSignals parameter for Lang.Class
WithSignals parameter for Lang.Class
Status: RESOLVED FIXED
Product: gjs
Classification: Bindings
Component: general
unspecified
Other All
: Normal enhancement
: ---
Assigned To: gjs-maint
gjs-maint
Depends on:
Blocks:
 
 
Reported: 2011-11-27 03:20 UTC by Frederik Zipp
Modified: 2017-02-16 04:53 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch to support optional WithSignals parameter in Lang.Class definitions (1.32 KB, patch)
2011-11-27 03:20 UTC, Frederik Zipp
none Details | Review
signals: Add WithSignals interface (2.44 KB, patch)
2017-01-06 05:00 UTC, Philip Chimento
committed Details | Review

Description Frederik Zipp 2011-11-27 03:20:33 UTC
Created attachment 202220 [details] [review]
Patch to support optional WithSignals parameter in Lang.Class definitions

Currently the code to add signal support to a class is hidden below the class definition:

const Signals = imports.signals;

const Foo = new Lang.Class({
    Name: 'Foo',
    Extends: Bar,

    // ...
});
Signals.addSignalMethods(Foo.prototype);

-------------------------------------------------------

The proposed patch enables an optional boolean 'WithSignals' parameter for class definitions to add signal support:

const Foo = new Lang.Class({
    Name: 'Foo',
    Extends: Bar,
    WithSignals: true,

    // ...
});

The signal awareness of the class is now easily visible at the top of the class definition and the import statement is no longer necessary.


A more general approach would be mixins:

const Foo = new Lang.Class({
    Name: 'Foo',
    Extends: Bar,
    Mixins: [Signals.SignalAware],

    // ...
});
Comment 1 Jasper St. Pierre (not reading bugmail) 2011-11-27 03:30:12 UTC
I was considering doing this with the Mixins approach, only using MooTools's vernacular of "Implements":

const Foo = new Lang.Class9{
    Name: 'Foo',
    Extends: Bar,
    Implements: [Signals.Signals]
});
Comment 2 Frederik Zipp 2011-11-27 08:59:58 UTC
(In reply to comment #1)
> I was considering doing this with the Mixins approach, only using MooTools's
> vernacular of "Implements":
> 
> const Foo = new Lang.Class9{
>     Name: 'Foo',
>     Extends: Bar,
>     Implements: [Signals.Signals]
> });

It's probably a good idea to stay close to the MooTools original. On the other hand 'Implements' reads as if the class definition provided the implementation on its side and as if Signals.Signals was only an empty interface stub. So I throw in another possible name for consideration: 'Includes' (Ruby also uses 'include' for mixins).
Comment 3 Philip Chimento 2017-01-06 05:00:37 UTC
Created attachment 342999 [details] [review]
signals: Add WithSignals interface

This is an alternative to using Signals.addSignalMethods(). A class can
implement Signals.WithSignals to get the signal methods built in.
Comment 4 Philip Chimento 2017-01-06 05:02:08 UTC
Now that we have interfaces, this is pretty easy to do, as "Implements: [Signals.WithSignals]". I don't really use signals on non-GObjects so I don't know if this would actually be used, would people find this useful?
Comment 5 Cosimo Cecchi 2017-02-15 18:14:05 UTC
Review of attachment 342999 [details] [review]:

This looks good to me; I don't think it makes a lot of difference, but the interface feels like a more natural match than what we had before.
Comment 6 Philip Chimento 2017-02-16 04:52:59 UTC
Attachment 342999 [details] pushed as 66d531a - signals: Add WithSignals interface