Update wmts-hidpi, add nicer-api-docs

This commit is contained in:
Andreas Hocevar
2014-05-06 13:02:46 -05:00
parent b3ac1afd00
commit 1e25fc5585
2239 changed files with 3726515 additions and 37010 deletions

View File

@@ -0,0 +1,63 @@
// 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 Provides a notice object that is used to encapsulates
* information about a particular change/notification on an observable
* object.
*/
goog.provide('goog.labs.observe.Notice');
/**
* A notice object encapsulates information about a notification fired
* by an observable.
* @param {!goog.labs.observe.Observable} observable The observable
* object that fires this notice.
* @param {*=} opt_data The optional data associated with this notice.
* @constructor
*/
goog.labs.observe.Notice = function(observable, opt_data) {
/**
* @type {!goog.labs.observe.Observable}
* @private
*/
this.observable_ = observable;
/**
* @type {*}
* @private
*/
this.data_ = opt_data;
};
/**
* @return {!goog.labs.observe.Observable} The observable object that
* fires this notice.
*/
goog.labs.observe.Notice.prototype.getObservable = function() {
return this.observable_;
};
/**
* @return {*} The optional data associated with this notice. May be
* null/undefined.
*/
goog.labs.observe.Notice.prototype.getData = function() {
return this.data_;
};

View File

@@ -0,0 +1,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) {};

View File

@@ -0,0 +1,180 @@
// 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 A set of {@code goog.labs.observe.Observable}s that
* allow registering and removing observers to all of the observables
* in the set.
*/
goog.provide('goog.labs.observe.ObservableSet');
goog.require('goog.array');
goog.require('goog.labs.observe.Observer');
/**
* Creates a set of observables.
*
* An ObservableSet is a collection of observables. Observers may be
* reigstered and will receive notifications when any of the
* observables notify. This class is meant to simplify management of
* observations on multiple observables of the same nature.
*
* @constructor
*/
goog.labs.observe.ObservableSet = function() {
/**
* The observers registered with this set.
* @type {!Array.<!goog.labs.observe.Observer>}
* @private
*/
this.observers_ = [];
/**
* The observables in this set.
* @type {!Array.<!goog.labs.observe.Observable>}
* @private
*/
this.observables_ = [];
};
/**
* Adds an observer that observes all observables in the set. If new
* observables are added to or removed from the set, the observer will
* be registered or unregistered accordingly.
*
* The observer will not be added if there is already an equivalent
* observer.
*
* @param {!goog.labs.observe.Observer} observer The observer to invoke.
* @return {boolean} Whether the observer is actually added.
*/
goog.labs.observe.ObservableSet.prototype.addObserver = function(observer) {
// Check whether the observer already exists.
if (goog.array.find(this.observers_, goog.partial(
goog.labs.observe.Observer.equals, observer))) {
return false;
}
this.observers_.push(observer);
goog.array.forEach(this.observables_, function(o) {
o.observe(observer);
});
return true;
};
/**
* Removes an observer from the set. The observer will be removed from
* all observables in the set. Does nothing if the observer is not in
* the set.
* @param {!goog.labs.observe.Observer} observer The observer to remove.
* @return {boolean} Whether the observer is actually removed.
*/
goog.labs.observe.ObservableSet.prototype.removeObserver = function(observer) {
// Check that the observer exists before removing.
var removed = goog.array.removeIf(this.observers_, goog.partial(
goog.labs.observe.Observer.equals, observer));
if (removed) {
goog.array.forEach(this.observables_, function(o) {
o.unobserve(observer);
});
}
return removed;
};
/**
* Removes all registered observers.
*/
goog.labs.observe.ObservableSet.prototype.removeAllObservers = function() {
this.unregisterAll_();
this.observers_.length = 0;
};
/**
* Adds an observable to the set. All previously added and future
* observers will be added to the new observable as well.
*
* The observable will not be added if it is already registered in the
* set.
*
* @param {!goog.labs.observe.Observable} observable The observable to add.
* @return {boolean} Whether the observable is actually added.
*/
goog.labs.observe.ObservableSet.prototype.addObservable = function(observable) {
if (goog.array.contains(this.observables_, observable)) {
return false;
}
this.observables_.push(observable);
goog.array.forEach(this.observers_, function(observer) {
observable.observe(observer);
});
return true;
};
/**
* Removes an observable from the set. All observers registered on the
* set will be removed from the observable as well.
* @param {!goog.labs.observe.Observable} observable The observable to remove.
* @return {boolean} Whether the observable is actually removed.
*/
goog.labs.observe.ObservableSet.prototype.removeObservable = function(
observable) {
var removed = goog.array.remove(this.observables_, observable);
if (removed) {
goog.array.forEach(this.observers_, function(observer) {
observable.unobserve(observer);
});
}
return removed;
};
/**
* Removes all registered observables.
*/
goog.labs.observe.ObservableSet.prototype.removeAllObservables = function() {
this.unregisterAll_();
this.observables_.length = 0;
};
/**
* Removes all registered observations and observables.
*/
goog.labs.observe.ObservableSet.prototype.removeAll = function() {
this.removeAllObservers();
this.observables_.length = 0;
};
/**
* Unregisters all registered observers from all registered observables.
* @private
*/
goog.labs.observe.ObservableSet.prototype.unregisterAll_ = function() {
goog.array.forEach(this.observers_, function(observer) {
goog.array.forEach(this.observables_, function(o) {
o.unobserve(observer);
});
}, this);
};

View File

@@ -0,0 +1,156 @@
// 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 A set of observations. This set provides a convenient
* means of observing many observables at once.
*
* This is similar in purpose to {@code goog.events.EventHandler}.
*
*/
goog.provide('goog.labs.observe.ObservationSet');
goog.require('goog.array');
goog.require('goog.labs.observe.Observer');
/**
* A set of observations. An observation is defined by an observable
* and an observer. The set keeps track of observations and
* allows their removal.
* @param {!Object=} opt_defaultScope Optional function scope to use
* when using {@code observeWithFunction} and
* {@code unobserveWithFunction}.
* @constructor
*/
goog.labs.observe.ObservationSet = function(opt_defaultScope) {
/**
* @type {!Array.<!goog.labs.observe.ObservationSet.Observation_>}
* @private
*/
this.storedObservations_ = [];
/**
* @type {!Object|undefined}
* @private
*/
this.defaultScope_ = opt_defaultScope;
};
/**
* Observes the given observer on the observable.
* @param {!goog.labs.observe.Observable} observable The observable to
* observe on.
* @param {!goog.labs.observe.Observer} observer The observer.
* @return {boolean} True if the observer is successfully registered.
*/
goog.labs.observe.ObservationSet.prototype.observe = function(
observable, observer) {
var success = observable.observe(observer);
if (success) {
this.storedObservations_.push(
new goog.labs.observe.ObservationSet.Observation_(
observable, observer));
}
return success;
};
/**
* Observes the given function on the observable.
* @param {!goog.labs.observe.Observable} observable The observable to
* observe on.
* @param {function(!goog.labs.observe.Notice)} fn The handler function.
* @param {!Object=} opt_scope Optional scope.
* @return {goog.labs.observe.Observer} The registered observer object.
* If the observer is not successfully registered, this will be null.
*/
goog.labs.observe.ObservationSet.prototype.observeWithFunction = function(
observable, fn, opt_scope) {
var observer = goog.labs.observe.Observer.fromFunction(
fn, opt_scope || this.defaultScope_);
if (this.observe(observable, observer)) {
return observer;
}
return null;
};
/**
* Unobserves the given observer from the observable.
* @param {!goog.labs.observe.Observable} observable The observable to
* unobserve from.
* @param {!goog.labs.observe.Observer} observer The observer.
* @return {boolean} True if the observer is successfully removed.
*/
goog.labs.observe.ObservationSet.prototype.unobserve = function(
observable, observer) {
var removed = goog.array.removeIf(
this.storedObservations_, function(o) {
return o.observable == observable &&
goog.labs.observe.Observer.equals(o.observer, observer);
});
if (removed) {
observable.unobserve(observer);
}
return removed;
};
/**
* Unobserves the given function from the observable.
* @param {!goog.labs.observe.Observable} observable The observable to
* unobserve from.
* @param {function(!goog.labs.observe.Notice)} fn The handler function.
* @param {!Object=} opt_scope Optional scope.
* @return {boolean} True if the observer is successfully removed.
*/
goog.labs.observe.ObservationSet.prototype.unobserveWithFunction = function(
observable, fn, opt_scope) {
var observer = goog.labs.observe.Observer.fromFunction(
fn, opt_scope || this.defaultScope_);
return this.unobserve(observable, observer);
};
/**
* Removes all observations registered through this set.
*/
goog.labs.observe.ObservationSet.prototype.removeAll = function() {
goog.array.forEach(this.storedObservations_, function(observation) {
var observable = observation.observable;
var observer = observation.observer;
observable.unobserve(observer);
});
};
/**
* A representation of an observation, which is defined uniquely by
* the observable and observer.
* @param {!goog.labs.observe.Observable} observable The observable.
* @param {!goog.labs.observe.Observer} observer The observer.
* @constructor
* @private
*/
goog.labs.observe.ObservationSet.Observation_ = function(
observable, observer) {
this.observable = observable;
this.observer = observer;
};

View File

@@ -0,0 +1,100 @@
// 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 Provide definition of an observer. This is meant to
* be used with {@code goog.labs.observe.Observable}.
*
* This file also provides convenient functions to compare and create
* Observer objects.
*
*/
goog.provide('goog.labs.observe.Observer');
/**
* A class implementing {@code Observer} may be informed of changes in
* observable object.
* @see {goog.labs.observe.Observable}
* @interface
*/
goog.labs.observe.Observer = function() {};
/**
* Notifies the observer of changes to the observable object.
* @param {!goog.labs.observe.Notice} notice The notice object.
*/
goog.labs.observe.Observer.prototype.notify;
/**
* Whether this observer is equal to the given observer.
* @param {!goog.labs.observe.Observer} observer The observer to compare with.
* @return {boolean} Whether the two observers are equal.
*/
goog.labs.observe.Observer.prototype.equals;
/**
* @param {!goog.labs.observe.Observer} observer1 Observer to compare.
* @param {!goog.labs.observe.Observer} observer2 Observer to compare.
* @return {boolean} Whether observer1 and observer2 are equal, as
* determined by the first observer1's {@code equals} method.
*/
goog.labs.observe.Observer.equals = function(observer1, observer2) {
return observer1 == observer2 || observer1.equals(observer2);
};
/**
* Creates an observer that calls the given function.
* @param {function(!goog.labs.observe.Notice)} fn Function to be converted.
* @param {!Object=} opt_scope Optional scope to execute the function.
* @return {!goog.labs.observe.Observer} An observer object.
*/
goog.labs.observe.Observer.fromFunction = function(fn, opt_scope) {
return new goog.labs.observe.Observer.FunctionObserver_(fn, opt_scope);
};
/**
* An observer that calls the given function on {@code notify}.
* @param {function(!goog.labs.observe.Notice)} fn Function to delegate to.
* @param {!Object=} opt_scope Optional scope to execute the function.
* @constructor
* @implements {goog.labs.observe.Observer}
* @private
*/
goog.labs.observe.Observer.FunctionObserver_ = function(fn, opt_scope) {
this.fn_ = fn;
this.scope_ = opt_scope;
};
/** @override */
goog.labs.observe.Observer.FunctionObserver_.prototype.notify = function(
notice) {
this.fn_.call(this.scope_, notice);
};
/** @override */
goog.labs.observe.Observer.FunctionObserver_.prototype.equals = function(
observer) {
return this.fn_ === observer.fn_ && this.scope_ === observer.scope_;
};

View File

@@ -0,0 +1,129 @@
// 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 An implementation of {@code Observable} that can be
* used as base class or composed into another class that wants to
* implement {@code Observable}.
*/
goog.provide('goog.labs.observe.SimpleObservable');
goog.require('goog.Disposable');
goog.require('goog.array');
goog.require('goog.asserts');
goog.require('goog.labs.observe.Notice');
goog.require('goog.labs.observe.Observable');
goog.require('goog.labs.observe.Observer');
goog.require('goog.object');
/**
* A simple implementation of {@code goog.labs.observe.Observable} that can
* be used as a standalone observable or as a base class for other
* observable object.
*
* When another class wants to implement observable without extending
* {@code SimpleObservable}, they can create an instance of
* {@code SimpleObservable}, specifying {@code opt_actualObservable},
* and delegate to the instance. Here is a trivial example:
*
* <pre>
* ClassA = function() {
* goog.base(this);
* this.observable_ = new SimpleObservable(this);
* this.registerDisposable(this.observable_);
* };
* goog.inherits(ClassA, goog.Disposable);
*
* ClassA.prototype.observe = function(observer) {
* this.observable_.observe(observer);
* };
*
* ClassA.prototype.unobserve = function(observer) {
* this.observable_.unobserve(observer);
* };
*
* ClassA.prototype.notify = function(opt_data) {
* this.observable_.notify(opt_data);
* };
* </pre>
*
* @param {!goog.labs.observe.Observable=} opt_actualObservable
* Optional observable object. Defaults to 'this'. When used as
* base class, the parameter need not be given. It is only useful
* when using this class to implement implement {@code Observable}
* interface on another object, see example above.
* @constructor
* @implements {goog.labs.observe.Observable}
* @extends {goog.Disposable}
*/
goog.labs.observe.SimpleObservable = function(opt_actualObservable) {
goog.base(this);
/**
* @type {!goog.labs.observe.Observable}
* @private
*/
this.actualObservable_ = opt_actualObservable || this;
/**
* Observers registered on this object.
* @type {!Array.<!goog.labs.observe.Observer>}
* @private
*/
this.observers_ = [];
};
goog.inherits(goog.labs.observe.SimpleObservable, goog.Disposable);
/** @override */
goog.labs.observe.SimpleObservable.prototype.observe = function(observer) {
goog.asserts.assert(!this.isDisposed());
// Registers the (type, observer) only if it has not been previously
// registered.
var shouldRegisterObserver = !goog.array.some(this.observers_, goog.partial(
goog.labs.observe.Observer.equals, observer));
if (shouldRegisterObserver) {
this.observers_.push(observer);
}
return shouldRegisterObserver;
};
/** @override */
goog.labs.observe.SimpleObservable.prototype.unobserve = function(observer) {
goog.asserts.assert(!this.isDisposed());
return goog.array.removeIf(this.observers_, goog.partial(
goog.labs.observe.Observer.equals, observer));
};
/** @override */
goog.labs.observe.SimpleObservable.prototype.notify = function(opt_data) {
goog.asserts.assert(!this.isDisposed());
var notice = new goog.labs.observe.Notice(this.actualObservable_, opt_data);
goog.array.forEach(
goog.array.clone(this.observers_), function(observer) {
observer.notify(notice);
});
};
/** @override */
goog.labs.observe.SimpleObservable.prototype.disposeInternal = function() {
this.observers_.length = 0;
};