amplify icon indicating copy to clipboard operation
amplify copied to clipboard

Add the topic to the callback method before executing the callback

Open dcneiner opened this issue 13 years ago • 12 comments

This allows the developer to access the current topic being handled by the callback without breaking existing implementations of amplify pub/sub. The example in the readme shows how to access this new property.

Also update the readme to clarify that multiple topics can be subscribed in a single subscribe call.

dcneiner avatar Apr 23 '12 17:04 dcneiner

Other than the two tiny readme comments, this looks good to me. I'll leave it open for a bit to allow discussion.

scottgonzalez avatar Apr 23 '12 17:04 scottgonzalez

Glad to see this going in. I think this is a win for amplify users!

ifandelse avatar Apr 23 '12 18:04 ifandelse

+1 Doug and I had a discussion about this earlier today. My suggestion was to add topic to amplify so amplify.topic would be how you'd access it.

RedWolves avatar Apr 23 '12 18:04 RedWolves

@RedWolves I like that idea, probably more than the one in this PR.

scottgonzalez avatar Apr 23 '12 18:04 scottgonzalez

I am in favor of that method as well. Should it be amplify.topic or amplify.currentTopic? Also, @RedWolves do you want to submit a separate pull request – or should I update this one to reflect using amplify instead of the callback?

dcneiner avatar Apr 23 '12 18:04 dcneiner

To clarify, I think using a global variable like this emphasizes the transitory nature of being able to access it. "If you don't reference it during the callback, it won't be there when you need it". I think that would be easier to understand with this approach vs. local callback variables.

dcneiner avatar Apr 23 '12 18:04 dcneiner

Yeah I'll work on a pull request tonight and submit it. do we want to do .topic or .currentTopic?

RedWolves avatar Apr 23 '12 18:04 RedWolves

I like both for different reasons. topic is shorter. currentTopic might be clearer.

I vote for topic.

dcneiner avatar Apr 23 '12 19:04 dcneiner

I'm fine with either.

scottgonzalez avatar Apr 23 '12 19:04 scottgonzalez

I'm not a big fan of amplify.topic. It doesn't sit well with me that you'd have to access an API outside of the current context to determine context. The topic is very specific to the handler being triggered and should be associated as much. (Unless I'm misunderstanding)

jdsharp avatar Apr 23 '12 21:04 jdsharp

I put this together the other night https://gist.github.com/8af1ca8a678bcbe4e19c I have to agree with JD ... now that I see it implemented I am not a fan of the approach. Personally, I am still in favor of my first pull request (#47) with attaching topic to the end of args. Seems like any issues that arise could be defeated with documentation.

RedWolves avatar Apr 25 '12 20:04 RedWolves

Since this PR is well out of date, and given theat we no longer have docs in the README, I'm inclined to port this one-line change to a new PR, with the test, and open a separate issue on the documentation site.

Any concerns there @dcneiner?

jakerella avatar Aug 14 '14 15:08 jakerella