Skip to content

Instantly share code, notes, and snippets.

@desiderantes
Created August 13, 2017 05:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save desiderantes/a73da8b8068455a2696e7b7d24dd5378 to your computer and use it in GitHub Desktop.
Save desiderantes/a73da8b8068455a2696e7b7d24dd5378 to your computer and use it in GitHub Desktop.
Emit custom notify in Vala
using GLib;
public class TestClass : GLib.Object {
public string test1 {get;set;default = "test1";}
//Ths one won't emit on assignment
[CCode (notify = false)]
public string test2 {get;set;default = "test2";}
public static void main (string[] args) {
var test = new TestClass ();
test.notify["test1"].connect (() => GLib.print ("test1 notification\n"));
test.notify["test2"].connect (() => GLib.print ("test2 notification\n"));
test.test1 = "Ahoy";
test.test2 = "Újale";
test.test2 = "Ajúa";
ParamSpec pspec = ((ObjectClass) typeof (TestClass).class_ref ()).find_property ("test2");
GLib.print ("First try, will not work %s\n", pspec.name);
test.notify(pspec);
GLib.print ("second one, this is how it works");
test.notify["test2"] (pspec);
return;
}
}
@matzipan
Copy link

Thanks a lot. I didn't know this is possible and I used it to implement notifications on a derived property (no setter).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment