Skip to content

Framework communicating using a Compassion atomic log.

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE-e
Notifications You must be signed in to change notification settings

bigeasy/conference

Repository files navigation

Actions Status codecov License: MIT

Reduce messages from an atomic log.

What Where
Discussion #1
Documentation https://bigeasy.github.io/conference
Source https://github.com/bigeasy/conference
Issues https://github.com/bigeasy/conference/issues
CI https://travis-ci.org/bigeasy/conference
Coverage: https://codecov.io/gh/bigeasy/conference
License: MIT

Ascension installs from NPM.

npm install conference

Living README.md

This README.md is also a unit test using the Proof unit test framework. We'll use the Proof okay function to assert out statements in the readme. A Proof unit test generally looks like this.

require('proof')(4, okay => {
    okay('always okay')
    okay(true, 'okay if true')
    okay(1, 1, 'okay if equal')
    okay({ value: 1 }, { value: 1 }, 'okay if deep strict equal')
})

You can run this unit test yourself to see the output from the various code sections of the readme.

git clone [email protected]:bigeasy/conference.git
cd conference
npm install --no-package-lock --no-save
node test/readme.t.js

Overview

Require.

const Conference = require('conference')

Construct.

const conference = new Conference

Arrive.

conference.arrive('1/0')

Map.

conference.map('x', { call: 1 })

Reduce.

const reduction = conference.reduce('x', '1/0', { response: 1 })
okay(reduction, [{
    key: 'x',
    map: { call: 1 },
    reduce: { '1/0': { response: 1 } }
}], 'reduced')

More meaningful if you can imagine multiple participants. You track each arrival.

conference.arrive('2/0')
conference.arrive('3/0')

Map is called once.

conference.map('x', { call: 1 })

Reduce is called once for each member.

okay(conference.reduce('x', '1/0', { reduce: 1 }), [], 'only one of three responses')
okay(conference.reduce('x', '3/0', { reduce: 1 }), [], 'two of three responses')
const reduction = conference.reduce('x', '2/0', { reduce: 1 })
okay(reduction, [{
    key: 'x',
    map: { call: 1 },
    reduce: {
        '1/0': { reduce: 1 },
        '2/0': { reduce: 1 },
        '3/0': { reduce: 1 }
    }
}], 'all responses')

Convert ot array.

okay(Conference.toArray(reduction[0]), [{
    promise: '1/0', value: { reduce: 1 },
}, {
    promise: '3/0', value: { reduce: 1 },
}, {
    promise: '2/0', value: { reduce: 1 }
}], 'to array')

Makes it easier to perform reduce-like actions with JavaScript array functions.

const sum = Conference.toArray(reduction[0])
    .map(reduced => reduced.value.reduce)
    .reduce((sum, value) => sum + value, 0)
okay(sum, 3, 'summed')
conference.map('x', { call: 1 })
conference.map('y', { call: 2 })
conference.reduce('x', '1/0', { response: 1 })
conference.reduce('x', '3/0', { response: 1 })
conference.reduce('y', '1/0', { response: 2 })
conference.reduce('y', '3/0', { response: 2 })
const reduction = conference.depart('2/0')
okay(reduction, [{
    key: 'x',
    map: { call: 1 },
    reduce: { '1/0': { response: 1 }, '3/0': { response: 1 } }
}, {
    key: 'y',
    map: { call: 2 },
    reduce: { '1/0': { response: 2 }, '3/0': { response: 2 } }
}], 'reductions upon depart')

About

Framework communicating using a Compassion atomic log.

Topics

Resources

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE-e

Stars

Watchers

Forks

Packages

No packages published