Search code examples
javascriptajaxyuiyui-datasource

How do you hook an event to a datasource in YUI?


http://developer.yahoo.com/yui/datasource/#events

I'm trying to use the responseParseEvent but I don't know how to hook into into my datasource object because YUI doesn't provide any examples.

Sidenote: Has anybody else noticed this with YUI? That their documentation doesn't contain nearly as many examples as jQuery?


Solution

  • instance.subscribe(eventName, callback) is a standard signature for most events across components in YUI 2.

    myDataSource.subscribe('responseParseEvent', function (e) {
        /*
         * available properties:
         *   e.request
         *   e.response
         *   e.callback
         *   e.caller
         */
    });
    

    YUI 3 follows a similar convention, but uses the methods on() and after()

    myYUI3DataSource.on('data', function (e) { ... });