firebase/app#firestore TypeScript Examples

The following examples show how to use firebase/app#firestore. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: trade-logs.effects.ts    From zorro-fire-log with MIT License 6 votes vote down vote up
onTradeLogUpdate$ = createEffect(() =>
    iif(
      () => this.useMockData,
      of(
        addTradeLogs({
          tradeLogs: mockTradeLogs,
        })
      ).pipe(
        delay(500),
        tap(() => console.warn('Using MOCKED data'))
      ),
      this.store.select(selectLatestEntryTime).pipe(
        map(
          (latest) =>
            latest && new Timestamp(latest.seconds, latest.nanoseconds).toDate()
        ),
        take(1),
        switchMap((latest) =>
          merge(
            ...environment.tradeLogs.map((tl) =>
              this.firestore
                .collection<TradeLogEntry>(tl, (ref) =>
                  (latest ? ref.where('close', '>', latest) : ref).orderBy(
                    'close'
                  )
                )
                .valueChanges({ idField: 'id' })
                .pipe(
                  map((entries) => entries.map((e) => ({ ...e, alias: tl })))
                )
            )
          ).pipe(
            tap(() => console.warn('Using LIVE data')),
            map((tradeLogs) => addTradeLogs({ tradeLogs }))
          )
        )
      )
    )
  );
Example #2
Source File: trade-logs.effects.ts    From zorro-fire-log with MIT License 6 votes vote down vote up
// TODO: add mocked positions
  onPositionLogUpdate$ = createEffect(() =>
    iif(
      () => false,
      of(
        addTradeLogs({
          tradeLogs: mockTradeLogs,
        })
      ).pipe(
        delay(500),
        tap(() => console.warn('Using MOCKED data'))
      ),
      merge(
        ...(environment.positionLogs || []).map((alias) =>
          this.firestore
            .collection('positions')
            .doc<PositionLog>(alias)
            .valueChanges()
            .pipe(
              filter((x) => !!x),
              map((pLog) =>
                addPositions({
                  alias,
                  positions: (pLog.positions || [])
                    .map((tle) => ({ ...tle, alias }))
                    .reduce((acc, val) => {
                      return acc.concat(val);
                    }, []),
                })
              )
            )
        )
      )
    )
  );
Example #3
Source File: timestamp.helper.ts    From FireAdmin with MIT License 5 votes vote down vote up
export function timestampToDate(timestamp: firestore.Timestamp): Date {
  if (timestamp instanceof firestore.Timestamp) {
    return new Date(+timestamp.seconds * 1000);
  } else {
    console.warn(`could not convert ${timestamp} to date!`);
    return timestamp;
  }
}
Example #4
Source File: trade-logs.effects.ts    From zorro-fire-log with MIT License 5 votes vote down vote up
constructor(
    private firestore: AngularFirestore,
    private store: Store<TradeLogState>,
    private actions$: Actions,
    @Inject(useMockData) private useMockData: boolean
  ) {}