vixalien / muzika

Elegant music streaming app
GNU General Public License v3.0
268 stars 17 forks source link

[Code] Use `bind-property` instead of property getters/setters #146

Open vixalien opened 4 months ago

vixalien commented 4 months ago

This is when you have properties that will sync to another object.

Instead of updating that object's property using getters/setters, you can use a simple bind_property.

Before:

  private _selection_mode = false;

  get selection_mode() {
    return this._selection_mode;
  }

  set selection_mode(value: boolean) {
    if (this.selection_mode == value) return;

    this._selection_mode = value;
    this._bar.selection_mode = value;
    this._playlist_item_view.selection_mode = value;

    this.notify("selection-mode");
  }

After:

    // selection-mode

    this.bind_property(
      "selection-mode",
      this._bar,
      "selection-mode",
      GObject.BindingFlags.SYNC_CREATE,
    );

    this.bind_property(
      "selection-mode",
      this._playlist_item_view,
      "selection-mode",
      GObject.BindingFlags.SYNC_CREATE,
    );