Here is some code that will do that.
It takes a similar approach to the quesion you linked, but since there is no G_OBJECT_GET_CLASS()
in GJS, it uses GIRepository
instead -- which is an extra dependency that you need compared to the C solution.