Skip to content

AMD modules and events #412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
turboteddy opened this issue Apr 29, 2013 · 5 comments
Closed

AMD modules and events #412

turboteddy opened this issue Apr 29, 2013 · 5 comments

Comments

@turboteddy
Copy link

I would be very thankful if you could provide an example in documentation on how to document events in the context of AMD modules (including the tags @event, @fires and @listens). Have tried numerous of combinations of syntax, but no result as expected... Hard to get my head around this one. E.g., what is the best way to document something like this?

/** @module a/b/c */
define(['dep1', 'dep2'], function (dep1, dep2) {
    return declare([...], {

       /**
         * This is the event handler
         * @listens event:eventname
         */
       myEventListener : function (event) {

       },

       /**
        * This is the description of the event 
        * @event description. 
        * @name a/b/c#event:eventname
        */
    };
});

...in combination with:

/** @module a/b/d */
define(['dep3', 'dep4'], function (dep3, dep4) {
    return declare([...], {

     /**
     * This function fires the event. 
     * @fires module:a/b/c#event:eventname
     */
     onSomething:function () {
        this.emit(eventname, {
             ...
        });
     }

    };
});

Any feedback / documentation would be highly appreciated!

@patocallaghan
Copy link

Did you manage to get this working? I'm having a similar issue.

@turboteddy
Copy link
Author

nope, @patocallaghan, I gave up. Hope this will become part of the documentation soon.

@micmath
Copy link
Contributor

micmath commented May 29, 2013

Using some of the examples in the unit test fixtures, I came up with the example below as an illustration. Is this useful?

/**
    Some description of the playground/monitor module.
    @module playground/monitor
 */
define('playground/monitor', [], function () {
    var exports = {
        /**
            @method module:playground/monitor.reportThrowage
            @listens module:hurler#snowball
         */
        reportThrowage: function (e) {
            this.log('snowball thrown: velocity ' + e.velocity);
        }
    };

    return exports;
});


/**
    Some description of the hurler module.
    @module hurler
 */
define('hurler', [], function () {
    /**
        Some description of snowball events.
        @event module:hurler#snowball
        @property {number} velocity
    */

    var exports = {
        /**
            @method module:hurler.attack
            @fires module:hurler#snowball
         */
        attack: function (e) {
            this.emit('snowball', { velocity: 10 });
        }
    };

    return exports;
});

@patocallaghan
Copy link

Thanks @micmath, It's kind of working now but I'll just have to rework some of my comments to make it work properly. Thanks for the tip about the tests.

@turboteddy have a look here and you may be able to reverse-engineer how the events work...

hegemonic added a commit to jsdoc/jsdoc.github.io that referenced this issue Nov 11, 2013
@hegemonic
Copy link
Contributor

Added to the @event page on Use JSDoc. I'll move part of the example to the new @listens page when I address jsdoc/jsdoc.github.io#25.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants