Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

kek

Package Overview
Dependencies
Maintainers
3
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kek

observable set that produces rows of rfc6902 patches as readable stream

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

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

kek

observable set (using mobx) that produces rows of rfc6902 patches (using fast-json-patch) as readable stream.

Build Status NPM version

example

import {Kek} from "kek"
import assert = require("assert")

type IModel = {
	id: string
	n: number
}

const models: IModel[] = [
	{ id: "foo", n: 10 },
	{ id: "bar", n: 5 }
]

const kek = new Kek<IModel>(models)

function nSum(models: IModel[]): number {
	return kek.children.reduce<number>((acc, x) => {
		acc += x.n
		return acc
	}, 0)
}

const reads = kek.observe((value, r) => {
	assert(kek.children === value)

	if (nSum(kek.children) === 22) {
		r.dispose()
	}
})

reads.on("data", changes => {
	console.log(changes)
})

const baz = { id: "baz", n: 1 }

kek.add(baz)

kek.batch(() => {
	baz.n = 5
	kek.add({ id: "qux", n: 0 })
	kek.add({ id: "quux", n: 0 })
})

kek.children.forEach(model => {
	if (model.id !== "baz") {
		model.n += 1
	}
})

outputs:

[ { op: 'add', path: '/2', value: { id: 'baz', n: 1 } } ]
[ { op: 'replace', path: '/2/n', value: 5 },
  { op: 'add', path: '/3', value: { id: 'qux', n: 0 } },
  { op: 'add', path: '/4', value: { id: 'quux', n: 0 } } ]
[ { op: 'replace', path: '/0/n', value: 11 } ]
[ { op: 'replace', path: '/1/n', value: 6 } ]

api

import {Kek} from "kek" 

const k = new kek.Kek(models?: T[])

k.children: T[]

k.add(model: T): this

k.remove(model: T): this

k.batch(fn: () => void): this

k.applyPatches(patches: kek.IPatch[], validate: boolean = false)

const stream = k.observe((value: T[], r: kek.IDisposer) => void)

stream.on("data", (patches: kek.IPatch[]) => void)

Keywords

FAQs

Package last updated on 08 Jan 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