GNOME Bugzilla – Bug 664897
WithSignals parameter for Lang.Class
Last modified: 2017-02-16 04:53:08 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], // ... });
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] });
(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).
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.
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?
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.
Attachment 342999 [details] pushed as 66d531a - signals: Add WithSignals interface