Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nickredmark/crdt-continuous-sequence
Makes CRDT sets orderable
https://github.com/nickredmark/crdt-continuous-sequence
Last synced: 3 months ago
JSON representation
Makes CRDT sets orderable
- Host: GitHub
- URL: https://github.com/nickredmark/crdt-continuous-sequence
- Owner: nickredmark
- Created: 2019-11-10T10:59:12.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-05-11T07:07:05.000Z (over 3 years ago)
- Last Synced: 2024-10-27T13:28:32.827Z (3 months ago)
- Language: TypeScript
- Size: 302 KB
- Stars: 17
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# CRDT Continuous Sequence
## Install
```
npm i -s crdt-continuous-sequence
```## Usage with plain array
```js
import { ContinuousSequence } from 'crdt-continuous-sequence'const cs = new ContinuousSequence();
const todos = [
{
id: 1
name: "Groceries"
},
{
id: 2,
name: "Cleaning"
},
{
id: 3,
name: "Admin"
}
]// move 'Admin' between 'Groceries' and 'Cleaning'
cs.move(todos[2], todos[0], todos[1]);
cs.sort(todos);
console.log(todos);
```## Usage with GUN
```js
import Gun from 'gun/gun'
import { GunContinuousSequence } from 'crdt-continuous-sequence'const gun = Gun();
cs = new GunContinuousSequence(gun);
// Initialize sequence
gun.get('todos')
.set({ name: "Groceries" })
.set({ name: "Cleaning"})
.set({ name: "Admin" })// Load items
const todos = [];
gun.get('todos').map().on(todo => {
let index
if ((index = todos.findIndex(todo['_']['#'])) > -1) {
todos[index] = {...todos[index], todo}
} else {
todos.push(todo)
}
cs.sort(todos);
})// Later
// move 'Admin' between 'Groceries' and 'Cleaning'
cs.move(todos[3], todos[0], todos[1])
```