0

How to use subscribeTo

Hi Guys

I'm pretty new on this Yahoo TV programming, I checked the sample code and find it seems we can use "subscribeTo" method to add an event listener:
CODE
EventHandlers.onApplicationStartup.subscribeTo(KONtx.application, ['onApplicationStartup'], EventHandlers);


I did do a lot of Google but cannot find too much about how to use "subscribeTo" method, is this something new to Yahoo TV or Javascript language itself? Can any body give me a clear explanation, thank you guys!

Cheers
Ramon

by
1 Reply
  • QUOTE (ramon.wang @ May 23 2011, 09:52 PM) <{POST_SNAPBACK}>
    OK, i found the answer, it's some Prototype Extensions to the native JS: "Function.subscribeTo".


    Located in the KONtx API Reference

    http://developer.yahoo.com/connectedtv/kon...idget_KONtx.pdf


    Function.subscribeTo()
    subscribes a method to a list of events

    Synopsis

    Function subscribeTo(Object publishingObject, MixedType eventTypes, Object bindingScope)

    Parameters

    The parameter publishingObject is the object on which you listen to events. The parameter
    eventTypes is a single String event type or an Array of event types to which to subcribe this
    Function. The optional parameter bindingScope is the Object to which this Function will be rebound
    before subscribing.

    Returns a Function which is the final method as subscribed.

    Description

    Subscribes the given events to the publishing object.

    Example
    CODE
    var ToolboxSnippetView = new KONtx.Class({
    ClassName: 'ToolboxSnippetView',
    Extends: KONtx.system.SnippetView,
    initialize: function() {
    this.parent();
    this._handleActivateSnippet.subscribeTo(this, ['onActivateSnippet'], this);
    },
    _handleActivateSnippet: function(event) {
    if(this.config.data && this.config.data.destinationId) {
    event.preventDefault();
    event.stopPropagation();
    KONtx.application.setHostResultToViewId(event, this.config.data.destinationId);
    }
    },
    createView: function() {
    }
    });
    0

Recent Posts

in Getting Started / Beginners - Yahoo! TV Widgets