mikehostetler / amplify

AmplifyJS
http://amplifyjs.com
GNU General Public License v2.0
1.45k stars 143 forks source link

Issue #46 - Multiple topics documentation and 'topic' callback argument added #53

Closed RedWolves closed 12 years ago

RedWolves commented 12 years ago

Reading through @ifandelse's pull request (https://github.com/appendto/amplify/pull/47) I felt like we could solve the identifying the topic pretty easily and explored that approach in this pull request.

I've included the multiple topic documentation that @ifandelse started then extended amplify to include the passing of 'topic' as the last argument to the callback function, optional of course. here's the examples of how this would work:

amplify.subscribe( "lion kitty dog", function( data, topic ) {
    console.log( "The " + topic + " says '" + data.bar + "'." );
});

amplify.publish( "lion", { bar: "RAWR!" } );         // The lion says 'RAWR!'.
amplify.publish( "kitty", { bar: "meow" } );         // The kitty says 'meow'.
amplify.publish( "dog", { bar: "Woof!" } );          // The dog says 'Woof!'.

I've included tests and documentation for subscribing multiple topics and identifying the topic published.

scottgonzalez commented 12 years ago

We can't modify the published data as that will break anything that supports variable arguments.