How to use array-find-index - 10 common examples

To help you get started, we’ve selected a few array-find-index examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github benwiley4000 / cassette / packages / core / src / PlayerContextProvider.js View on Github external
handleMediaSrcrequest(e) {
    const { playlist } = this.props;
    const sources = getTrackSources(playlist, this.state.activeTrackIndex);
    if (arrayFindIndex(sources, s => s.src === e.srcRequested) !== -1) {
      // we're good! nothing to update.
      return;
    }
    // looks like 'src' was set from outside our component.
    // let's see if we can use it.
    const newTrackIndex = findTrackIndexByUrl(playlist, e.srcRequested);
    if (newTrackIndex === -1) {
      logError(
        `Source '${e.srcRequested}' does not exist in the loaded playlist. ` +
          `Make sure you've updated the 'playlist' prop to ` +
          `PlayerContextProvider before you select this track!`
      );
      return;
    }
    this.selectTrackIndex(newTrackIndex);
  }
github canalplus / rx-player / src / core / abr / filter_by_bitrate.ts View on Github external
export default function filterByBitrate(
  representations : Representation[],
  bitrate : number
) : Representation[] {
  const firstSuperiorBitrate = arrayFindIndex(
    representations,
    (representation) => representation.bitrate > bitrate
  );

  if (firstSuperiorBitrate === -1) {
    return representations; // All representations have a lower bitrates.
  }
  return representations.slice(0, firstSuperiorBitrate);
}
github benwiley4000 / cassette / src / index.js View on Github external
this.audio.crossOrigin = nextProps.crossOrigin;

    const newPlaylist = nextProps.playlist;
    if (!newPlaylist || !newPlaylist.length) {
      if (this.audio) {
        this.audio.src = '';
      }
      this.currentTrackIndex = 0;
      return this.setState(this.defaultState);
    }

    const oldPlaylist = this.props.playlist;

    const currentTrackUrl = ((oldPlaylist || [])[this.currentTrackIndex] || {}).url;
    this.currentTrackIndex = arrayFindIndex(newPlaylist, track => {
      return track.url && currentTrackUrl === track.url;
    });
    /* if the track we're already playing is in the new playlist, update the
     * activeTrackIndex.
     */
    if (this.currentTrackIndex !== -1) {
      this.setState({
        activeTrackIndex: this.currentTrackIndex
      });
    }
  }
github necolas / react-native-web / packages / react-native-web / src / exports / NetInfo / index.js View on Github external
removeEventListener(type: string, handler: Function): void {
    invariant(
      eventTypes.indexOf(type) !== -1,
      'Trying to unsubscribe from unknown event: "%s"',
      type
    );
    if (type === 'change') {
      console.warn('Listening to event `change` is deprecated. Use `connectionChange` instead.');
    }

    const listenerIndex = findIndex(netInfoListeners, pair => pair[0] === handler);
    invariant(listenerIndex !== -1, 'Trying to remove NetInfo listener for unregistered handler');
    const [, wrappedHandler] = netInfoListeners[listenerIndex];
    connection.removeEventListener(eventTypesMap[type], wrappedHandler);
    netInfoListeners.splice(listenerIndex, 1);
  },
github necolas / react-native-web / packages / react-native-web / src / exports / NetInfo / index.js View on Github external
removeEventListener(type: string, handler: Function): void {
      invariant(
        eventTypes.indexOf(type) !== -1,
        'Trying to subscribe to unknown event: "%s"',
        type
      );
      if (type === 'change') {
        console.warn('Listening to event `change` is deprecated. Use `connectionChange` instead.');
      }

      const listenerIndex = findIndex(connectionListeners, pair => pair[0] === handler);
      invariant(
        listenerIndex !== -1,
        'Trying to remove NetInfo connection listener for unregistered handler'
      );
      const [, onlineCallback, offlineCallback] = connectionListeners[listenerIndex];

      window.removeEventListener('online', onlineCallback, false);
      window.removeEventListener('offline', offlineCallback, false);

      connectionListeners.splice(listenerIndex, 1);
    },
github UXtemple / panels / panels / panel.js View on Github external
function mapStateToProps(state, props) {
  const routeIndex = findIndex(state.router.routes, panel => panel.context === props.route.context);
  const app = state.apps[props.route.app] || {
    isLoading: true
  };
  const panel = state.panels[getPanelPathFromRoute(props.route)] || {
    isLoading: true
  };

  const isLoading = app.isLoading || panel.isLoading;
  const isReady = app.isReady && panel.isReady;
  const error = app.error || panel.error;

  return {
    app,
    error,
    isLoading,
    isReady,
github benwiley4000 / cassette / packages / core / src / utils / findTrackIndexByUrl.js View on Github external
function findTrackIndexByUrl(playlist, url) {
  return arrayFindIndex(playlist, track => {
    if (track.sources) {
      return arrayFindIndex(track.sources, source => source.src === url) !== -1;
    }
    return track.url && url === track.url;
  });
}
github StreakYC / react-menu-list / src / MenuList.js View on Github external
const register = () => {
        let i = -1;
        if (item.props.index == null) {
          i = findIndex(
            this._listItems,
            _item =>
              (item.el.compareDocumentPosition(_item.el)&Node.DOCUMENT_POSITION_PRECEDING) === 0
          );
        } else {
          i = findIndex(
            this._listItems,
            _item => _item.props.index != null && item.props.index < _item.props.index
          );
        }
        if (i < 0) {
          this._listItems.push(item);
        } else {
          this._listItems.splice(i, 0, item);
          if (this._naturalHighlightedIndex != null && i <= this._naturalHighlightedIndex) {
            this._naturalHighlightedIndex++;
github necolas / react-native-web / src / apis / AppState / index.js View on Github external
static removeEventListener(type: string, handler: Function) {
    if (AppState.isAvailable) {
      invariant(
        EVENT_TYPES.indexOf(type) !== -1,
        'Trying to remove listener for unknown event: "%s"',
        type
      );
      const listenerIndex = findIndex(listeners, pair => pair[0] === handler);
      invariant(
        listenerIndex !== -1,
        'Trying to remove AppState listener for unregistered handler'
      );
      const callback = listeners[listenerIndex][1];
      document.removeEventListener(VISIBILITY_CHANGE_EVENT, callback, false);
      listeners.splice(listenerIndex, 1);
    }
  }
}
github StreakyCobra / raposfly / frontend / src / store / modules / cart.js View on Github external
[types.REMOVE_FROM_CART]: function (state, item) {
        var index = arrayFindIndex(state.cart, (elm) => elm.item === item)
        if (index !== -1) {
            if (state.cart[index].quantity > 1) {
                state.cart[index].quantity--
            } else {
                state.cart.splice(index, 1)
            }
        }
    },
    [types.DISCARD_CART]: function (state) {

array-find-index

ES2015 `Array#findIndex()` ponyfill

MIT
Latest version published 8 years ago

Package Health Score

67 / 100
Full package analysis

Popular array-find-index functions