Sha256: a5e8e93037f5d579656af5fb062afc69e4ade5db85241b26b7d2d4e12c9f5c8c

Contents?: true

Size: 1.21 KB

Versions: 15

Compression:

Stored size: 1.21 KB

Contents

require 'spec_helper'

describe Volt::Computation do
  it 'should trigger again when a dependent changes' do
    a = Volt::ReactiveHash.new

    values = []

    -> { values << a[0] }.watch!

    expect(values).to eq([nil])

    a[0] = 'one'
    Volt::Computation.flush!
    expect(values).to eq([nil, 'one'])

    a[0] = 'two'
    Volt::Computation.flush!
    expect(values).to eq([nil, 'one', 'two'])
  end

  it 'should not trigger after the computation is stopped' do
    a = Volt::ReactiveHash.new

    values = []
    computation = -> { values << a[0] }.watch!

    expect(values).to eq([nil])

    a[0] = 'one'
    Volt::Computation.flush!
    expect(values).to eq([nil, 'one'])

    computation.stop

    a[0] = 'two'
    Volt::Computation.flush!
    expect(values).to eq([nil, 'one'])
  end

  it 'should support nested watches' do
    a = Volt::ReactiveHash.new

    values = []
    -> do
      values << a[0]

      -> do
        values << a[1]
      end.watch!
    end.watch!

    expect(values).to eq([nil, nil])

    a[1] = 'inner'
    Volt::Computation.flush!
    expect(values).to eq([nil, nil, 'inner'])

    a[0] = 'outer'
    Volt::Computation.flush!
    expect(values).to eq([nil, nil, 'inner', 'outer', 'inner'])
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
volt-0.8.27.beta2 spec/reactive/computation_spec.rb
volt-0.8.27.beta1 spec/reactive/computation_spec.rb
volt-0.8.26.beta1 spec/reactive/computation_spec.rb
volt-0.8.26 spec/reactive/computation_spec.rb
volt-0.8.24 spec/reactive/computation_spec.rb
volt-0.8.23 spec/reactive/computation_spec.rb
volt-0.8.22 spec/reactive/computation_spec.rb
volt-0.8.22.beta2 spec/reactive/computation_spec.rb
volt-0.8.22.beta1 spec/reactive/computation_spec.rb
volt-0.8.21 spec/reactive/computation_spec.rb
volt-0.8.20 spec/reactive/computation_spec.rb
volt-0.8.19 spec/reactive/computation_spec.rb
volt-0.8.18 spec/reactive/computation_spec.rb
volt-0.8.17 spec/reactive/computation_spec.rb
volt-0.8.16 spec/reactive/computation_spec.rb