Skip to content

Instantly share code, notes, and snippets.

@scorredoira
Created June 10, 2018 08:41
Show Gist options
  • Save scorredoira/2d0053f82d7cc3ee2d52762ce6faadf7 to your computer and use it in GitHub Desktop.
Save scorredoira/2d0053f82d7cc3ee2d52762ce6faadf7 to your computer and use it in GitHub Desktop.

Events

    class MyWidget extends S.Widget {
        constructor(w: S.WidgetInfo) {
            super(w)

            this.sendEvent("load")
        }
    }

To receive events the class must expose a public method onEvent:

    class MyWidget extends S.Widget {
        constructor(w: S.WidgetInfo) {
            super(w)
        }

        onEvent(event: S.WidgetEvent) {
            switch (event.name) {
                case "load":
                    // do stuff
                    return;
            }
        }
    }

The event object:

    export interface WidgetEvent {
        name: string
        source: Widget
        asrgs?: any
    }

To make a widget listen to events in the declaration file:

"listeners": {
    "urlChange": "onURLChange"
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment