Draft: Add GObject.Object.regster, Gtk.Widget.register
GObject.registerClass
Differences with GObject.registerClass
was designed as a decorator or wrapped function which would transform a passed class, .register()
is designed to have no side-effects on the instance and generally follow a "what you see is what you get" pattern. The API is designed to be simpler to use with current JavaScript features such as class fields.
There are two primary differences:
- Accessors are not automatically generated. Instead of auto-generating accessors with camel and underscore variants,
register()
class only binds to existing getters/setters.this.bindPropertyFields()
is a proposed API to support binding properties to instance-level fields. - Gtk.Widget children are not defined automatically. They are still initialized on the template. Instead,
register()
supports loading children viathis.get_template_child
.Gtk.defineChildren
andthis.get_template_children
are two proposed APIs to support the previous behavior.
Example
class MyObject extends GObject.Object {
}
MyObject.register();
Proposed API Additions
namespace Gtk {
export class Widget {
static register({ CssName, Properties, Signals, ... }): void;
}
}
namespace GObject {
export class Object {
static register({ Properties, Signals, ... }): void;
}
}
Edited by Evan Welsh