Skip to content

API Reference / @gtkx/runtime / newObjectWithProperties

Function: newObjectWithProperties()

newObjectWithProperties<T>(gtype, props, wrapper): T

Defined in: packages/runtime/dist/object.d.ts:48

Constructs a new GObject of the given type, setting the supplied construct properties, and binds wrapper to it. A property the wrapper's class declares through registerConstructProperties is marshalled through its descriptor; any other one is marshalled through the GObject.ParamSpec the type installs under that name, dashed or camelCased, and is skipped when the type installs none. A value that ParamSpec would refuse throws before GObject sees it: a TypeError for a read-only property and for a value of a type the property cannot hold, and a RangeError for a value the ParamSpec rejects. A value marshalled through a declared descriptor is converted rather than checked, so a null handed to a numeric one of those lands 0 rather than being refused, and a number is fitted to the property first, as coerceObjectProperty does: truncated toward zero for a whole-number property and clamped to the range its GObject.ParamSpec allows. Properties whose value is undefined are skipped. A type registered with registerClass binds the wrapper before its constructed slot runs, so an override of that slot already sees a usable instance. When construction returns an object that already has a wrapper — it reached JavaScript and was wrapped before g_object_new returned, for example a Gtk.Window observed through the toplevels list — that existing wrapper is returned instead of binding wrapper, so both references stay one object.

Type Parameters

T

T extends object

Parameters

gtype

bigint

The GType of the object to construct.

props

object

Property names mapped to the values to set them to.

wrapper

T

The wrapper instance to bind to the new object.

Returns

T

The wrapper bound to the constructed object: wrapper itself, or the wrapper the object already had.

Released under the MPL-2.0 License.