Debian Codegraph @

closure-library/closure/goog/pubsub/topicid.js

raw
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
15 goog.provide('goog.pubsub.TopicId');
16
17
18
19 /**
20 * A templated class that is used to register {@code goog.pubsub.PubSub}
21 * subscribers.
22 *
23 * Typical usage for a publisher:
24 * <code>
25 * /** @type {!goog.pubsub.TopicId<!zorg.State>}
26 * zorg.TopicId.STATE_CHANGE = new goog.pubsub.TopicId(
27 * goog.events.getUniqueId('state-change'));
28 *
29 * // Compiler enforces that these types are correct.
30 * pubSub.publish(zorg.TopicId.STATE_CHANGE, zorg.State.STARTED);
31 * </code>
32 *
33 * Typical usage for a subscriber:
34 * <code>
35 * // Compiler enforces the callback parameter type.
36 * pubSub.subscribe(zorg.TopicId.STATE_CHANGE, function(state) {
37 * if (state == zorg.State.STARTED) {
38 * // Handle STARTED state.
39 * }
40 * });
41 * </code>
42 *
43 * @param {string} topicId
44 * @template PAYLOAD
45 * @constructor
46 * @final
47 * @struct
48 */
49 goog.pubsub.TopicId = function(topicId) {
50 /**
51 * @const
52 * @private
53 */
54 this.topicId_ = topicId;
55 };
56
57
58 /** @override */
59 goog.pubsub.TopicId.prototype.toString = function() {
60 return this.topicId_;
61 };