Skip to main content

I’m trying to use custom event publishing using skuid.events.publish and skuid.events.subscribe.  The basic event system is working, but I’m having problems getting the data argument to work.  If I publish with:


skuid.events.publish('my.custom.event', 'my argument')


I get an error during the publishing:


Uncaught TypeError: Function.prototype.apply: Arguments list has wrong type


If instead I publish using a generic object for the data parameter, such as:


skuid.events.publish('my.custom.event', {myarg: 'my argument'})


the publish works fine, and the subscribe handler gets called.  However, the data argument passed to the handler is ‘undefined’ rather than containing my custom object.  My handler looks something like this:


skuid.events.subscribe('my.custom.event', function(data) { console.log(data); });


Any hints on what I might be doing wrong?

Thanks,

- Chris

Chris, 

Sorry this isn’t documented, we’ll add this, but you need to pass an array, like this:

skuid.events.publish(‘my.custom.event’, v‘my argument 1’,‘my argument 2’]);

Each Item in the Array will be converted into an argument handed to the subscriber function. We recommend just having one argument, and having it be a JavaScript object with as many properties as you need, but this is up to you.

For instance:



var eventParams = {<br>&nbsp; &nbsp;foo: 'bar',<br>&nbsp; &nbsp;name: 'Zach'<br>};<br>skuid.events.publish('my.custom.event', yeventParams, 'Mint Chocolate Chip']);


Then your subscriber function should do this:


skuid.events.subscribe('my.custom.event',function(eventParams, favoriteIceCream){<br>&nbsp; &nbsp; console.log('Foo: ' + eventParams.foo);<br>&nbsp; &nbsp; console.log('Name: ' + eventParams.name);<br>&nbsp; &nbsp; console.log('Favorite Ice Cream: ' + favoriteIceCream);<br>});




Phew - I was worried it was me!  Thanks for the writeup… I’ll give it a go.

- Chris


Just wanted to confirm that this method works great.  Thanks!


I have updated the skuid.events API documentation to clarify the expected data arguments.