rxjs/operators#filter JavaScript Examples

The following examples show how to use rxjs/operators#filter. 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: restaurantEpic.js    From git-brunching with GNU General Public License v3.0 6 votes vote down vote up
fetchSearchedRestaurants = (action$) => action$.pipe(
  filter((action) => action.type === actionType.ADD_SEARCH_RESTAURANTS),
  mergeMap(async (action) => {
    const restaurants = await fetch(`${GET_SEARCH_RESTAURANTS}${action.searchText}`).then((res) => res.json());
    return { ...action, type: actionType.ADD_RESTAURANTS_SUCCESS, restaurants };
  }),
  catchError((err) => Promise.resolve({
    type: actionType.ADD_RESTAURANTS_FAIL,
    message: err.message,
  })),
)
Example #2
Source File: OnlineAccountClient.js    From invizi with GNU General Public License v3.0 6 votes vote down vote up
// Fetch all trades, all deposits and withdraws
  // returns obs
  synchronizeTransactions (account, symbolCurrencyPair, apiKeys, params) {
    const allTrades$ = this.getMyTradesObs(...arguments)
    const withdrawals$ = this.getWithdrawalsObs(...arguments)
    const deposits$ = from(this.getDepositsObs(...arguments))
    const timer$ = timer(5000)
    const maxIter = this.allTransactionsMaxIter(account.name)
    let currentIter = 1

    let load$ = concat(deposits$, timer$, withdrawals$, timer$, allTrades$).pipe(
      tap(data => {
        console.log(data)
      }),
      filter(data => data), // filter timerObs values
      map(result => {
        let tradesFiltered = result.data
        // if (account.last_sync_at) {
        //   tradesFiltered = result.data.filter(trade => trade.date > account.last_sync_at / 1000)
        // }
        tradesFiltered.progress = (currentIter + 1) / maxIter
        currentIter++
        return result
      })
    )
    return load$
  }
Example #3
Source File: OnlineAccountClient.js    From invizi with GNU General Public License v3.0 6 votes vote down vote up
// Like loadBalance but convert into trades
  async loadBalanceForTrades (account) {
    let result = await this.loadBalance(account.name)
    let importItems = TradeClient.balanceToTrades(result, account.name, account.account_type, {fromExchange: true})
    // Remove from the imported balance the ones already present in db
    let exchangeDbTrades = await TradeClient.account(account.name)
    let exchangeOrderHistory = exchangeDbTrades.filter(trade => trade.fromExchange === true)
    let newExchangeTrades = _.differenceWith(importItems, exchangeOrderHistory, (a, b) => {
      return a.to === b.to && a.quantity_to === b.quantity_to
    })
    newExchangeTrades = newExchangeTrades.map(trade => Object.assign({}, trade, {_id: TradeClient.hashId(trade)}))
    let oldLocalTrades = _.differenceWith(exchangeOrderHistory, importItems, (a, b) => {
      return a.to === b.to && a.quantity_to === b.quantity_to
    })
    // Delete old local trades since they are not on exchange anymore
    TradeClient.remove(oldLocalTrades.map(trade => trade.id))

    return newExchangeTrades
  }
Example #4
Source File: restaurantEpic.js    From git-brunching with GNU General Public License v3.0 6 votes vote down vote up
fetchNewRestaurants = (action$) => action$.pipe(
  filter((action) => action.type === actionType.ADD_NEW_RESTAURANTS),
  mergeMap(async (action) => {
    const newRestaurants = await fetch(GET_NEW_RESTAURANTS).then((res) => res.json());
    return { ...action, type: actionType.ADD_NEW_RESTAURANTS_SUCCESS, newRestaurants };
  }),
  catchError((err) => Promise.resolve({
    type: actionType.ADD_RESTAURANTS_FAIL,
    message: err.message,
  })),
)
Example #5
Source File: restaurantEpic.js    From git-brunching with GNU General Public License v3.0 6 votes vote down vote up
fetchPopularRestaurants = (action$) => action$.pipe(
  filter((action) => action.type === actionType.ADD_POPULAR_RESTAURANTS),
  mergeMap(async (action) => {
    const popularRestaurants = await fetch(GET_POPULAR_RESTAURANTS).then((res) => res.json());
    return { ...action, type: actionType.ADD_POPULAR_RESTAURANTS_SUCCESS, popularRestaurants };
  }),
  catchError((err) => Promise.resolve({
    type: actionType.ADD_RESTAURANTS_FAIL,
    message: err.message,
  })),
)
Example #6
Source File: restaurantEpic.js    From git-brunching with GNU General Public License v3.0 6 votes vote down vote up
fetchOpenRestaurants = (action$) => action$.pipe(
  filter((action) => action.type === actionType.ADD_OPEN_RESTAURANTS),
  mergeMap(async (action) => {
    const openRestaurants = await fetch(GET_OPEN_RESTAURANTS).then((res) => res.json());
    return { ...action, type: actionType.ADD_OPEN_RESTAURANTS_SUCCESS, openRestaurants };
  }),
  catchError((err) => Promise.resolve({
    type: actionType.ADD_RESTAURANTS_FAIL,
    message: err.message,
  })),
)
Example #7
Source File: restaurantEpic.js    From git-brunching with GNU General Public License v3.0 6 votes vote down vote up
fetchRestaurants = (action$) => action$.pipe(
  filter((action) => action.type === actionType.ADD_RESTAURANTS),
  mergeMap(async (action) => {
    const restaurants = await fetch(GET_ALL_RESTAURANTS).then((res) => res.json());
    return { ...action, type: actionType.ADD_RESTAURANTS_SUCCESS, restaurants };
  }),
  catchError((err) => Promise.resolve({
    type: actionType.ADD_RESTAURANTS_FAIL,
    message: err.message,
  })),
)
Example #8
Source File: menu.js    From git-brunching with GNU General Public License v3.0 6 votes vote down vote up
getRestaurantMenu = (action$, store) => action$.pipe(
    filter((action) => action.type === actionType.GET_RESTAURANT_MENU),
    mergeMap(async (action) => {
      const menu = await fetch(RESTAURANT_MENU(action.restaurantID))
        .then((res) => res.json());
      return { ...action, type: actionType.GET_RESTAURANT_MENU_SUCCESS, menus: menu };
    }),
    catchError((err) => Promise.resolve({
      type: actionType.GET_RESTAURANT_MENU_FAIL,
      message: err.message,
    })),
  )
Example #9
Source File: bookingEpic.js    From git-brunching with GNU General Public License v3.0 6 votes vote down vote up
getTableCapacity = (action$, store) => action$.pipe(
  filter((action) => action.type === actionType.GET_TABLE_CAPACITY),
  mergeMap(async (action) => {
    const restaurantData = store.value.restaurantReducer;
    const capacity = await fetch(TABLE_CAPACITY(restaurantData.selected.ID)).then((res) => res.json());
    return {
      ...action,
      type: actionType.GET_TABLE_CAPACITY_SUCCESS,
      tableCapacity: capacity,
    };
  }),
  catchError((err) => Promise.resolve({
    type: actionType.GET_TABLE_CAPACITY_FAIL,
    message: err.message,
  })),
)
Example #10
Source File: bookingEpic.js    From git-brunching with GNU General Public License v3.0 6 votes vote down vote up
getAvailableHours = (action$, store) => action$.pipe(
  filter((action) => action.type === actionType.GET_AVAILABLE_RESTAURANT_HOURS),
  mergeMap(async (action) => {
    const bookingData = store.value.bookingReducer;
    const restaurantData = store.value.restaurantReducer;
    const endPoint = `${FREE_TABLE}?restaurantID=${restaurantData.selected.ID}&numberOfGuests=${bookingData.seats}&date=${bookingData.date}`;
    const available = await fetch(endPoint).then((res) => res.json());
    return {
      ...action,
      type: actionType.GET_AVAILABLE_RESTAURANT_HOURS_SUCCESS,
      availableRestaurantHours: available,
    };
  }),
  catchError((err) => Promise.resolve({
    type: actionType.GET_AVAILABLE_RESTAURANT_HOURS_FAIL,
    message: err.message,
  })),
)
Example #11
Source File: bookingEpic.js    From git-brunching with GNU General Public License v3.0 6 votes vote down vote up
getRestaurantHours = (action$, store) => action$.pipe(
  filter((action) => action.type === actionType.GET_RESTAURANT_HOURS),
  mergeMap(async (action) => {
    const restaurantData = store.value.restaurantReducer;
    const hours = await fetch(RESTAURANT_HOURS(restaurantData.selected.ID))
      .then((res) => res.json());
    return { ...action, type: actionType.GET_RESTAURANT_HOURS_SUCCESS, restaurantHours: hours };
  }),
  catchError((err) => Promise.resolve({
    type: actionType.GET_RESTAURANT_HOURS_FAIL,
    message: err.message,
  })),
)
Example #12
Source File: bookingEpic.js    From git-brunching with GNU General Public License v3.0 6 votes vote down vote up
getRestaurantBookings = (action$, store) => action$.pipe(
  filter((action) => action.type === actionType.GET_RESTAURANT_BOOKINGS),
  mergeMap(async (action) => {
    const bookingData = store.value.bookingReducer;
    const bookings = await fetch(RESTAURANT_BOOKING(bookingData.currentRestaurantID))
      .then((res) => res.json());
    return {
      ...action,
      type: actionType.GET_RESTAURANT_BOOKINGS_SUCCCESS,
      restaurantBookings: bookings.result,
    };
  }),
  catchError((err) => Promise.resolve({
    type: actionType.GET_RESTAURANT_BOOKINGS_FAIL,
    message: err.message,
  })),
)
Example #13
Source File: bookingEpic.js    From git-brunching with GNU General Public License v3.0 6 votes vote down vote up
editReservation = (action$, store) => action$.pipe(
  filter((action) => action.type === actionType.EDIT_BOOKING),
  mergeMap(async (action) => {
    const bookingData = store.value.bookingReducer;
    const restaurantData = store.value.restaurantReducer;

    const booking = await fetch(`${PUT_RESERVATION}/${bookingData.bookingCode}`, {
      method: "PUT",
      mode: "cors",
      credentials: "same-origin",
      headers: {
        Accept: "application/json, text/plain, */*",
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        date: bookingData.date,
        time: bookingData.time,
        restaurantID: restaurantData.selected.ID,
        numberOfGuests: bookingData.seats,
        notes: bookingData.notes,
        name: bookingData.name,
        phone: bookingData.phone,
        email: bookingData.email,
      }),
    }).then((res) => res.json());

    return { ...action, type: actionType.EDIT_BOOKING_SUCCESS, booking };
  }),
  catchError((err) => Promise.resolve({
    type: actionType.EDIT_BOOKING_FAIL,
    message: err.message,
  })),
)
Example #14
Source File: bookingEpic.js    From git-brunching with GNU General Public License v3.0 5 votes vote down vote up
addReservation = (action$, store) => action$.pipe(
  filter((action) => action.type === actionType.ADD_BOOKING),
  mergeMap(async (action) => {
    const bookingData = store.value.bookingReducer;
    const restaurantData = store.value.restaurantReducer;

    const tableIDEndpoint = `${TABLE_ID.toString()}?date=${bookingData.date}&time=${bookingData.time.substring(0, 2)}&numberOfGuests=${bookingData.seats}&restaurantID=${restaurantData.selected.ID}`;

    const tableID = await fetch(tableIDEndpoint, {
      method: "GET",
      mode: "cors",
      credentials: "same-origin",
      headers: {
        Accept: "application/json, text/plain, */*",
        "Content-Type": "application/json",
      },
    }).then((res) => res.json());

    const booking = await fetch(POST_RESERVATION, {
      method: "POST",
      mode: "cors",
      credentials: "same-origin",
      headers: {
        Accept: "application/json, text/plain, */*",
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        date: bookingData.date,
        time: bookingData.time,
        restaurantID: restaurantData.selected.ID,
        numberOfGuests: bookingData.seats,
        tableID: tableID.result[0].ID,
        notes: bookingData.notes,
        name: bookingData.name,
        phone: bookingData.phone,
        email: bookingData.email,
      }),
    }).then((res) => res.json());

    return { ...action, type: actionType.ADD_BOOKING_SUCCESS, booking };
  }),
  catchError((err) => Promise.resolve({
    type: actionType.ADD_BOOKING_FAIL,
    message: err.message,
  })),
)
Example #15
Source File: restaurantEpic.js    From git-brunching with GNU General Public License v3.0 5 votes vote down vote up
pingEpic = (action$) => action$.pipe(
  filter((action) => action.type === actionType.ADD_RESTAURANTS),
  delay(1000), // Asynchronously wait 1000ms then continue
  mapTo({ type: actionType.ADD_RESTAURANTS_SUCCESS, restaurants: [1, 2] }),
)
Example #16
Source File: alert.service.js    From maps with MIT License 5 votes vote down vote up
// enable subscribing to alerts observable
function onAlert(id = defaultId) {
  return alertSubject.asObservable().pipe(filter((x) => x && x.id === id));
}
Example #17
Source File: alert.service.js    From next-js-10-crud-example with MIT License 5 votes vote down vote up
// enable subscribing to alerts observable
function onAlert(id = defaultId) {
    return alertSubject.asObservable().pipe(filter(x => x && x.id === id));
}
Example #18
Source File: alert.service.js    From react-alert-notifications with MIT License 5 votes vote down vote up
// enable subscribing to alerts observable
function onAlert(id = defaultId) {
    return alertSubject.asObservable().pipe(filter(x => x && x.id === id));
}
Example #19
Source File: alert.service.js    From react-formik-master-details-crud-example with MIT License 5 votes vote down vote up
// enable subscribing to alerts observable
function onAlert(id = defaultId) {
    return alertSubject.asObservable().pipe(filter(x => x && x.id === id));
}
Example #20
Source File: alert.service.js    From react-hooks-bootstrap-alerts with MIT License 5 votes vote down vote up
// enable subscribing to alerts observable
function onAlert(id = defaultId) {
    return alertSubject.asObservable().pipe(filter(x => x && x.id === id));
}
Example #21
Source File: alert.service.js    From react-signup-verification-boilerplate with MIT License 5 votes vote down vote up
// enable subscribing to alerts observable
function onAlert(id = defaultId) {
    return alertSubject.asObservable().pipe(filter(x => x && x.id === id));
}
Example #22
Source File: OnlineAccountClient.js    From invizi with GNU General Public License v3.0 5 votes vote down vote up
async allWithApiKeys () {
    let allAccounts = await this.limit()
    return allAccounts.filter(acc => this.hasApiKeys(acc))
  }
Example #23
Source File: OnlineAccountClient.js    From invizi with GNU General Public License v3.0 5 votes vote down vote up
async allExchangeNames () {
    let allAccounts = await this.all()
    let result = _.filter(allAccounts, account => !!Ticker.SUPPORTED_EXCHANGES[account.name] === true)
    return result
  }