aboutsummaryrefslogtreecommitdiff
path: root/contexts/data/lib/closure-library/closure/goog/labs/observe/observable.js
blob: 2ca576f57fcd293b3997b5821e675002e53ede0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2012 The Closure Library Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
 * @fileoverview Experimental observer-observable API. This is
 * intended as super lightweight replacement of
 * goog.events.EventTarget when w3c event model bubble/capture
 * behavior is not required.
 *
 * This is similar to {@code goog.pubsub.PubSub} but with different
 * intent and naming so that it is more discoverable. The API is
 * tighter while allowing for more flexibility offered by the
 * interface {@code Observable}.
 *
 * WARNING: This is still highly experimental. Please contact author
 * before using this.
 *
 */

goog.provide('goog.labs.observe.Observable');

goog.require('goog.disposable.IDisposable');



/**
 * Interface for an observable object.
 * @interface
 * @extends {goog.disposable.IDisposable}
 */
goog.labs.observe.Observable = function() {};


/**
 * Registers an observer on the observable.
 *
 * Note that no guarantee is provided on order of execution of the
 * observers. For a single notification, one Notice object is reused
 * across all invoked observers.
 *
 * Note that if an observation with the same observer is already
 * registered, it will not be registered again. Comparison is done via
 * observer's {@code equals} method.
 *
 * @param {!goog.labs.observe.Observer} observer The observer to add.
 * @return {boolean} Whether the observer was successfully added.
 */
goog.labs.observe.Observable.prototype.observe = function(observer) {};


/**
 * Unregisters an observer from the observable. The parameter must be
 * the same as those passed to {@code observe} method. Comparison is
 * done via observer's {@code equals} method.
 * @param {!goog.labs.observe.Observer} observer The observer to remove.
 * @return {boolean} Whether the observer is removed.
 */
goog.labs.observe.Observable.prototype.unobserve = function(observer) {};


/**
 * Notifies observers by invoking them. Optionally, a data object may be
 * given to be passed to each observer.
 * @param {*=} opt_data An optional data object.
 */
goog.labs.observe.Observable.prototype.notify = function(opt_data) {};