diff --git a/src/util/observer.ts b/src/util/observer.ts index 6a17beb902450e1e8f7da5c3d21023a49fd03fca..fea87f9cf42d50e533150b989c8586b9547fa71c 100644 --- a/src/util/observer.ts +++ b/src/util/observer.ts @@ -51,3 +51,26 @@ export class Observable implements IObservable { o.update(sender, data); } } + +/** + * @return true si l'objet passé implémente IObservable + * @param o objet à tester + */ +export function isObservable(o: any): boolean { + if (o === undefined) + return false; + + const ob = <IObservable>o; + return typeof ob.addObserver === "function"; +} + +/** + * cast d'un objet implémentant IObservable + * @param o objet à convertir + */ +export function asObservable(o: any): IObservable { + if (isObservable(o)) + return <IObservable>o; + + return undefined; +}