volt 0.6.5 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Readme.md +47 -40
- data/VERSION +1 -1
- data/app/volt/controllers/notices_controller.rb +3 -3
- data/app/volt/tasks/live_query/data_store.rb +2 -2
- data/app/volt/tasks/live_query/live_query.rb +20 -20
- data/app/volt/tasks/live_query/live_query_pool.rb +6 -6
- data/app/volt/tasks/live_query/query_tracker.rb +15 -15
- data/app/volt/tasks/query_tasks.rb +13 -13
- data/app/volt/tasks/store_tasks.rb +7 -7
- data/app/volt/views/notices/index.html +17 -18
- data/lib/volt/assets/test.rb +2 -2
- data/lib/volt/benchmark/benchmark.rb +25 -23
- data/lib/volt/cli/asset_compile.rb +11 -0
- data/lib/volt/cli/new_gem.rb +16 -16
- data/lib/volt/cli.rb +14 -12
- data/lib/volt/console.rb +5 -6
- data/lib/volt/controllers/model_controller.rb +18 -18
- data/lib/volt/extra_core/array.rb +4 -4
- data/lib/volt/extra_core/hash.rb +3 -3
- data/lib/volt/extra_core/object.rb +6 -6
- data/lib/volt/extra_core/string.rb +6 -6
- data/lib/volt/extra_core/symbol.rb +5 -5
- data/lib/volt/extra_core/time.rb +4 -4
- data/lib/volt/extra_core/true_false.rb +6 -6
- data/lib/volt/extra_core/try.rb +9 -9
- data/lib/volt/models/array_model.rb +26 -26
- data/lib/volt/models/model.rb +35 -35
- data/lib/volt/models/model_hash_behaviour.rb +15 -15
- data/lib/volt/models/model_helpers.rb +8 -8
- data/lib/volt/models/model_wrapper.rb +6 -6
- data/lib/volt/models/persistors/array_store.rb +36 -36
- data/lib/volt/models/persistors/base.rb +6 -6
- data/lib/volt/models/persistors/flash.rb +5 -5
- data/lib/volt/models/persistors/model_identity_map.rb +2 -2
- data/lib/volt/models/persistors/model_store.rb +22 -22
- data/lib/volt/models/persistors/params.rb +3 -3
- data/lib/volt/models/persistors/query/query_listener.rb +14 -14
- data/lib/volt/models/persistors/query/query_listener_pool.rb +2 -2
- data/lib/volt/models/persistors/store.rb +8 -8
- data/lib/volt/models/persistors/store_factory.rb +2 -2
- data/lib/volt/models/url.rb +37 -37
- data/lib/volt/page/bindings/attribute_binding.rb +14 -14
- data/lib/volt/page/bindings/base_binding.rb +9 -9
- data/lib/volt/page/bindings/component_binding.rb +7 -7
- data/lib/volt/page/bindings/content_binding.rb +3 -3
- data/lib/volt/page/bindings/each_binding.rb +13 -13
- data/lib/volt/page/bindings/event_binding.rb +4 -4
- data/lib/volt/page/bindings/if_binding.rb +12 -12
- data/lib/volt/page/bindings/template_binding.rb +30 -30
- data/lib/volt/page/channel.rb +19 -19
- data/lib/volt/page/channel_stub.rb +6 -6
- data/lib/volt/page/document.rb +2 -2
- data/lib/volt/page/document_events.rb +4 -4
- data/lib/volt/page/draw_cycle.rb +3 -3
- data/lib/volt/page/memory_test.rb +6 -6
- data/lib/volt/page/page.rb +19 -19
- data/lib/volt/page/reactive_template.rb +9 -9
- data/lib/volt/page/sub_context.rb +5 -5
- data/lib/volt/page/targets/attribute_section.rb +9 -9
- data/lib/volt/page/targets/attribute_target.rb +3 -3
- data/lib/volt/page/targets/base_section.rb +2 -2
- data/lib/volt/page/targets/binding_document/component_node.rb +23 -23
- data/lib/volt/page/targets/binding_document/html_node.rb +2 -2
- data/lib/volt/page/targets/dom_section.rb +40 -38
- data/lib/volt/page/targets/dom_target.rb +2 -2
- data/lib/volt/page/tasks.rb +12 -12
- data/lib/volt/page/template_renderer.rb +4 -4
- data/lib/volt/page/url_tracker.rb +6 -6
- data/lib/volt/reactive/array_extensions.rb +2 -2
- data/lib/volt/reactive/destructive_methods.rb +5 -5
- data/lib/volt/reactive/event_chain.rb +25 -25
- data/lib/volt/reactive/events.rb +33 -33
- data/lib/volt/reactive/object_tracker.rb +21 -21
- data/lib/volt/reactive/object_tracking.rb +2 -2
- data/lib/volt/reactive/reactive_array.rb +57 -57
- data/lib/volt/reactive/reactive_tags.rb +16 -16
- data/lib/volt/reactive/reactive_value.rb +72 -72
- data/lib/volt/reactive/string_extensions.rb +3 -3
- data/lib/volt/router/routes.rb +22 -23
- data/lib/volt/server/component_handler.rb +5 -5
- data/lib/volt/server/component_templates.rb +14 -11
- data/lib/volt/server/html_parser/attribute_scope.rb +116 -0
- data/lib/volt/server/html_parser/each_scope.rb +18 -0
- data/lib/volt/server/html_parser/if_view_scope.rb +71 -0
- data/lib/volt/server/html_parser/sandlebars_parser.rb +219 -0
- data/lib/volt/server/html_parser/textarea_scope.rb +31 -0
- data/lib/volt/server/html_parser/view_handler.rb +82 -0
- data/lib/volt/server/html_parser/view_parser.rb +23 -0
- data/lib/volt/server/html_parser/view_scope.rb +145 -0
- data/lib/volt/server/rack/asset_files.rb +17 -17
- data/lib/volt/server/rack/component_paths.rb +18 -18
- data/lib/volt/server/rack/index_files.rb +8 -8
- data/lib/volt/server/rack/opal_files.rb +11 -11
- data/lib/volt/server/socket_connection_handler.rb +13 -13
- data/lib/volt/server/socket_connection_handler_stub.rb +2 -2
- data/lib/volt/server.rb +18 -18
- data/lib/volt/tasks/dispatcher.rb +5 -5
- data/lib/volt/utils/ejson.rb +2 -2
- data/lib/volt/utils/generic_counting_pool.rb +8 -8
- data/lib/volt/utils/generic_pool.rb +16 -16
- data/lib/volt/volt/environment.rb +4 -4
- data/lib/volt.rb +6 -6
- data/spec/integration/test_integration_spec.rb +2 -2
- data/spec/models/event_chain_spec.rb +38 -38
- data/spec/models/model_spec.rb +128 -128
- data/spec/models/old_model_spec.rb +17 -17
- data/spec/models/persistors/params_spec.rb +3 -3
- data/spec/models/persistors/store_spec.rb +7 -7
- data/spec/models/reactive_array_spec.rb +82 -82
- data/spec/models/reactive_generator_spec.rb +11 -11
- data/spec/models/reactive_tags_spec.rb +6 -6
- data/spec/models/reactive_value_spec.rb +70 -70
- data/spec/models/store_spec.rb +4 -4
- data/spec/models/string_extensions_spec.rb +13 -13
- data/spec/page/bindings/content_binding_spec.rb +6 -6
- data/spec/page/sub_context_spec.rb +1 -1
- data/spec/router/routes_spec.rb +3 -3
- data/spec/server/html_parser/sample_page.html +595 -0
- data/spec/server/html_parser/sandlebars_parser_spec.rb +192 -0
- data/spec/server/html_parser/view_parser_spec.rb +286 -0
- data/spec/server/rack/asset_files_spec.rb +6 -6
- data/spec/server/rack/component_paths_spec.rb +5 -5
- data/spec/spec_helper.rb +4 -5
- data/spec/store/mongo_spec.rb +3 -3
- data/spec/tasks/live_query_spec.rb +6 -6
- data/spec/tasks/query_tasks.rb +4 -4
- data/spec/tasks/query_tracker_spec.rb +20 -20
- data/spec/templates/targets/binding_document/component_node_spec.rb +4 -4
- data/spec/templates/template_binding_spec.rb +28 -28
- data/spec/utils/generic_counting_pool_spec.rb +5 -5
- data/spec/utils/generic_pool_spec.rb +14 -14
- data/templates/newgem/app/newgem/views/index/index.html +1 -2
- data/templates/project/app/home/config/dependencies.rb +1 -1
- data/templates/project/app/home/controllers/index_controller.rb +1 -1
- data/templates/project/app/home/views/index/about.html +4 -6
- data/templates/project/app/home/views/index/home.html +4 -5
- data/templates/project/app/home/views/index/index.html +8 -9
- data/templates/project/spec/spec_helper.rb +1 -1
- metadata +17 -8
- data/lib/volt/server/binding_setup.rb +0 -2
- data/lib/volt/server/if_binding_setup.rb +0 -31
- data/lib/volt/server/scope.rb +0 -43
- data/lib/volt/server/template_parser.rb +0 -453
- data/spec/server/template_parser_spec.rb +0 -50
|
@@ -1,67 +1,67 @@
|
|
|
1
1
|
# # require 'volt/spec_helper'
|
|
2
2
|
# require 'volt/models'
|
|
3
|
-
#
|
|
3
|
+
#
|
|
4
4
|
# describe Model do
|
|
5
|
-
#
|
|
6
|
-
#
|
|
5
|
+
#
|
|
6
|
+
#
|
|
7
7
|
# describe "user models" do
|
|
8
8
|
# class User < Model
|
|
9
9
|
# def full_name
|
|
10
10
|
# _first_name + _last_name
|
|
11
11
|
# end
|
|
12
12
|
# end
|
|
13
|
-
#
|
|
13
|
+
#
|
|
14
14
|
# class Info < Model ; end
|
|
15
|
-
#
|
|
15
|
+
#
|
|
16
16
|
# class Todo < Model ; end
|
|
17
|
-
#
|
|
17
|
+
#
|
|
18
18
|
# before do
|
|
19
19
|
# class_models = {
|
|
20
20
|
# ['*', '_user'] => User,
|
|
21
21
|
# ['*', '_info'] => Info,
|
|
22
22
|
# ['*', '_todo'] => Todo
|
|
23
23
|
# }
|
|
24
|
-
#
|
|
24
|
+
#
|
|
25
25
|
# @model = ReactiveValue.new(Model.new({}, nil, 'page', class_models))
|
|
26
26
|
# end
|
|
27
|
-
#
|
|
27
|
+
#
|
|
28
28
|
# it "should be loaded as the correct class" do
|
|
29
29
|
# @model._users << {_name: 'Test'}
|
|
30
30
|
# @model._users[0].cur.is_a?(User).should == true
|
|
31
31
|
# end
|
|
32
|
-
#
|
|
32
|
+
#
|
|
33
33
|
# it "should be loaded in as the correct class for single items" do
|
|
34
34
|
# @model._info._total_users = 5
|
|
35
35
|
# @model._info.cur.is_a?(Info).should == true
|
|
36
36
|
# end
|
|
37
|
-
#
|
|
37
|
+
#
|
|
38
38
|
# it "should load the correct nested class" do
|
|
39
39
|
# @model._todo_lists << {_name: 'Test1', _todos: []}
|
|
40
40
|
# @model._todo_lists[0]._todos << {_label: 'Do something'}
|
|
41
41
|
# @model._todo_lists[0]._todos[0].cur.is_a?(Todo).should == true
|
|
42
42
|
# end
|
|
43
|
-
#
|
|
43
|
+
#
|
|
44
44
|
# it "should assume the default model if used incorrectly" do
|
|
45
45
|
# @model._infos._something = 10
|
|
46
46
|
# @model._infos.cur.is_a?(Info).should == false
|
|
47
47
|
# end
|
|
48
|
-
#
|
|
48
|
+
#
|
|
49
49
|
# it "should keep lookups as children for any looked up value" do
|
|
50
50
|
# @model._users << {_first_name: 'Jim', _last_name: 'Bob'}
|
|
51
|
-
#
|
|
51
|
+
#
|
|
52
52
|
# @model._users.last.cur.is_a?(User).should == true
|
|
53
53
|
# # @model._users.last.full_name.dependents.parents.size.should == 2
|
|
54
54
|
# end
|
|
55
|
-
#
|
|
55
|
+
#
|
|
56
56
|
# it "should call changed on methods that depend on other values" do
|
|
57
57
|
# @model._users << {_first_name: 'Jim', _last_name: 'Bob'}
|
|
58
|
-
#
|
|
58
|
+
#
|
|
59
59
|
# count = 0
|
|
60
60
|
# @model._users.last.full_name.on('changed') { count += 1 }
|
|
61
61
|
# count.should == 0
|
|
62
|
-
#
|
|
62
|
+
#
|
|
63
63
|
# @model._users.last._first_name = 'James'
|
|
64
64
|
# count.should == 1
|
|
65
65
|
# end
|
|
66
66
|
# end
|
|
67
|
-
# end
|
|
67
|
+
# end
|
|
@@ -4,11 +4,11 @@ describe Persistors::Params do
|
|
|
4
4
|
it "should stay as params classes when used" do
|
|
5
5
|
a = Model.new({}, persistor: Persistors::Params)
|
|
6
6
|
expect(a._test.class).to eq(Model)
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
expect(a._test._cool.persistor.class).to eq(Persistors::Params)
|
|
9
|
-
|
|
9
|
+
|
|
10
10
|
a._items << {_name: 'Test'}
|
|
11
|
-
|
|
11
|
+
|
|
12
12
|
expect(a._items.persistor.class).to eq(Persistors::Params)
|
|
13
13
|
expect(a._items[0].persistor.class).to eq(Persistors::Params)
|
|
14
14
|
expect(a._items[0]._name.class).to eq(String)
|
|
@@ -6,24 +6,24 @@ describe Persistors::Store do
|
|
|
6
6
|
persistor_instance = double('persistor instance')
|
|
7
7
|
expect(persistor_instance).to receive(:loaded)
|
|
8
8
|
expect(persistor).to receive(:new).and_return(persistor_instance)
|
|
9
|
-
|
|
9
|
+
|
|
10
10
|
@model = Model.new(nil, persistor: persistor)
|
|
11
|
-
|
|
11
|
+
|
|
12
12
|
expect(persistor_instance).to receive(:changed)
|
|
13
|
-
|
|
13
|
+
|
|
14
14
|
@model._attr = 'yes'
|
|
15
15
|
end
|
|
16
|
-
|
|
16
|
+
|
|
17
17
|
it "should tell the persistor when something is added to an array model" do
|
|
18
18
|
persistor = double('persistor')
|
|
19
19
|
persistor_instance = double('persistor instance')
|
|
20
20
|
expect(persistor_instance).to receive(:loaded)
|
|
21
21
|
expect(persistor).to receive(:new).and_return(persistor_instance)
|
|
22
|
-
|
|
22
|
+
|
|
23
23
|
@model = ArrayModel.new([1,2,3], persistor: persistor)
|
|
24
|
-
|
|
24
|
+
|
|
25
25
|
expect(persistor_instance).to receive(:added).with(4,3)
|
|
26
|
-
|
|
26
|
+
|
|
27
27
|
@model << 4
|
|
28
28
|
end
|
|
29
29
|
end
|
|
@@ -3,90 +3,90 @@ require 'volt/models'
|
|
|
3
3
|
describe ReactiveArray do
|
|
4
4
|
it "should trigger a change event on any ReactiveValues derived from items in the array" do
|
|
5
5
|
model = ReactiveValue.new(Model.new)
|
|
6
|
-
|
|
6
|
+
|
|
7
7
|
model._my_ary = [1,2,3]
|
|
8
|
-
|
|
8
|
+
|
|
9
9
|
array_one_item = model._my_ary[4]
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
@changed = false
|
|
12
12
|
array_one_item.on('changed') { @changed = true }
|
|
13
13
|
expect(@changed).to eq(false)
|
|
14
|
-
|
|
14
|
+
|
|
15
15
|
model._my_ary.insert(0,1,2)
|
|
16
|
-
|
|
16
|
+
|
|
17
17
|
expect(@changed).to eq(true)
|
|
18
18
|
end
|
|
19
|
-
|
|
19
|
+
|
|
20
20
|
it "should trigger changed from an insert in all places after the index" do
|
|
21
21
|
model = ReactiveValue.new(Model.new)
|
|
22
22
|
model._my_ary = [1,2,3]
|
|
23
|
-
|
|
23
|
+
|
|
24
24
|
count1 = 0
|
|
25
25
|
count2 = 0
|
|
26
26
|
model._my_ary[1].on('changed') { count1 += 1 }
|
|
27
27
|
model._my_ary[3].on('changed') { count2 += 1 }
|
|
28
28
|
expect(count1).to eq(0)
|
|
29
29
|
expect(count2).to eq(0)
|
|
30
|
-
|
|
30
|
+
|
|
31
31
|
model._my_ary.insert(1, 10)
|
|
32
32
|
expect(count1).to eq(1)
|
|
33
33
|
expect(count2).to eq(1)
|
|
34
|
-
|
|
34
|
+
|
|
35
35
|
expect(model._my_ary.cur).to eq([1,10,2,3])
|
|
36
36
|
end
|
|
37
|
-
|
|
37
|
+
|
|
38
38
|
it "should pass the index the item was inserted at" do
|
|
39
39
|
model = ReactiveValue.new(Model.new)
|
|
40
40
|
model._my_ary = [1,2,3]
|
|
41
|
-
|
|
41
|
+
|
|
42
42
|
model._my_ary.on('added') do |_, index|
|
|
43
43
|
expect(index).to eq(2)
|
|
44
44
|
end
|
|
45
|
-
|
|
45
|
+
|
|
46
46
|
model._my_ary.insert(2, 20)
|
|
47
47
|
end
|
|
48
|
-
|
|
48
|
+
|
|
49
49
|
it "should pass the index the item was inserted at with multiple inserted objects" do
|
|
50
50
|
model = ReactiveValue.new(Model.new)
|
|
51
51
|
model._my_ary = [1,2,3]
|
|
52
|
-
|
|
52
|
+
|
|
53
53
|
received = []
|
|
54
54
|
model._my_ary.on('added') do |_, index|
|
|
55
55
|
received << index
|
|
56
56
|
end
|
|
57
|
-
|
|
57
|
+
|
|
58
58
|
model._my_ary.insert(2, 20, 30)
|
|
59
|
-
|
|
59
|
+
|
|
60
60
|
expect(received).to eq([2, 3])
|
|
61
61
|
end
|
|
62
|
-
|
|
62
|
+
|
|
63
63
|
it "should trigger changed on methods of an array model that involve just one cell" do
|
|
64
64
|
model = ReactiveValue.new(ReactiveArray.new)
|
|
65
|
-
|
|
65
|
+
|
|
66
66
|
model << 1
|
|
67
67
|
model << 2
|
|
68
68
|
model << 3
|
|
69
|
-
|
|
69
|
+
|
|
70
70
|
max = model.max
|
|
71
71
|
expect(max.cur).to eq(3)
|
|
72
|
-
|
|
72
|
+
|
|
73
73
|
count = 0
|
|
74
74
|
max.on('changed') { count += 1 }
|
|
75
75
|
expect(count).to eq(0)
|
|
76
|
-
|
|
76
|
+
|
|
77
77
|
model[0] = 10
|
|
78
|
-
|
|
78
|
+
|
|
79
79
|
expect(count).to eq(1)
|
|
80
80
|
expect(max.cur).to eq(10)
|
|
81
81
|
end
|
|
82
|
-
|
|
82
|
+
|
|
83
83
|
it "should not trigger changed events on cells that are not being updated" do
|
|
84
84
|
model = ReactiveValue.new(ArrayModel.new([]))
|
|
85
|
-
|
|
85
|
+
|
|
86
86
|
model << 1
|
|
87
87
|
model << 2
|
|
88
88
|
model << 3
|
|
89
|
-
|
|
89
|
+
|
|
90
90
|
index_0_count = 0
|
|
91
91
|
last_count = 0
|
|
92
92
|
sum_count = 0
|
|
@@ -94,74 +94,74 @@ describe ReactiveArray do
|
|
|
94
94
|
model.last.on('changed') { last_count += 1 }
|
|
95
95
|
model.sum.on('changed') { sum_count += 1 }
|
|
96
96
|
model[1] = 20
|
|
97
|
-
|
|
97
|
+
|
|
98
98
|
expect(index_0_count).to eq(0)
|
|
99
99
|
expect(sum_count).to eq(1)
|
|
100
100
|
expect(last_count).to eq(0)
|
|
101
|
-
|
|
101
|
+
|
|
102
102
|
expect(model[0].cur).to eq(1)
|
|
103
103
|
expect(model[1].cur).to eq(20)
|
|
104
104
|
expect(model[2].cur).to eq(3)
|
|
105
105
|
expect(model.last.cur).to eq(3)
|
|
106
106
|
expect(model.sum.cur).to eq(24)
|
|
107
|
-
|
|
107
|
+
|
|
108
108
|
model[2] = 100
|
|
109
109
|
expect(last_count).to eq(1)
|
|
110
110
|
end
|
|
111
|
-
|
|
111
|
+
|
|
112
112
|
it "should trigger added when an element is added" do
|
|
113
113
|
a = ReactiveValue.new(Model.new)
|
|
114
114
|
count = 0
|
|
115
115
|
a._items.on('added') { count += 1 }
|
|
116
116
|
expect(count).to eq(0)
|
|
117
|
-
|
|
117
|
+
|
|
118
118
|
a._items << 1
|
|
119
119
|
expect(count).to eq(1)
|
|
120
120
|
end
|
|
121
|
-
|
|
121
|
+
|
|
122
122
|
it "should trigger updates when appending" do
|
|
123
123
|
[:size, :length, :count, :last].each do |attribute|
|
|
124
124
|
a = ReactiveValue.new(ReactiveArray.new([1,2,3]))
|
|
125
|
-
|
|
125
|
+
|
|
126
126
|
count = 0
|
|
127
127
|
val = a.send(attribute)
|
|
128
128
|
old_value = val.cur
|
|
129
129
|
val.on('changed') { count += 1 }
|
|
130
130
|
expect(count).to eq(0)
|
|
131
|
-
|
|
131
|
+
|
|
132
132
|
added_count = 0
|
|
133
133
|
a.on('added') { added_count += 1 }
|
|
134
134
|
expect(added_count).to eq(0)
|
|
135
|
-
|
|
135
|
+
|
|
136
136
|
a << 4
|
|
137
|
-
|
|
137
|
+
|
|
138
138
|
expect(val.cur).to eq(old_value + 1)
|
|
139
139
|
expect(count).to eq(1)
|
|
140
|
-
|
|
140
|
+
|
|
141
141
|
expect(added_count).to eq(1)
|
|
142
142
|
end
|
|
143
143
|
end
|
|
144
|
-
|
|
144
|
+
|
|
145
145
|
describe "real world type specs" do
|
|
146
146
|
it "should let you add in another array" do
|
|
147
147
|
a = ReactiveValue.new(ReactiveArray.new([1,2,3]))
|
|
148
|
-
|
|
148
|
+
|
|
149
149
|
pos_4 = a[4]
|
|
150
150
|
expect(pos_4.cur).to eq(nil)
|
|
151
151
|
pos_4_changed = 0
|
|
152
152
|
pos_4.on('changed') { pos_4_changed += 1 }
|
|
153
|
-
|
|
153
|
+
|
|
154
154
|
count = 0
|
|
155
155
|
a.on('added') { count += 1 }
|
|
156
|
-
|
|
156
|
+
|
|
157
157
|
a += [4,5,6]
|
|
158
158
|
expect(a.cur).to eq([1,2,3,4,5,6])
|
|
159
159
|
# TODO: Failing?
|
|
160
160
|
# expect(pos_4_changed).to eq(1)
|
|
161
|
-
|
|
161
|
+
|
|
162
162
|
# expect(count).to eq(3)
|
|
163
163
|
end
|
|
164
|
-
|
|
164
|
+
|
|
165
165
|
it "should trigger changes when an index that is Reactive changes" do
|
|
166
166
|
index = ReactiveValue.new(0)
|
|
167
167
|
model = ReactiveValue.new(Model.new)
|
|
@@ -169,23 +169,23 @@ describe ReactiveArray do
|
|
|
169
169
|
model._array << 2
|
|
170
170
|
model._array << 3
|
|
171
171
|
b = model._array[index]
|
|
172
|
-
|
|
172
|
+
|
|
173
173
|
direct_count = 0
|
|
174
174
|
b.on('changed') { direct_count += 1 }
|
|
175
175
|
expect(direct_count).to eq(0)
|
|
176
|
-
|
|
176
|
+
|
|
177
177
|
model._current_array = b
|
|
178
|
-
|
|
178
|
+
|
|
179
179
|
count = 0
|
|
180
|
-
|
|
180
|
+
|
|
181
181
|
model._current_array.on('changed') { count += 1 }
|
|
182
182
|
expect(count).to eq(0)
|
|
183
|
-
|
|
183
|
+
|
|
184
184
|
index.cur = 1
|
|
185
185
|
expect(count).to eq(1)
|
|
186
186
|
expect(direct_count).to eq(1)
|
|
187
187
|
end
|
|
188
|
-
|
|
188
|
+
|
|
189
189
|
it "should trigger changes when cell data changes when using ReactiveValue's as indicies" do
|
|
190
190
|
index = ReactiveValue.new(0)
|
|
191
191
|
index2 = ReactiveValue.new(0)
|
|
@@ -193,113 +193,113 @@ describe ReactiveArray do
|
|
|
193
193
|
model._array << 1
|
|
194
194
|
model._array << 2
|
|
195
195
|
model._array << 3
|
|
196
|
-
|
|
197
|
-
zero_cell = model._array[index]
|
|
196
|
+
|
|
197
|
+
zero_cell = model._array[index]
|
|
198
198
|
zero_cell2 = model._array[index2]
|
|
199
|
-
|
|
199
|
+
|
|
200
200
|
count = 0
|
|
201
201
|
count2 = 0
|
|
202
202
|
zero_cell.on('changed') { count += 1 }
|
|
203
203
|
zero_cell2.on('changed') { count2 += 1 }
|
|
204
|
-
|
|
204
|
+
|
|
205
205
|
zero_cell.cur = 3
|
|
206
|
-
|
|
206
|
+
|
|
207
207
|
expect(count).to eq(1)
|
|
208
208
|
expect(count2).to eq(1)
|
|
209
209
|
end
|
|
210
|
-
|
|
211
|
-
|
|
210
|
+
|
|
211
|
+
|
|
212
212
|
it "should call added on an array within an array" do
|
|
213
213
|
a = ReactiveValue.new(Model.new)
|
|
214
214
|
index = ReactiveValue.new(0)
|
|
215
215
|
count = 0
|
|
216
216
|
a._items << ArrayModel.new([])
|
|
217
|
-
|
|
217
|
+
|
|
218
218
|
a._items[0].on('added') { count += 1 }
|
|
219
219
|
expect(count).to eq(0)
|
|
220
|
-
|
|
220
|
+
|
|
221
221
|
a._items[0] << 1
|
|
222
222
|
expect(count).to eq(1)
|
|
223
|
-
|
|
223
|
+
|
|
224
224
|
end
|
|
225
|
-
|
|
225
|
+
|
|
226
226
|
# TODO: Needs to be fixed
|
|
227
227
|
# it "should call added through an index from one array to a sub array" do
|
|
228
228
|
# model = ReactiveValue.new(Model.new)
|
|
229
229
|
# index = ReactiveValue.new(nil)
|
|
230
|
-
#
|
|
230
|
+
#
|
|
231
231
|
# count = 0
|
|
232
232
|
# model._current_todo._todos.on('added') { count += 1 }
|
|
233
233
|
# expect(count).to eq(0)
|
|
234
|
-
#
|
|
234
|
+
#
|
|
235
235
|
# model._todo_lists << Model.new(_name: 'One', _todos: [])
|
|
236
236
|
# model._todo_lists << Model.new(_name: 'Two', _todos: [])
|
|
237
|
-
#
|
|
237
|
+
#
|
|
238
238
|
# model._current_todo = model._todo_lists[0]
|
|
239
|
-
#
|
|
239
|
+
#
|
|
240
240
|
# model._current_todo._todos << "Svoltle todo"
|
|
241
241
|
# expect(count).to eq(1)
|
|
242
242
|
# end
|
|
243
|
-
|
|
243
|
+
|
|
244
244
|
it "should trigger changed when an item is deleted" do
|
|
245
245
|
model = ReactiveValue.new(Model.new)
|
|
246
246
|
model._items = [1,2,3]
|
|
247
|
-
|
|
247
|
+
|
|
248
248
|
cur = model._current = model._items[0]
|
|
249
|
-
|
|
249
|
+
|
|
250
250
|
count = 0
|
|
251
251
|
# model._items[0].on('changed') { count += 1}
|
|
252
252
|
model._current.on('changed') { count += 1 }
|
|
253
253
|
expect(count).to eq(0)
|
|
254
|
-
|
|
254
|
+
|
|
255
255
|
ObjectTracker.process_queue
|
|
256
256
|
model._items.delete_at(0)
|
|
257
|
-
|
|
257
|
+
|
|
258
258
|
expect(count).to eq(1)
|
|
259
259
|
end
|
|
260
|
-
|
|
260
|
+
|
|
261
261
|
it "should not trigger changed on the array when an element is added" do
|
|
262
262
|
a = ReactiveValue.new(Model.new)
|
|
263
263
|
a._items = []
|
|
264
|
-
|
|
264
|
+
|
|
265
265
|
count = 0
|
|
266
266
|
a._items.on('changed') { count += 1}
|
|
267
267
|
expect(count).to eq(0)
|
|
268
|
-
|
|
268
|
+
|
|
269
269
|
a._items << 1
|
|
270
270
|
expect(count).to eq(0)
|
|
271
271
|
end
|
|
272
|
-
|
|
272
|
+
|
|
273
273
|
it "should trigger changed for a Reactive index and a non-reactive index with the same value" do
|
|
274
274
|
a = ReactiveValue.new(Model.new)
|
|
275
275
|
index = ReactiveValue.new(0)
|
|
276
276
|
a._items << 0
|
|
277
277
|
a._items << 1
|
|
278
|
-
|
|
278
|
+
|
|
279
279
|
count = 0
|
|
280
280
|
a._items[0].on('changed') { count += 1 }
|
|
281
281
|
expect(count).to eq(0)
|
|
282
|
-
|
|
282
|
+
|
|
283
283
|
a._items[index] = 5
|
|
284
284
|
expect(count).to eq(1)
|
|
285
|
-
|
|
285
|
+
|
|
286
286
|
# Reversed
|
|
287
287
|
count2 = 0
|
|
288
288
|
a._items[index].on('changed') { count2 += 1 }
|
|
289
289
|
expect(count2).to eq(0)
|
|
290
|
-
|
|
290
|
+
|
|
291
291
|
index.cur = 1
|
|
292
|
-
|
|
292
|
+
|
|
293
293
|
# Double update since one is bound to a Integer and one to a ReactiveValue
|
|
294
294
|
# TODO: Any way to combine these
|
|
295
295
|
expect(count2).to eq(2)
|
|
296
|
-
|
|
296
|
+
|
|
297
297
|
a._items[1] = 2
|
|
298
298
|
expect(count2).to eq(3)
|
|
299
|
-
|
|
299
|
+
|
|
300
300
|
# a._items[index] = 10
|
|
301
|
-
|
|
302
|
-
|
|
301
|
+
|
|
302
|
+
|
|
303
303
|
end
|
|
304
304
|
end
|
|
305
|
-
end
|
|
305
|
+
end
|
|
@@ -13,27 +13,27 @@ describe ReactiveGenerator do
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
end
|
|
16
|
-
|
|
17
|
-
it "should find all reactive values in any object" do
|
|
16
|
+
|
|
17
|
+
it "should find all reactive values in any object" do
|
|
18
18
|
values = ReactiveGenerator.find_reactives(@object)
|
|
19
|
-
|
|
19
|
+
|
|
20
20
|
expect(values.map(&:cur)).to eq(['bob', 'Bozeman', 'The Garage', 'Ale Works'])
|
|
21
21
|
end
|
|
22
|
-
|
|
22
|
+
|
|
23
23
|
it "should return a reactive value that changes whenever a child reactive value changes" do
|
|
24
24
|
values = ReactiveGenerator.from_hash(@object)
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
count = 0
|
|
27
27
|
values.on('changed') { count += 1 }
|
|
28
28
|
expect(count).to eq(0)
|
|
29
|
-
|
|
29
|
+
|
|
30
30
|
@object[:name].cur = 'jim'
|
|
31
|
-
|
|
31
|
+
|
|
32
32
|
expect(count).to eq(1)
|
|
33
|
-
|
|
33
|
+
|
|
34
34
|
@object[:location][:places].last.cur = 'Starkies'
|
|
35
35
|
expect(count).to eq(2)
|
|
36
|
-
|
|
36
|
+
|
|
37
37
|
expect(values.to_h).to eq({
|
|
38
38
|
name: 'jim',
|
|
39
39
|
location: {
|
|
@@ -45,7 +45,7 @@ describe ReactiveGenerator do
|
|
|
45
45
|
}
|
|
46
46
|
})
|
|
47
47
|
end
|
|
48
|
-
|
|
48
|
+
|
|
49
49
|
it "should optionally return a normal hash if there are no child reactive values" do
|
|
50
50
|
values = ReactiveGenerator.from_hash({name: 'bob'})
|
|
51
51
|
expect(values.reactive?).to eq(true)
|
|
@@ -55,4 +55,4 @@ describe ReactiveGenerator do
|
|
|
55
55
|
expect(values.reactive?).to eq(false)
|
|
56
56
|
expect(values.is_a?(Hash)).to eq(true)
|
|
57
57
|
end
|
|
58
|
-
end
|
|
58
|
+
end
|
|
@@ -2,14 +2,14 @@ require 'volt/models'
|
|
|
2
2
|
|
|
3
3
|
class TestCustomClass
|
|
4
4
|
include ReactiveTags
|
|
5
|
-
|
|
5
|
+
|
|
6
6
|
tag_method(:cool) do
|
|
7
7
|
destructive!
|
|
8
8
|
end
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
class TestSubClass < TestCustomClass
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
class TestInherit < TestCustomClass
|
|
@@ -18,18 +18,18 @@ class TestInherit < TestCustomClass
|
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
describe ReactiveTags do
|
|
21
|
+
describe ReactiveTags do
|
|
22
22
|
it "should tag correctly" do
|
|
23
23
|
expect(TestCustomClass.new.reactive_method_tag(:cool, :destructive)).to eq(true)
|
|
24
24
|
end
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
it "should include tags in a subclass" do
|
|
27
27
|
expect(TestSubClass.new.reactive_method_tag(:cool, :destructive)).to eq(true)
|
|
28
28
|
expect(TestSubClass.new.reactive_method_tag(:cool, :pass_reactive)).to eq(nil)
|
|
29
29
|
end
|
|
30
|
-
|
|
30
|
+
|
|
31
31
|
it "should inherit" do
|
|
32
32
|
expect(TestInherit.new.reactive_method_tag(:cool, :destructive)).to eq(true)
|
|
33
33
|
expect(TestInherit.new.reactive_method_tag(:cool, :pass_reactive)).to eq(true)
|
|
34
34
|
end
|
|
35
|
-
end
|
|
35
|
+
end
|