Socket
Book a DemoInstallSign in
Socket

@jtalton/observable-collections-hooks

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

@jtalton/observable-collections-hooks

Collections of items that emit change events.

unpublished
latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

Collections

Collections are designed to be an efficient way to manage collections of items.

Changes to a collection are emitted as events that other collections can listen and react to.

Instead of filtering, searching, sorting, and paging a whole array anytime there is a change, collections will only filter, search, sort, and page the changes. This makes collections much more efficient and scalable.

Collection Types

  • Collection: A writeable collection that is used as the source for other collections.
  • FilteredCollection: Used to filter a source collection.
  • SearchedCollection: Used to search a source collection.
  • SortedCollection: Used to sort a source collection.
  • SelectedCollection: Used to manage the selected items of a source collection.
  • PagedCollection: Used to page a source collection.

React Hooks

Collections bypass much of the react state management for efficiency. Only when something changes that affects the rendered state will the collections emit state change.

Collections have a set of react hooks for managing collections and state.

const [collection] = useState(() => new Collection(item => item.id))
const { selected, selectedCount } = useSelected(collection)
cosnt { filtered, filteredCount, setFilterFn } = useFiltered(collection)
cosnt { searched, searchedCount, search, setSearch } = useSearched(filtered)
const { sorted, sortedCount, setSortFn } = useSorted(searched)
const { paged, pagedCount, page, setPage, pageSize, setPageSize } = usePage(sorted, 1, 10)
const items = useItems(paged)

return (
    <table>
        {items.map(items => (
            <tr key={item.id}>
                {columns.map(cell=>(
                    <td>{cell}</td>
                ))}
            <tr>
        ))}
    </table>
)

FAQs

Package last updated on 26 Sep 2021

Did you know?

Socket

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.

Install

Related posts