JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 10
  • Score
    100M100P100Q45747F
  • License MIT

Derive a list/map from another via live binding

Package Exports

  • can-derive

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (can-derive) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

can-derive

Derive live can.List and can.Maps from source lists.

This supports O(log n) maintaintence of mapped and filtered can.Lists. Basically this means if you setup a derived list like completed in the following example:

var sourceList = new can.List([{name: "dishes", complete: true}, 
                               {name: "lawn", complete: false}, 
                              ...])

var completed = sourceList.filter(function(todo){
  return todo.attr("complete");
});

Any changes to sourceList will automatically update the derived completed list in O(log n) time.
This avoids the standard O(n) times done everywhere else.

It does this by:

  • keeping completed in a RBTree.
  • listening to when any items are added or removed from the source list.
  • listening to when the predicate function value changes for any item.

The general algorithim was worked out in this thread.