goog.pubsub.PubSub
Classgoog.pubsub.PubSub
> goog.Disposable
goog.pubsub.PubSub()
Topic-based publish/subscribe channel. Maintains a map of topics to subscriptions. When a message is published to a topic, all functions subscribed to that topic are invoked in the order they were added. Uncaught errors abort publishing. Topics may be identified by any nonempty string, except strings corresponding to native Object properties, e.g. "constructor", "toString", "hasOwnProperty", etc.
.addOnDisposeCallback(callback, opt_scope)
Inherited from goog.Disposable
.
Invokes a callback function when this object is disposed. Callbacks are invoked in the order in which they were added.
callback
{!Function
}
opt_scope
{Object
=}
.clear(opt_topic)
Clears the subscription list for a topic, or all topics if unspecified.
opt_topic
{string
=}
.creationStack
{string
}Inherited from goog.Disposable
.
If monitoring the goog.Disposable instances is enabled, stores the creation stack trace of the Disposable instance.
.dispose()
Inherited from goog.Disposable
.
Disposes of the object. If the object hasn't already been disposed of, calls {@link #disposeInternal}. Classes that extend {@code goog.Disposable} should override {@link #disposeInternal} in order to delete references to COM objects, DOM nodes, and other disposable objects. Reentrant.
void
}
.disposeInternal()
[protected]Deletes or nulls out any references to COM objects, DOM nodes, or other disposable objects. Classes that extend {@code goog.Disposable} should override this method. Not reentrant. To avoid calling it twice, it must only be called from the subclass' {@code disposeInternal} method. Everywhere else the public {@code dispose} method must be used. For example:
mypackage.MyClass = function() { goog.base(this); // Constructor logic specific to MyClass. ... }; goog.inherits(mypackage.MyClass, goog.Disposable); mypackage.MyClass.prototype.disposeInternal = function() { goog.base(this, 'disposeInternal'); // Dispose logic specific to MyClass. ... };
.getCount(opt_topic)
Returns the number of subscriptions to the given topic (or all topics if unspecified).
opt_topic
{string
=}
number
}
.getDisposed
[deprecated]Deprecated. Use {@link #isDisposed} instead.
Inherited from goog.Disposable
.
boolean
}
.isDisposed()
Inherited from goog.Disposable
.
boolean
}
.publish(topic, var_args)
Publishes a message to a topic. Calls functions subscribed to the topic in the order in which they were added, passing all arguments along. If any of the functions throws an uncaught error, publishing is aborted.
topic
{string
}
var_args
{...*}
boolean
}
.registerDisposable(disposable)
Inherited from goog.Disposable
.
Associates a disposable object with this object so that they will be disposed together.
disposable
{goog.disposable.IDisposable
}
.subscribe(topic, fn, opt_context)
Subscribes a function to a topic. The function is invoked as a method on the given {@code opt_context} object, or in the global scope if no context is specified. Subscribing the same function to the same topic multiple times will result in multiple function invocations while publishing. Returns a subscription key that can be used to unsubscribe the function from the topic via {@link #unsubscribeByKey}.
topic
{string
}
fn
{Function
}
opt_context
{Object
=}
number
}
.subscribeOnce(topic, fn, opt_context)
Subscribes a single-use function to a topic. The function is invoked as a method on the given {@code opt_context} object, or in the global scope if no context is specified, and is then unsubscribed. Returns a subscription key that can be used to unsubscribe the function from the topic via {@link #unsubscribeByKey}.
topic
{string
}
fn
{Function
}
opt_context
{Object
=}
number
}
.unsubscribe(topic, fn, opt_context)
Unsubscribes a function from a topic. Only deletes the first match found. Returns a Boolean indicating whether a subscription was removed.
topic
{string
}
fn
{Function
}
opt_context
{Object
=}
boolean
}
.unsubscribeByKey(key)
Removes a subscription based on the key returned by {@link #subscribe}. No-op if no matching subscription is found. Returns a Boolean indicating whether a subscription was removed.
key
{number
}
boolean
}