# splice-stream

> Stream changes to an array

Latest version **0.3.1** (published 2012-08-29) · 0 weekly downloads

## Install

```sh
npm install splice-stream
pnpm add splice-stream
yarn add splice-stream
bun add splice-stream
```

## Health

**Score 10/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.1 |
| Published | 2012-08-29 |
| First published | 2012-08-26 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Raynos |
| Maintainers | raynos |

## Links

- npm: https://www.npmjs.com/package/splice-stream
- Repository: https://github.com/Raynos/splice-stream
- Issues: https://github.com/Raynos/splice-stream/issues
- npm.io page: https://npm.io/package/splice-stream

## Dependencies (4)

- [xtend](https://npm.io/package/xtend.md) ~1.0.3
- [node-uuid](https://npm.io/package/node-uuid.md) ~1.3.3
- [re-emitter](https://npm.io/package/re-emitter.md) 0.0.1
- [source-stream](https://npm.io/package/source-stream.md) 0.0.2

## Recent versions

- 0.3.1 (latest) — 2012-08-29
- 0.3.0 — 2012-08-29
- 0.2.3 — 2012-08-27
- 0.2.2 — 2012-08-27
- 0.2.1 — 2012-08-27
- 0.2.0 — 2012-08-27
- 0.1.1 — 2012-08-27
- 0.1.0 — 2012-08-27
- 0.0.2 — 2012-08-26
- 0.0.1 — 2012-08-26

## README

# splice-stream

Stream changes to an array

## Data protocol

`[[/* Array.prototype.splice arguments */], timestamp, sourceIdentifier]`

A splice-stream emits an array, where the first value is an array of parameters compatible with `Array.prototype.slice`. This represents the delta in change on an array.

The second value is a time stamp which can be used for clever synchronization. 

The third value is a source identifier. It's used to identify who created this splice

## Example

``` js
var SpliceStream = require("splice-stream")

var stream1 = SpliceStream()
    , stream2 = SpliceStream()

var list1 = stream1.createList()
    , list2 = stream2.createList()

list1.on("add", function (item, index) {
    console.log("[LIST1]", item, index)
})

list2.on("remove", function (item) {
    console.log("[LIST2]", item)
})

stream2.pipe(stream1).pipe(stream2)

list2.push("bar") // [LIST1] bar 0

console.log("lengths", list1.length(), list2.length()) // lengths 1 1

list1.shift() // [LIST2] bar
```

## Movable List

Sometimes you don't want to add / remove items but move them inside a single list. Use a MovableList to represent moves of items

``` js
var MovableList = require("splice-stream").MovableList

var list1 = MovableList()

// When an item moves around in the list
list1.on("move", function (item, index, old) {
    console.log("[MOVE]", item, index, old)
})

// Normal list events
list1.on("add", function (item, index) {
    console.log("[ADD]", item, index)
})

list1.push("bar")
list1.push("foo")

// Wait a tick to register the adds
process.nextTick(function () {
    // Perform movement of items in a single tick for them to register as 
    // move events
    var elem = list1.pop()
    list1.unshift(elem)
})
```

## Installation

`npm install splice-stream`

## Compatible modules

 - [element-list][1]

## Compatible minus one issue

 - [crdt][2]

## Contributors

 - Raynos

## MIT Licenced

  [1]: https://github.com/Raynos/element-list
  [2]: https://github.com/dominictarr/crdt/issues/3

---
_Source: https://npm.io/package/splice-stream · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
