topicid.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2014 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. goog.provide('goog.pubsub.TopicId');
  15. /**
  16. * A templated class that is used to register {@code goog.pubsub.PubSub}
  17. * subscribers.
  18. *
  19. * Typical usage for a publisher:
  20. * <code>
  21. * /** @type {!goog.pubsub.TopicId<!zorg.State>}
  22. * zorg.TopicId.STATE_CHANGE = new goog.pubsub.TopicId(
  23. * goog.events.getUniqueId('state-change'));
  24. *
  25. * // Compiler enforces that these types are correct.
  26. * pubSub.publish(zorg.TopicId.STATE_CHANGE, zorg.State.STARTED);
  27. * </code>
  28. *
  29. * Typical usage for a subscriber:
  30. * <code>
  31. * // Compiler enforces the callback parameter type.
  32. * pubSub.subscribe(zorg.TopicId.STATE_CHANGE, function(state) {
  33. * if (state == zorg.State.STARTED) {
  34. * // Handle STARTED state.
  35. * }
  36. * });
  37. * </code>
  38. *
  39. * @param {string} topicId
  40. * @template PAYLOAD
  41. * @constructor
  42. * @final
  43. * @struct
  44. */
  45. goog.pubsub.TopicId = function(topicId) {
  46. /**
  47. * @const
  48. * @private
  49. */
  50. this.topicId_ = topicId;
  51. };
  52. /** @override */
  53. goog.pubsub.TopicId.prototype.toString = function() {
  54. return this.topicId_;
  55. };