mobx#entries TypeScript Examples

The following examples show how to use mobx#entries. 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: swapStore.ts    From lightning-terminal with MIT License 6 votes vote down vote up
/** removes completed swap IDs from the swappedChannels list */
  pruneSwappedChannels() {
    this._store.log.info('pruning swapped channels list');
    // create a list of the currently pending swaps
    const processingIds = values(this.swaps)
      .filter(s => s.isPending)
      .map(s => s.id);
    // loop over the swapped channels that are stored
    entries(this.swappedChannels).forEach(([chanId, swapIds]) => {
      // filter out the swaps that are no longer processing
      const pendingSwapIds = swapIds.filter(id => processingIds.includes(id));
      if (swapIds.length !== pendingSwapIds.length) {
        // if the list has changed then the swapped channels value needs to be updated
        if (pendingSwapIds.length === 0) {
          // remove the channel id key if there are no more processing swaps using it
          this.swappedChannels.delete(chanId);
        } else {
          // update the swapIds with the updated list
          this.swappedChannels.set(chanId, pendingSwapIds);
        }
      }
    });
    this._store.log.info('updated swapStore.swappedChannels', toJS(this.swappedChannels));
  }