本文整理匯總了TypeScript中rxjs/Rx.BehaviorSubject.asObservable方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript BehaviorSubject.asObservable方法的具體用法?TypeScript BehaviorSubject.asObservable怎麽用?TypeScript BehaviorSubject.asObservable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rxjs/Rx.BehaviorSubject
的用法示例。
在下文中一共展示了BehaviorSubject.asObservable方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: constructor
constructor() {
this._data = this.emptyData(); // Initialize session data with empty default values
let storedData = this.retrieve();
if (storedData) {
Object.assign(this._data, storedData);
}
this.dataSubject = new BehaviorSubject(this._data);
this.data = this.dataSubject.asObservable();
}
示例2: constructor
constructor() {
this.connections = [];
this._onUpdate = new BehaviorSubject([]);
this.onUpdate = this._onUpdate.asObservable();
}
示例3: constructor
constructor(
private zone: NgZone
) {
this.window = getWindow();
this.document = getDocument();
const initialFocus = this.document["visibilityState"] === "visible"
? DetailedFocusStates.TabFocus
: DetailedFocusStates.TabBlur;
this.detailedFocusSubject = new BehaviorSubject<DetailedFocusStates>(initialFocus);
// Wire up the detailed focus observable
//
this.detailedFocus$ = this.detailedFocusSubject
.asObservable()
.distinctUntilChanged();
// Now wire up the more generic observable by mapping the detailed values to the
// broader ones. We also add distinct until changed because we might get both
// a tab and window event fired, and we don't want to emit duplicates
//
this.focus$ = this.detailedFocus$
.map((focus) => {
switch (focus) {
case DetailedFocusStates.WindowFocus:
case DetailedFocusStates.TabFocus:
{
return FocusStates.Focus;
}
}
return FocusStates.Blur;
})
.distinctUntilChanged();
this.zone.run(() => {
this.document.addEventListener("visibilitychange", () => {
if (document.visibilityState === "visible") {
this.detailedFocusSubject.next(DetailedFocusStates.TabFocus);
} else {
this.detailedFocusSubject.next(DetailedFocusStates.TabBlur);
}
});
/////////////////////////////////////////
// check if browser window has focus
let notIE = (this.document.documentMode === undefined),
isChromium = this.window.chrome;
if (notIE && !isChromium) {
// checks for Firefox and other NON IE Chrome versions
this.window.on("focusin",
() => {
setTimeout(() => {
this.detailedFocusSubject.next(DetailedFocusStates.WindowFocus);
},
300);
});
this.window.on("focusout", () => {
this.detailedFocusSubject.next(DetailedFocusStates.WindowBlur);
});
} else {
// checks for IE and Chromium versions
if (this.window.addEventListener) {
// bind focus event
this.window.addEventListener("focus", (event: any) => {
setTimeout(() => {
this.detailedFocusSubject.next(DetailedFocusStates.WindowFocus);
},
300);
},
false);
// bind blur event
this.window.addEventListener("blur", (event: any) => {
this.detailedFocusSubject.next(DetailedFocusStates.WindowBlur);
},
false);
} else {
// bind focus event
this.window.attachEvent("focus", (event: any) => {
setTimeout(() => {
this.detailedFocusSubject.next(DetailedFocusStates.WindowFocus);
},
//.........這裏部分代碼省略.........
示例4: getCurrentUser
getCurrentUser(): Observable<User> {
return this.currentUser.asObservable().share();
}
示例5: getTheme
getTheme() {
return this.theme.asObservable();
}
示例6: constructor
constructor() {
this._counties$ = new BehaviorSubject([]);
this.counties$ = this._counties$.asObservable();
}
示例7: getActiveTheme
getActiveTheme() {
return this.theme.asObservable();
}