本文整理匯總了TypeScript中rxjs/Rx.ReplaySubject類的典型用法代碼示例。如果您正苦於以下問題:TypeScript ReplaySubject類的具體用法?TypeScript ReplaySubject怎麽用?TypeScript ReplaySubject使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了ReplaySubject類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: start
public start(task: () => Promise<any>): Observable<boolean> {
let working = new ReplaySubject<boolean>();
working.next(true);
task().then(() => {
working.next(false);
}).catch(() => {
working.next(false);
});
return working.asObservable();
}
示例2: startObservable
public startObservable(task: () => Subscription): Observable<boolean> {
let working = new ReplaySubject<boolean>();
let taskSubscription = task();
working.next(true);
taskSubscription.add(() => {
working.next(false);
taskSubscription.unsubscribe();
});
return working.asObservable();
}
示例3: observableSineWave
observableSineWave(increment: number, period: number) : ReplaySubject<string> {
let subject = new ReplaySubject<string>(1);
let ws = new WebSocket('ws://' + window.location.hostname + ':' + window.location.port, 'sinedata');
ws.onmessage = function(e: MessageEvent) {
return subject.next(e.data)
};
return subject;
}
示例4: readUserData
readUserData(user: firebase.User): Observable<FirebaseUser> {
const usersRefPath = 'users/' + user.uid;
const returner$ = new ReplaySubject<FirebaseUser>();
firebase.database().ref(usersRefPath).on('value', snapshot => {
returner$.next(snapshot.val());
});
return returner$;
}
示例5: readUserData
readUserData(): Observable<FirebaseUser> {
const uid = this.store.currentUser.uid;
const usersRefPath = 'users/' + uid;
const returner$ = new ReplaySubject<FirebaseUser>();
firebase.database().ref(usersRefPath).on('value', snapshot => {
const user: FirebaseUser = snapshot.val(); // rename
returner$.next(user);
});
this.disposableRefPaths.push(usersRefPath);
return returner$;
}
示例6:
readNote$(noteid: string): Observable<FirebaseNote> {
const notesRefPath = 'notes/' + noteid;
const returner$ = new ReplaySubject<FirebaseNote>();
/* onメソッドで監視することで変更検知してViewが更新される。 */
firebase.database().ref(notesRefPath).on('value', snapshot => {
const note: FirebaseNote = snapshot.val(); // rename
returner$.next(note);
});
this.disposableRefPaths.push(notesRefPath);
return returner$;
}
示例7: return
firebase.database().ref(notesIndexRefPath).orderByChild('timestamp').limitToLast(100).on('value', snapshot => {
const noteIndices: FirebaseNoteIndex[] = lodash.toArray(snapshot.val()); // rename, reshape
let cachedNotes = this.store.cachedNotes; // Storeに保存してあるcachedNotesを取得する
/* 更新の必要があるnoteIndexだけを抽出する(noteidとtimestampが同一のnoteは更新の必要がない) */
let differenceNoteIndices = noteIndices.filter(noteIndex => {
const compareNotes = cachedNotes.filter(note => note.noteid === noteIndex.noteid);
return (compareNotes.length > 0 && compareNotes[0].timestamp === noteIndex.timestamp) ? false : true;
});
differenceNoteIndices = lodash.orderBy(differenceNoteIndices, ['timestamp'], ['desc']); // timestampの降順で並び替える
console.log('differenceNoteIndices: ');
console.log(differenceNoteIndices);
/* noteIndexに基づいてnoteを取得する。onceメソッドは非同期のため完了は順不同となる。(本當に?) */
if (differenceNoteIndices.length > 0) {
differenceNoteIndices.forEach(noteIndex => {
const notesRefPath = 'notes/' + noteIndex.noteid;
firebase.database().ref(notesRefPath).once('value', snapshot => {
const note: FirebaseNote = snapshot.val(); // rename
cachedNotes.unshift(note); // cachedNotesの先頭にnoteを追加
cachedNotes = lodash.uniqBy(cachedNotes, 'noteid'); // noteidの重複をまとめる。(先頭寄りにあるものを生かす)
cachedNotes = lodash.orderBy(cachedNotes, ['timestamp'], ['desc']); // timestampの降順で並べ替える
this.notes$.next(cachedNotes);
this.store.cachedNotes = cachedNotes; // 新しいcachedNotesをStoreのcachedNotesに書き戻す
});
});
} else { // differenceNoteIndices.length === 0
this.notes$.next(cachedNotes);
}
}, err => {
示例8:
firebase.database().ref(notesRefPath).once('value', snapshot => {
const note: FirebaseNote = snapshot.val(); // rename
cachedNotes.unshift(note); // cachedNotesの先頭にnoteを追加
cachedNotes = lodash.uniqBy(cachedNotes, 'noteid'); // noteidの重複をまとめる。(先頭寄りにあるものを生かす)
cachedNotes = lodash.orderBy(cachedNotes, ['timestamp'], ['desc']); // timestampの降順で並べ替える
this.notes$.next(cachedNotes);
this.store.cachedNotes = cachedNotes; // 新しいcachedNotesをStoreのcachedNotesに書き戻す
});
示例9: next
next() {
if (this._data.current < this._data.members.length - 1) {
this._data.current += 1;
} else {
this._data.current = 0;
this._data.turn += 1;
}
this.data$.next(this._data);
}
示例10: initNoteListReadStream
/*
notesIndexツリーのindexを取得してからnotesツリーのnote実體を取得する、という多段クエリ。
Data Transferを節約するため、更新の必要があるnodeIndexだけを抽出する。
*/
initNoteListReadStream(): Observable<FirebaseNote[]> {
// this.experiment();
const uid = this.store.currentUser.uid; // shorthand
const notesIndexRefPath = 'notesIndex/' + uid;
this.notes$.next(this.store.cachedNotes); // とりあえずキャッシュしてあるノートをViewに表示させる
/* onメソッドはObservableを生成し、offメソッドをコールするまで待機し続ける。 */
firebase.database().ref(notesIndexRefPath).orderByChild('timestamp').limitToLast(100).on('value', snapshot => {
const noteIndices: FirebaseNoteIndex[] = lodash.toArray(snapshot.val()); // rename, reshape
let cachedNotes = this.store.cachedNotes; // Storeに保存してあるcachedNotesを取得する
/* 更新の必要があるnoteIndexだけを抽出する(noteidとtimestampが同一のnoteは更新の必要がない) */
let differenceNoteIndices = noteIndices.filter(noteIndex => {
const compareNotes = cachedNotes.filter(note => note.noteid === noteIndex.noteid);
return (compareNotes.length > 0 && compareNotes[0].timestamp === noteIndex.timestamp) ? false : true;
});
differenceNoteIndices = lodash.orderBy(differenceNoteIndices, ['timestamp'], ['desc']); // timestampの降順で並び替える
console.log('differenceNoteIndices: ');
console.log(differenceNoteIndices);
/* noteIndexに基づいてnoteを取得する。onceメソッドは非同期のため完了は順不同となる。(本當に?) */
if (differenceNoteIndices.length > 0) {
differenceNoteIndices.forEach(noteIndex => {
const notesRefPath = 'notes/' + noteIndex.noteid;
firebase.database().ref(notesRefPath).once('value', snapshot => {
const note: FirebaseNote = snapshot.val(); // rename
cachedNotes.unshift(note); // cachedNotesの先頭にnoteを追加
cachedNotes = lodash.uniqBy(cachedNotes, 'noteid'); // noteidの重複をまとめる。(先頭寄りにあるものを生かす)
cachedNotes = lodash.orderBy(cachedNotes, ['timestamp'], ['desc']); // timestampの降順で並べ替える
this.notes$.next(cachedNotes);
this.store.cachedNotes = cachedNotes; // 新しいcachedNotesをStoreのcachedNotesに書き戻す
});
});
} else { // differenceNoteIndices.length === 0
this.notes$.next(cachedNotes);
}
}, err => {
console.error(err);
});
this.disposableRefPaths.push(notesIndexRefPath);
return this.notes$;
}