Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/charliewilco/immutable-array-helpers


https://github.com/charliewilco/immutable-array-helpers

Last synced: about 1 month ago
JSON representation

Awesome Lists containing this project

README

        

# Immutable Array Helpers

## Install

```sh
yarn add immutable-array-helpers
```

## Setup

```typescript
import { ImmutableArrayHelpers } from "immutable-array-helpers";

interface SomeInterface {
key1: any;
key2: any;
id: string;
}

const someArray: SomeInterface[] = [...]

const data = new ImmutableArrayHelpers(someArray)
```

## Usage

This is a class that helps manipulate an array of objects in an immutable way. The class holds an internal array of objects and provides methods to add, remove, or update objects in the array.

### Parameters

- `data: K[]`: An initial array of objects. The objects in the array should have a property specified by the key parameter.

### Properties

- `data: K[]`: The internal array of objects held by the class. This property is read-only.

### Methods

- `add(x: K): K[]`: Adds an object `x` to the beginning of the internal array. Returns the new array.
- `remove(removed: K, key?: string): K[]`: Removes an object from the internal array based on the specified `key`. If `key` is not specified, the default value is `"id"`. Returns the new array.
- `update(updated: K, key?: string): K[]`: Updates an object in the internal array based on the specified `key`. If `key` is not specified, the default value is `"id"`. Returns the new array.