Repository: expo/expo
File: packages/expo-media-library/src/MediaLibrary.ts (TypeScript)

Code before:
    ...options,
    sortBy: options.sortBy.map(sortByOptionToString),
  });
}

// @needsAudit
/**
 * Subscribes for updates in user's media library.
 * @param listener A callback that is fired when any assets have been inserted or deleted from the
 * library. On Android it's invoked with an empty object. On iOS, it's invoked with [`MediaLibraryAssetsChangeEvent`](#medialibraryassetschangeevent)
 * object.
 *
 * Additionally, only on iOS, the listener is also invoked when the user changes access to individual assets in the media library
 * using `presentPermissionsPickerAsync()`.
 * @return An [`Subscription`](#subscription) object that you can call `remove()` on when you would
 * like to unsubscribe the listener.
 */
export function addListener(
  listener: (event: MediaLibraryAssetsChangeEvent) => void
): EventSubscription {
  return MediaLibrary.addListener(MediaLibrary.CHANGE_LISTENER_NAME, listener);
}

/**
 * @deprecated use subscription.remove() instead
 * */
export function removeSubscription(subscription: EventSubscription): void {
  subscription.remove();
}

// @needsAudit
/**
 * Removes all listeners.
 */
export function removeAllListeners(): void {
  MediaLibrary.removeAllListeners(MediaLibrary.CHANGE_LISTENER_NAME);
}

// @needsAudit
/**
 * Fetches a list of moments, which is a group of assets taken around the same place
 * and time.
 * @return An array of [albums](#album) whose type is `moment`.
 * @platform ios
 */
export async function getMomentsAsync() {
  if (!MediaLibrary.getMomentsAsync) {
    throw new UnavailabilityError('MediaLibrary', 'getMomentsAsync');
  }

  return await MediaLibrary.getMomentsAsync();

Review comment (suggestion):
```suggestion
 * @deprecated use subscription.remove() instead.
 */
```

Code after:
    ...options,
    sortBy: options.sortBy.map(sortByOptionToString),
  });
}

// @needsAudit
/**
 * Subscribes for updates in user's media library.
 * @param listener A callback that is fired when any assets have been inserted or deleted from the
 * library. On Android it's invoked with an empty object. On iOS, it's invoked with [`MediaLibraryAssetsChangeEvent`](#medialibraryassetschangeevent)
 * object.
 *
 * Additionally, only on iOS, the listener is also invoked when the user changes access to individual assets in the media library
 * using `presentPermissionsPickerAsync()`.
 * @return An [`Subscription`](#subscription) object that you can call `remove()` on when you would
 * like to unsubscribe the listener.
 */
export function addListener(
  listener: (event: MediaLibraryAssetsChangeEvent) => void
): EventSubscription {
  return MediaLibrary.addListener(MediaLibrary.CHANGE_LISTENER_NAME, listener);
}

/**
 * @deprecated use subscription.remove() instead.
 */
export function removeSubscription(subscription: EventSubscription): void {
  subscription.remove();
}

// @needsAudit
/**
 * Removes all listeners.
 */
export function removeAllListeners(): void {
  MediaLibrary.removeAllListeners(MediaLibrary.CHANGE_LISTENER_NAME);
}

// @needsAudit
/**
 * Fetches a list of moments, which is a group of assets taken around the same place
 * and time.
 * @return An array of [albums](#album) whose type is `moment`.
 * @platform ios
 */
export async function getMomentsAsync() {
  if (!MediaLibrary.getMomentsAsync) {
    throw new UnavailabilityError('MediaLibrary', 'getMomentsAsync');
  }

  return await MediaLibrary.getMomentsAsync();