describe 'mixco.value', ->
{Value, Reduce, Const, transform} = require '../../mixco/value'
describe 'Value', ->
it "is initialized to given value", ->
v = new Value initial: 5
expect(v.value).toBe 5
v = new Value initial: "hello"
expect(v.value).toBe "hello"
it "notifies when value changes", ->
callback = createSpy()
v = new Value
v.on 'value', callback
expect(callback).not.toHaveBeenCalled()
v.value = 5
expect(callback).toHaveBeenCalledWith 5
it "returns newly set value", ->
v = new Value
v.value = 5
expect(v.value).toBe 5
describe 'Reduce', ->
v = null
r = null
beforeEach ->
v = [
new Value initial: 1
new Value initial: 2
new Value initial: 3
]
r = new Reduce ((a, b) -> a + b), v...
it "reduces all given values with binary operation", ->
expect(r.value).toBe 6
it "updates when any of the values changes", ->
v[1].value = 0
expect(r.value).toBe 4
v[0].value = 5
expect(r.value).toBe 8
describe 'transform', ->
it "applies a nullary operation", ->
r = transform ((a) -> a*4), new Const 2
expect(r.value).toBe 8