ericelliott/object-list

Implement object-list methods

Open

#4 aberto em 17 de mar. de 2015

Ver no GitHub
 (18 comments) (0 reactions) (0 assignees)JavaScript (2 forks)github user discovery
enhancementhelp wanted

Métricas do repositório

Stars
 (43 stars)
Métricas de merge de PR
 (Métricas PR pendentes)

Description

object-list

Treat arrays of objects like a db you can query. A single object from an object-list is called a record.

A common API for object collections

You may be scratching your head right now and wondering how this is different from Underscore, Lodash, or Rx Observables. Astute observations. The implementation will likely lean heavily on both Lodash and Rx Observables.

The difference is that this is intended to provide a universal facade for many types of object collections. It is an interface contract that will hopefully support a number of modular collection adapters. Read on for more details.

Current Status

Developer preview.

API Design Goals

Only a few of these design goals have been met in the current implementation, so read this section like everything is prefixed with "eventually..." See future.

  • A common API for object collections (e.g. arrays of objects). Must have adapters: Array, Immutable.js:List, Rx Observable, Siren-Resource API via HTTP Fetch, Mongo client, Redis client.
  • object-lists are immutable. Instead of mutating the source data, a new object-list will be returned.
  • Completely modular. Enable require() at the function level similar to require('lodash/object/assign'), etc... Compatibility transforms for things that aren't required for hard dependencies should also be separate modules. Minimize browserify bundle weight.
  • Node or Browser.
  • Provide ES6 Array.prototype compatible API. Almost anything that takes an array as input should be able to take an object-list, as well, provided the API does not rely on array mutation.
  • Use ES6 and make compiled ES5 version available on npm.
  • Compatible with infinite streams and generators.
  • Should be capable of sync or async. Add .subscribe() method for async results.

See Future.

What needs doing?

  • Create checklist from method names (only partially complete)
  • Create corresponding issues for each checklist item
  • Comment on each issue with this meta-issues URL so that issue status is displayed below this ticket

High Priority

  • .push(record), .add(record) - Append the record to the list.
  • .remove(obj) – Removes an item from the collection if it looks like the passed-in object (deepEqual).
  • .removeWhere({key1: value, key2: value2...}) - Remove all objects that match the key:value where clauses.
  • .distinct(predicate) - Returns only distinct records which satisfy the predicate function.
  • .distinctWhere({key: value, key2: value2}) - Returns only distinct records which match all supplied where clauses.
  • .sortBy({foo: 'descending'}, [fn]) – Sorts the list based on the property passed in using optional [].sort() compatible custom sort function.
  • ES6 Array.prototype methods

Medium Priority

  • .at(index), .recordAt(index) – Returns the record at index.
  • .removeSlice(startIndex, endIndex) – Filter out a range of indexes. Basically the opposite of .slice() (return the filtered list instead of the sliced out subset).

Guia do colaborador