Skip to content

Draft: Add GObject.Object.regster, Gtk.Widget.register

Evan Welsh requested to merge ewlsh/register-type into master

Differences with GObject.registerClass

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 via this.get_template_child. Gtk.defineChildren and this.get_template_children are two proposed APIs to support the previous behavior.


class MyObject extends GObject.Object {



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

Merge request reports