1.5.4 • Published 1 year ago

dop v1.5.4

Weekly downloads
115
License
MIT
Repository
github
Last release
1 year ago

npm npm bundle size Build Status

Distributed Object Protocol is a thin layer on top of your data network that helps you communicate server and clients (nodes) using RPCs. It is also a pattern that makes easy update, mutate or even sync the state of your App using Patches.

Quick example using RPCs with WebSockets

// Server
const { createNode } = require('dop')
const WebSocket = require('ws')
const wss = new WebSocket.Server({ port: 8080 })

const sum = (a, b) => a + b
const multiply = (a, b) => a * b
const getCalculator = () => ({ sum, multiply })

wss.on('connection', ws => {
    const client = createNode()
    client.open(ws.send.bind(ws), getCalculator)
    ws.on('message', client.message)
})
// Client
const ws = new WebSocket('ws://localhost:8080')
const server = createNode()
ws.on('open', async () => {
    const getCalculator = server.open(ws.send.bind(ws))
    const { sum, multiply } = await getCalculator()
    const result1 = await sum(5, 5)
    const result2 = await multiply(3, 3)
    console.log(result1, result2) // 10, 9
})
ws.on('message', server.message)

Quick example using Stores and Patches

// Server
const { createStore } = require('dop')

const store = createStore({ players: 0 })

function subscribeToServerStore(listener) {
    // Incrementing number of player as a patch
    const listeners = store.applyPatch({ players: store.state.players + 1 })
    // We emit the patch to all the subscribers
    listeners.forEach(({ listener, patch }) => listener(patch))
    // Here we subscribe our client
    store.subscribe(listener)
    return store.state
}
// Client
const { createStore } = require('dop')

// Getting the current state of the server and subscribing to it
const state = await subscribeToServerStore(onPatch)
// Creates a local store where our UX components can subscribe to
const store = createStore(state)

function onPatch(patch) {
    // Applying patch from the server
    const listeners = store.applyPatch(patch)
    // We emit the patch to subscribers. Like React components.
    listeners.forEach(({ listener, patch }) => listener(patch))
}

Check the website for more info https://distributedobjectprotocol.org/

License

MIT

1.5.4

1 year ago

1.5.3

1 year ago

1.5.2

2 years ago

1.5.1

2 years ago

1.5.0

2 years ago

1.4.3

3 years ago

1.4.2

3 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.2.0-rc1

4 years ago

1.1.0

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

1.0.0-beta.5

4 years ago

1.0.0-beta.4

4 years ago

1.0.0-beta.3

4 years ago

1.0.0-beta.2

4 years ago

1.0.0-beta.0

4 years ago

1.0.0-beta.1

4 years ago

1.0.0-rc3

5 years ago

1.0.0-rc2

5 years ago

0.43.3

5 years ago

0.43.2

5 years ago

1.0.0-rc1

5 years ago

0.43.0

5 years ago

0.42.0

5 years ago

0.41.0

5 years ago

0.40.1

5 years ago

0.40.0

5 years ago

0.30.2

6 years ago

0.30.1

6 years ago

0.30.0

6 years ago

0.28.0

6 years ago

0.27.0

6 years ago

0.26.2

6 years ago

0.26.1

6 years ago

0.26.0

7 years ago

0.25.2

7 years ago

0.25.1

7 years ago

0.25.0

7 years ago

0.24.3

7 years ago

0.24.2

7 years ago

0.24.1

7 years ago

0.24.0

7 years ago

0.23.0

7 years ago

0.22.10

7 years ago

0.22.9

7 years ago

0.22.8

7 years ago

0.22.7

7 years ago

0.22.6

7 years ago

0.22.5

7 years ago

0.22.4

7 years ago

0.22.3

7 years ago

0.22.2

7 years ago

0.22.1

7 years ago

0.22.0

7 years ago

0.21.2

7 years ago

0.21.1

7 years ago

0.20.0

7 years ago

0.11.11

7 years ago

0.11.10

7 years ago

0.11.9

7 years ago

0.11.8

7 years ago

0.11.7

7 years ago

0.11.6

7 years ago

0.11.5

7 years ago

0.11.4

7 years ago

0.11.3

7 years ago

0.11.2

7 years ago

0.11.1

7 years ago

0.11.0

7 years ago

0.10.2

7 years ago

0.10.1

7 years ago

0.10.0

7 years ago

0.9.0

7 years ago

0.8.0

7 years ago

0.7.0

7 years ago

0.6.0

7 years ago

0.5.0

7 years ago

0.4.0

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.0.1

8 years ago