3.0.1 • Published 2 years ago

qing-keyed-array v3.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

qing-keyed-array

Build Status npm version Node.js Version

Keyed observable array.

Installation

npm add qing-keyed-array

Usage

import KeyedObservableArray from 'qing-keyed-array';

// Contains information about a change in immutable mode.
export interface ChangeInfo<K> {
  // The index associated with the change.
  index: number;
  // Number of changed keys.
  numberOfChanges: number;
  // Updated keys.
  updated?: K[];
  // Added keys.
  added?: K[];
  // Removed keys.
  removed?: K[];
  // An extra piece of data associated with this change.
  tag?: unknown;
}

class KeyedObservableArray<K, T> {
  // Creates an instance of `KeyedObservableArray`.
  // `immutable` if `this.array` will be changed in a immutable way.
  // `keyFn` function to get the key from an array element.
  constructor(immutable: boolean, keyFn: (item: T) => K);

  // Whether the internal array is immutable.
  readonly immutable: boolean;

  // Fires when the internal array changes in immutable mode.
  changed?: (sender: this, e: ChangeInfo<K>) => void;

  // An extra piece of data associated with this change.
  // It gets reset every time `changed` fires.
  tag?: unknown;

  // Gets the number of elements.
  get count(): number;

  // Gets the internal array.
  get array(): ReadonlyArray<T>;

  // Gets the internal map.
  get map(): Readonly<Map<K, T>>;

  // Appends the given items to the end of the array.
  push(...items: T[]): number;

  // Inserts items into the given index.
  insert(index: number, ...items: T[]): number;

  // Removes an item at the given index.
  deleteByIndex(index: number): void;

  // Removes the item associated with the given key.
  deleteByKey(key: K): void;

  // Replaces the item associated with the given item key with the new item.
  update(newItem: T);

  // Returns if the internal map contains the given key.
  containsKey(key: K): boolean;
}
3.0.1

2 years ago

3.0.0

2 years ago

2.2.1

2 years ago

2.2.0

2 years ago

2.2.2

2 years ago

2.1.2

2 years ago

2.1.1

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

2.1.0

2 years ago

2.0.0

2 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago