New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

kefir-collection

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kefir-collection

Stream helper for managing a collection of items that may be updated, added and removed.

  • 0.1.11
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

kefir-collection

Stream helper for managing a collection of items that may be updated, added and removed.

Install

npm install kefir-collection

Usage

Create a collection stream with KefirCollection(items). This stream has a few helper functions for managing items:

  • setItems(item_id, merge=false) Sets the collection's items, optionally merging with existing items
  • getItem(item_id) Returns a stream for an individual item
  • updateItem(item_id, update) Updates the item, returns individual stream for the updated item
  • createItem(new_item) Creates a new item, returns individual stream for the created item
  • removeItem(item_id) Removes an item, returns the overall items stream

Example

KefirCollection = require 'kefir-collection'

items$ = KefirCollection [
    {_id: 123, name: "Test"},
    {_id: 425, name: "Jones"},
    {_id: 850, name: "Frank"}
]

items$.onValue (items) ->
    console.log '\n[items]', items

items$.getItem(123).onValue (item) ->
    console.log '\n[item 123]', item

# Run some operations

items$.updateItem 123, name: "Hello"

create$ = items$.createItem {_id: 999, name: "Ok"}

create$.onValue (item) ->
    console.log '\n[new item]', item

items$.removeItem 850
[items] [ { _id: 123, name: 'Test' },
  { _id: 425, name: 'Jones' },
  { _id: 850, name: 'Frank' } ]

[item 123] { _id: 123, name: 'Test' }

[items] [ { _id: 123, name: 'Hello' },
  { _id: 425, name: 'Jones' },
  { _id: 850, name: 'Frank' } ]

[item 123] { _id: 123, name: 'Hello' }

[items] [ { _id: 123, name: 'Hello' },
  { _id: 425, name: 'Jones' },
  { _id: 850, name: 'Frank' },
  { _id: 999, name: 'Ok' } ]

[new item] { _id: 999, name: 'Ok' }

[items] [ { _id: 123, name: 'Hello' },
  { _id: 425, name: 'Jones' },
  { _id: 999, name: 'Ok' } ]

Keywords

FAQs

Package last updated on 17 Apr 2017

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc