
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
@jtalton/observable-collections
Advanced tools
Collections of items that emit change events.
Collections of items that emit change events.
Collections can be hooked together to create a pipeline which efficiently filters, searches, sorts, and pages the source collection based on the emitted change events.
A writeable collection that is used as the source for other collections.
const keyFn: KeyFn<T> = (item: T) => item.id
const source = new Collection<T>(keyFn)
source.insert(item)
source.removeKey(item.id)
source.clear()
Collection that filters a source collection.
const filtered = new FilteredCollection<ItemT>(source)
const filterFn: FilterFn<T> = (item: T) => true
filtered.setFilterFn(filterFn)
Collection that searches a source collection.
const searched = new SearchedCollection<ItemT>(source)
const searchFn: SearchFn<T> = (item: T) => 1
searched.setSearchFn(searchFn)
searched.setSearch("some search string")
Collection that sorts a source collection.
const sorted = new SortedCollection<ItemT>(source)
const sortFn: SortFn<T> = (item: T) => 0
sorted.setSortFn(sortFn)
Collection that keeps its items in sync with a source collection.
const selected = new SelectedCollection<ItemT>(source)
selected.insert(item)
Collection used to page a source collection.
const paged = new PagedCollection(source)
const page = 1
const pageSize = 10
paged.setPage(page, pageSize)
interface ItemT {
id: number
name: string
}
const keyFn = (item: ItemT) => item.id
const source = new Collection<ItemT>(keyFn)
const filtered = new FilteredCollection(source)
const filterFn = (_item: ItemT) => true
filtered.setFilterFn(filterFn)
const sorted = new SortedCollection(filtered)
const sortFn = (lhs: ItemT, rhs: ItemT) => lhs.name.localeCompare(rhs.name)
sorted.setSortFn(sortFn)
const page = 1
const pageSize = 10
const paged = new PagedCollection(sorted, page, pageSize)
source.insert({ id: 1, name: 'One' })
expect(paged.items()).toEqual([{ id: 1, name: 'One' }])
All collections extend EventEmitter and emit a "change" event when the collection changes.
collection.on("change", (change: CollectionChange<T> => {
// Handle change
}))
Emitted when items are added.
{
"addedCount": 1,
"added": { 1: { "id": 1 }},
}
Emitted when items are updated.
{
"updatedCount": 1,
"updated": { 1: { "id": 1 }},
}
Emitted when items are removed.
{
"revmovedCount": 1,
"removed": { 1: { "id": 1 }},
}
Emitted when the order of the items has changed. (Only ordered collections like searched, sorted, and paged.)
{
"ordered": true
}
FAQs
Collections of items that emit change events.
We found that @jtalton/observable-collections demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.