Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/danielkucal/rx-collections
Reactive implementations of ES6 Collections - Set and Map
https://github.com/danielkucal/rx-collections
es6-collections map rxjs set typescript
Last synced: about 1 month ago
JSON representation
Reactive implementations of ES6 Collections - Set and Map
- Host: GitHub
- URL: https://github.com/danielkucal/rx-collections
- Owner: DanielKucal
- Created: 2017-08-24T12:41:30.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-03-29T11:46:02.000Z (almost 4 years ago)
- Last Synced: 2024-11-30T10:06:15.466Z (about 2 months ago)
- Topics: es6-collections, map, rxjs, set, typescript
- Language: TypeScript
- Size: 6.84 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: change-event.interface.ts
Awesome Lists containing this project
README
## Reactive collections
#### `npm install rx-collections`
Reactive implementations of ES6 Collections: Set and Map (and Array coming soon) created with TypeScript.
Using this library you can pretty easily watch for changes on your collections.
`RxSet` and `RxMap` classes wrap native equivalents adding `changes$` property, which is an `RxJS` Observable. Data are emitted in the following format:```typescript
export interface RxChangeEvent {
method: string; // name of invoked method (e.g. "add", "delete")
key: K; // string or undefined
value: V; // any stored object affected in the operation
collection: C; // up-to-date Set or Map instance
}
```### Example of usage (TypeScript):
```typescript
import { RxSet } from 'rx-collections';let set: RxSet = new RxSet();
set.change$.subscribe((event) => {
console.log('Method', event.method, 'has affected value:', event.value);
console.log('Current Set state:', event.collection);
// do something here, e.g. prevent adding null values
if (event.method === 'add' && event.value === null) {
event.collection.delete(null);
}
});
set.add(1).add(2).add(3).add(null).add(4);
// Result: set contains merely 1,2,3,4
console.log('Array created from set:', Array.from(set));
```**Note:** be careful to not accidentally overwrite the object, because observers won't be moved to the new instance. In order to clear it just use built-in `.clear()` method.
### Support this project by giving it a star if you'd like to see it developed!