Talking between 2 components

52 views
Skip to first unread message

Z. B.

unread,
Jan 10, 2015, 8:09:43 PM1/10/15
to twitter...@googlegroups.com
Talking between 2 components...
That is request something and do something with the response...

What are my options? 

option #1:
component1 -> trigger('askForAnId')
component2 -> on('askForAnId', getId)
component2 -> trigger('replyWithId')
component1 -> on('replywithId')

A bit ugly, but it doesn't work out of component3,4,5,etc. want to also 'askForAnId' unless i have all components listen on 'replywithId' and set a key on the payload to filter who it's actually for

option #2:

send a 'callback' function along with the payload to be run, seems the most reasonable

What do you guys do?

Gabriel Pugliese

unread,
Jan 10, 2015, 9:31:24 PM1/10/15
to Z. B., twitter...@googlegroups.com
Are you triggering 'askForAnId' on document? All other components should listen for it on document too and it would work.

Cristiano Oliveira

unread,
Jan 15, 2015, 5:45:14 PM1/15/15
to twitter...@googlegroups.com
Ui components trigger where this.$node is and Data components trigger on doc.body
I also have a mixin `uniqueId` which adds a guid and sets this._id to that.
When the response comes back, I'll do :
onGetFooResponse: function (resp) {
  if (resp._id == this._id) return;
Reply all
Reply to author
Forward
0 new messages