Sha256: b99993f24019adaa707683e70ff5a5a476e9dbb7395ad57ca37eaa1b1a3d54e2
Contents?: true
Size: 1.43 KB
Versions: 23
Compression:
Stored size: 1.43 KB
Contents
require 'volt/models' describe ReactiveGenerator do before do @object = { name: ReactiveValue.new('bob'), location: { town: ReactiveValue.new('Bozeman'), places: [ ReactiveValue.new('The Garage'), ReactiveValue.new('Ale Works') ] } } end it "should find all reactive values in any object" do values = ReactiveGenerator.find_reactives(@object) expect(values.map(&:cur)).to eq(['bob', 'Bozeman', 'The Garage', 'Ale Works']) end it "should return a reactive value that changes whenever a child reactive value changes" do values = ReactiveGenerator.from_hash(@object) count = 0 values.on('changed') { count += 1 } expect(count).to eq(0) @object[:name].cur = 'jim' expect(count).to eq(1) @object[:location][:places].last.cur = 'Starkies' expect(count).to eq(2) expect(values.to_h).to eq({ name: 'jim', location: { town: 'Bozeman', places: [ 'The Garage', 'Starkies' ] } }) end it "should optionally return a normal hash if there are no child reactive values" do values = ReactiveGenerator.from_hash({name: 'bob'}) expect(values.reactive?).to eq(true) expect(values.is_a?(Hash)).to eq(false) values = ReactiveGenerator.from_hash({name: 'bob'}, true) expect(values.reactive?).to eq(false) expect(values.is_a?(Hash)).to eq(true) end end
Version data entries
23 entries across 23 versions & 1 rubygems