Constructor
new module:br/util/Observable()
Constructs a new
Observable.
- Source:
Methods
-
(static) FailedNotification(observer, methodName, exception)
-
Constructs a new
Observable.FailedNotificationwith the specified observer, method name and exception.Parameters:
Name Type Description observerObject The observer that threw the exception whilst processing a notification. methodNameString The name of the method that was invoked. exceptionObject The exception that was thrown. -
addObserver(observer)
-
Adds the specified observer to the list of those to be called when
module:br/util/Observable#notifyObserversis invoked. This method will not prevent a particular observer from being added multiple times. Themodule:br/util/Observable#addUniqueObservermethod should be used for this behaviour. If an observer is added multiple times it will receive every notification once for each time it has been registered.Parameters:
Name Type Description observerObject The object to be added as an observer. - Source:
Throws:
-
if the specified observer is not an
Object, or if it is a native JavaScriptString,Number,BooleanorFunction. - Type
- Error
-
addUniqueObserver(observer) → {Boolean}
-
Adds the specified observer to the list of those to be called when
module:br/util/Observable#notifyObserversis invoked. This method prevents a observer that has already been added to anObservablefrom being added again. Themodule:br/util/Observable#addObservermethod should be used if duplicates are allowed.Parameters:
Name Type Description observerObject The object to be added as an observer. - Source:
Throws:
-
if the specified observer is not an
Object, or if it is a native JavaScriptString,Number,BooleanorFunction. - Type
- Error
Returns:
trueif the observer was successfully added orfalseif it failed because it had already been added before.- Type
- Boolean
-
getAllObservers() → {Array}
-
Gets a list of all the observers that have been registered with this
Observable.Returns:
A list of the observers that have been registered.- Type
- Array
-
getCount()
-
Gets the number of listeners within the observer.
- Source:
Returns:
The number of listeners within the observer. -
notify(methodName)
-
Invokes the specified method with specified parameters on each of the observers that have been added to this
Observable. Please note that this method does not attempt to catch any exceptions that may be thrown by the caller. It is recommended that before adding an observer to theObservable, it should be tested to ensure it conforms to the expected interface, and if not it should be rejected.Parameters:
Name Type Description methodNameString The method to be invoked on each of the registered observers. \{...\}(Optional) Additional parameters are passed to the observer. -
notifyObservers(methodName, (Optional))
-
Invokes the specified method with specified array of parameters on each of the observers that have been added to this
Observable. Please note that this method does not attempt to catch any exceptions that may be thrown by the caller. If this is an issue then themodule:br/util/Observable#notifyObserversWithTryCatchmethod should be used instead. It is recommended that before adding an observer to theObservable, it should be tested to ensure it conforms to the expected interface, and if not it should be rejected.Parameters:
Name Type Description methodNameString The method to be invoked on each of the registered observers. (Optional)Array parameters An array of the parameters to be passed into the specified method. The first element of the array will be the first parameter in the callback method, the second element the second parameter, and so on. -
notifyObserversWithTryCatch(methodName, parameters, throwExceptions) → {Array}
-
Invokes the specified method with a specified array of parameters on each of the observers that have been added to this
Observable. This method wraps each call to the observer in atry..catchblock so that if any observer throws an exception it will get caught and the execution will continue to the remaining observers. When exceptions occur, they are wrapped inmodule:br/util/Observable/FailedNotificationand an array of these are returned to the caller.Parameters:
Name Type Description methodNameString The method to be invoked on each of the registered observers. parametersArray An array of the parameters to be passed into the specified method. The first element of the array will be the first parameter in the callback method, the second element the second parameter, and so on. throwExceptionsboolean (optional) You can use this parameter if you wish the exception array to be thrown rather than returned. If no exceptions occur then nothing will be thrown and the method will return normally. - Source:
- See:
-
- br.util.Observable#notifyObservers to notify without guarding against exceptions.
Returns:
The list ofbr.util.Observable.FailedNotifications that occured or an empty array if no exceptions occurred.- Type
- Array
-
removeAllObservers()
-
Removes all observers from this
Observable. They will no longer be informed of any events that are raised on it. -
removeObserver(observer) → {Boolean}
-
Removes the specified observer from the list of registered observers. It will no longer be notified of any events that are raised on this
Observable.Parameters:
Name Type Description observerObject The observer to be removed. Returns:
trueif the observer has been removed, otherwisefalse, which indicates that the observer was not registered.- Type
- Boolean