[polari] js: Fix constructor parameters



commit 56efe1afcf77c1e52f36d89e67c0c816ccff1524
Author: Florian Müllner <fmuellner gnome org>
Date:   Fri Mar 18 19:50:30 2022 +0100

    js: Fix constructor parameters
    
    Commit 33368eba moved the initialization of properties that back
    GObject properties into fields, because in subclasses `this` only
    becomes available after chaining up with `super()`.
    
    However fields don't work in that case, because they are applied
    right before the `super()` call returns, which means they override
    the values that were passed to the GObject constructor.
    
    In cases where we don't need any special handling in getters or
    setters, we can remove the backing variable altogether and rely
    on automatic accessors.
    
    In other cases we can add the CONSTRUCT flag to force the setter
    to run with the default value.
    
    In either case, we can get rid of the fields.
    
    Part-of: <https://gitlab.gnome.org/GNOME/polari/-/merge_requests/248>

 src/appNotifications.js |  7 ++-----
 src/chatView.js         | 21 ++-------------------
 src/connections.js      | 18 +-----------------
 src/entryArea.js        |  4 ----
 src/mainWindow.js       |  7 ++-----
 src/userList.js         |  6 ++----
 6 files changed, 9 insertions(+), 54 deletions(-)
---
diff --git a/src/appNotifications.js b/src/appNotifications.js
index 6e591826..0c26aecf 100644
--- a/src/appNotifications.js
+++ b/src/appNotifications.js
@@ -151,17 +151,14 @@ class MessageInfoBar extends Gtk.InfoBar {
     static [GObject.properties] = {
         'title': GObject.ParamSpec.string(
             'title', 'title', 'title',
-            GObject.ParamFlags.READWRITE,
+            GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT,
             ''),
         'subtitle': GObject.ParamSpec.string(
             'subtitle', 'subtitle', 'subtitle',
-            GObject.ParamFlags.READWRITE,
+            GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT,
             ''),
     };
 
-    _title = '';
-    _subtitle = '';
-
     constructor(params) {
         let defaultParams = {
             show_close_button: true,
diff --git a/src/chatView.js b/src/chatView.js
index 53da3931..f361f7fd 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -51,17 +51,14 @@ class TextView extends Gtk.TextView {
     static [GObject.properties] = {
         'indent-width-chars': GObject.ParamSpec.uint(
             'indent-width-chars', 'indent-width-chars', 'indent-width-chars',
-            GObject.ParamFlags.READWRITE,
+            GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT,
             0, GLib.MAXUINT32, 0),
         'indext-spacing': GObject.ParamSpec.uint(
             'indent-spacing', 'indent-spacing', 'indent-spacing',
-            GObject.ParamFlags.READWRITE,
+            GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT,
             0, GLib.MAXUINT32, 0),
     };
 
-    _indentWidthChars = 0;
-    _indentSpacing = 0;
-
     constructor(params) {
         super(params);
 
@@ -222,20 +219,6 @@ class ButtonTag extends Gtk.TextTag {
         'popup-menu': { param_types: [GObject.TYPE_DOUBLE, GObject.TYPE_DOUBLE] },
     };
 
-    _hover = false;
-
-    get hover() {
-        return this._hover;
-    }
-
-    set hover(hover) {
-        if (this._hover === hover)
-            return;
-
-        this._hover = hover;
-        this.notify('hover');
-    }
-
     clicked(...coords) {
         this.emit('clicked', ...coords);
     }
diff --git a/src/connections.js b/src/connections.js
index 81bcfed3..3f8cf6a7 100644
--- a/src/connections.js
+++ b/src/connections.js
@@ -87,8 +87,6 @@ class ConnectionsList extends Gtk.ScrolledWindow {
         'account-selected': {},
     };
 
-    _favoritesOnly = false;
-
     constructor(params) {
         super(params);
 
@@ -144,20 +142,6 @@ class ConnectionsList extends Gtk.ScrolledWindow {
         });
     }
 
-    // eslint-disable-next-line camelcase
-    get favorites_only() {
-        return this._favoritesOnly;
-    }
-
-    // eslint-disable-next-line camelcase
-    set favorites_only(favsOnly) {
-        if (this._favoritesOnly === favsOnly)
-            return;
-
-        this._favoritesOnly = favsOnly;
-        this.notify('favorites-only');
-    }
-
     setFilter(filter) {
         if (!Utils.updateTerms(this._filterTerms, filter))
             return;
@@ -199,7 +183,7 @@ class ConnectionsList extends Gtk.ScrolledWindow {
         let usedNetworks = accounts.filter(a => a.predefined).map(a => a.service);
 
         this._networksManager.networks.forEach(network => {
-            if (this._favoritesOnly &&
+            if (this.favoritesOnly &&
                 !this._networksManager.getNetworkIsFavorite(network.id))
                 return;
 
diff --git a/src/entryArea.js b/src/entryArea.js
index ce6154c3..3683442e 100644
--- a/src/entryArea.js
+++ b/src/entryArea.js
@@ -6,7 +6,6 @@ import GObject from 'gi://GObject';
 import Gtk from 'gi://Gtk';
 import Tp from 'gi://TelepathyGLib';
 
-import { MAX_NICK_CHARS } from './chatView.js';
 import { DropTargetIface, gtypeFromFormats } from './pasteManager.js';
 import IrcParser from './ircParser.js';
 import TabCompletion from './tabCompletion.js';
@@ -113,8 +112,6 @@ class NickPopover extends Gtk.Popover {
         'nick-changed': {},
     };
 
-    _nick = '';
-
     constructor() {
         super();
 
@@ -173,7 +170,6 @@ class EntryArea extends Gtk.Stack {
         return this.__nickPopover;
     }
 
-    _maxNickChars = MAX_NICK_CHARS;
     _nickChangedId = 0;
     _popoverClosedId = 0;
 
diff --git a/src/mainWindow.js b/src/mainWindow.js
index be9b6715..0d01f5d5 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -19,17 +19,14 @@ class FixedSizeFrame extends Gtk.Widget {
     static [GObject.properties] = {
         height: GObject.ParamSpec.int(
             'height', 'height', 'height',
-            GObject.ParamFlags.READWRITE,
+            GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT,
             -1, GLib.MAXINT32, -1),
         width: GObject.ParamSpec.int(
             'width', 'width', 'width',
-            GObject.ParamFlags.READWRITE,
+            GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT,
             -1, GLib.MAXINT32, -1),
     };
 
-    _height = -1;
-    _width = -1;
-
     constructor(params) {
         super({
             ...params,
diff --git a/src/userList.js b/src/userList.js
index ac048a7e..aa34c6c3 100644
--- a/src/userList.js
+++ b/src/userList.js
@@ -125,17 +125,15 @@ class UserDetails extends Gtk.Box {
     static [GObject.properties] = {
         'expanded': GObject.ParamSpec.boolean(
             'expanded', 'expanded', 'expanded',
-            GObject.ParamFlags.READWRITE,
+            GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT,
             false),
         'notifications-enabled': GObject.ParamSpec.boolean(
             'notifications-enabled', 'notifications-enabled', 'notifications-enabled',
-            GObject.ParamFlags.READWRITE,
+            GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT,
             false),
     };
 
-    _expanded = false;
     _initialDetailsLoaded = false;
-    _notificationsEnabled = false;
     _user = null;
 
     constructor(params = {}) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]