volt 0.8.14 → 0.8.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/Readme.md +8 -2
- data/VERSION +1 -1
- data/app/volt/controllers/notices_controller.rb +1 -1
- data/app/volt/models/user.rb +2 -2
- data/app/volt/tasks/live_query/live_query_pool.rb +1 -1
- data/app/volt/tasks/query_tasks.rb +1 -1
- data/app/volt/tasks/store_tasks.rb +1 -1
- data/app/volt/tasks/user_tasks.rb +2 -2
- data/lib/volt/boot.rb +2 -2
- data/lib/volt/cli/asset_compile.rb +31 -27
- data/lib/volt/cli.rb +64 -65
- data/lib/volt/config.rb +25 -23
- data/lib/volt/console.rb +17 -16
- data/lib/volt/controllers/model_controller.rb +82 -80
- data/lib/volt/data_stores/data_store.rb +2 -2
- data/lib/volt/data_stores/mongo_driver.rb +2 -2
- data/lib/volt/extra_core/inflections.rb +2 -2
- data/lib/volt/extra_core/inflector/inflections.rb +185 -183
- data/lib/volt/extra_core/inflector/methods.rb +50 -48
- data/lib/volt/extra_core/string.rb +2 -2
- data/lib/volt/models/array_model.rb +93 -92
- data/lib/volt/models/cursor.rb +3 -2
- data/lib/volt/models/model.rb +248 -251
- data/lib/volt/models/model_hash_behaviour.rb +44 -44
- data/lib/volt/models/model_helpers.rb +38 -36
- data/lib/volt/models/model_state.rb +16 -17
- data/lib/volt/models/model_wrapper.rb +25 -24
- data/lib/volt/models/persistors/array_store.rb +145 -143
- data/lib/volt/models/persistors/base.rb +18 -16
- data/lib/volt/models/persistors/flash.rb +24 -22
- data/lib/volt/models/persistors/local_store.rb +46 -44
- data/lib/volt/models/persistors/model_identity_map.rb +10 -8
- data/lib/volt/models/persistors/model_store.rb +76 -76
- data/lib/volt/models/persistors/params.rb +19 -17
- data/lib/volt/models/persistors/query/query_listener.rb +65 -63
- data/lib/volt/models/persistors/query/query_listener_pool.rb +12 -10
- data/lib/volt/models/persistors/store.rb +28 -28
- data/lib/volt/models/persistors/store_factory.rb +12 -10
- data/lib/volt/models/persistors/store_state.rb +33 -31
- data/lib/volt/models/url.rb +96 -104
- data/lib/volt/models/validations.rb +56 -54
- data/lib/volt/models/validators/length_validator.rb +24 -22
- data/lib/volt/models/validators/presence_validator.rb +14 -12
- data/lib/volt/page/bindings/attribute_binding.rb +106 -106
- data/lib/volt/page/bindings/base_binding.rb +23 -21
- data/lib/volt/page/bindings/component_binding.rb +3 -1
- data/lib/volt/page/bindings/content_binding.rb +34 -34
- data/lib/volt/page/bindings/each_binding.rb +113 -113
- data/lib/volt/page/bindings/event_binding.rb +38 -34
- data/lib/volt/page/bindings/if_binding.rb +56 -54
- data/lib/volt/page/bindings/template_binding/grouped_controllers.rb +24 -22
- data/lib/volt/page/bindings/template_binding.rb +182 -185
- data/lib/volt/page/channel.rb +79 -77
- data/lib/volt/page/channel_stub.rb +29 -27
- data/lib/volt/page/document.rb +6 -5
- data/lib/volt/page/document_events.rb +54 -52
- data/lib/volt/page/page.rb +139 -138
- data/lib/volt/page/string_template_renderer.rb +36 -36
- data/lib/volt/page/sub_context.rb +26 -25
- data/lib/volt/page/targets/attribute_section.rb +27 -25
- data/lib/volt/page/targets/attribute_target.rb +7 -6
- data/lib/volt/page/targets/base_section.rb +27 -26
- data/lib/volt/page/targets/binding_document/base_node.rb +3 -1
- data/lib/volt/page/targets/binding_document/component_node.rb +85 -82
- data/lib/volt/page/targets/binding_document/html_node.rb +11 -9
- data/lib/volt/page/targets/dom_section.rb +78 -77
- data/lib/volt/page/targets/dom_target.rb +8 -6
- data/lib/volt/page/targets/dom_template.rb +90 -88
- data/lib/volt/page/targets/helpers/comment_searchers.rb +51 -49
- data/lib/volt/page/tasks.rb +59 -57
- data/lib/volt/page/template_renderer.rb +17 -14
- data/lib/volt/page/url_tracker.rb +26 -24
- data/lib/volt/reactive/computation.rb +87 -88
- data/lib/volt/reactive/dependency.rb +30 -28
- data/lib/volt/reactive/eventable.rb +64 -62
- data/lib/volt/reactive/hash_dependency.rb +25 -23
- data/lib/volt/reactive/reactive_accessors.rb +34 -32
- data/lib/volt/reactive/reactive_array.rb +162 -162
- data/lib/volt/reactive/reactive_hash.rb +37 -35
- data/lib/volt/router/routes.rb +99 -101
- data/lib/volt/server/component_handler.rb +20 -21
- data/lib/volt/server/component_templates.rb +72 -70
- data/lib/volt/server/html_parser/attribute_scope.rb +109 -99
- data/lib/volt/server/html_parser/each_scope.rb +17 -16
- data/lib/volt/server/html_parser/if_view_scope.rb +51 -49
- data/lib/volt/server/html_parser/sandlebars_parser.rb +184 -177
- data/lib/volt/server/html_parser/textarea_scope.rb +24 -22
- data/lib/volt/server/html_parser/view_handler.rb +66 -65
- data/lib/volt/server/html_parser/view_parser.rb +23 -21
- data/lib/volt/server/html_parser/view_scope.rb +142 -141
- data/lib/volt/server/rack/asset_files.rb +81 -79
- data/lib/volt/server/rack/component_code.rb +17 -15
- data/lib/volt/server/rack/component_html_renderer.rb +14 -12
- data/lib/volt/server/rack/component_paths.rb +72 -71
- data/lib/volt/server/rack/index_files.rb +36 -39
- data/lib/volt/server/rack/opal_files.rb +43 -41
- data/lib/volt/server/rack/source_map_server.rb +23 -21
- data/lib/volt/server/socket_connection_handler.rb +46 -45
- data/lib/volt/server/socket_connection_handler_stub.rb +21 -19
- data/lib/volt/server.rb +60 -58
- data/lib/volt/spec/setup.rb +3 -3
- data/lib/volt/tasks/dispatcher.rb +24 -23
- data/lib/volt/tasks/task_handler.rb +35 -33
- data/lib/volt/utils/ejson.rb +8 -6
- data/lib/volt/utils/generic_counting_pool.rb +33 -31
- data/lib/volt/utils/generic_pool.rb +73 -70
- data/lib/volt/utils/local_storage.rb +42 -38
- data/lib/volt/volt/environment.rb +1 -1
- data/lib/volt.rb +44 -42
- data/spec/apps/kitchen_sink/app/main/assets/css/todos.css +28 -0
- data/spec/apps/kitchen_sink/app/main/config/routes.rb +1 -0
- data/spec/apps/kitchen_sink/app/main/controllers/main_controller.rb +2 -2
- data/spec/apps/kitchen_sink/app/main/controllers/todos_controller.rb +17 -0
- data/spec/apps/kitchen_sink/app/main/views/main/main.html +1 -0
- data/spec/apps/kitchen_sink/app/main/views/todos/index.html +24 -0
- data/spec/apps/kitchen_sink/config.ru +1 -1
- data/spec/controllers/reactive_accessors_spec.rb +5 -5
- data/spec/extra_core/inflector_spec.rb +2 -2
- data/spec/integration/list_spec.rb +68 -0
- data/spec/models/model_spec.rb +57 -57
- data/spec/models/persistors/params_spec.rb +6 -6
- data/spec/models/persistors/store_spec.rb +7 -7
- data/spec/models/validations_spec.rb +3 -3
- data/spec/page/bindings/content_binding_spec.rb +7 -7
- data/spec/page/bindings/template_binding_spec.rb +4 -5
- data/spec/page/sub_context_spec.rb +2 -2
- data/spec/reactive/computation_spec.rb +10 -10
- data/spec/reactive/dependency_spec.rb +2 -2
- data/spec/reactive/eventable_spec.rb +4 -4
- data/spec/reactive/reactive_array_spec.rb +13 -13
- data/spec/router/routes_spec.rb +5 -5
- data/spec/server/html_parser/sandlebars_parser_spec.rb +9 -9
- data/spec/server/html_parser/view_parser_spec.rb +27 -27
- data/spec/server/rack/asset_files_spec.rb +5 -5
- data/spec/server/rack/component_paths_spec.rb +2 -2
- data/spec/tasks/live_query_spec.rb +2 -2
- data/spec/tasks/query_tasks.rb +1 -1
- data/spec/tasks/query_tracker_spec.rb +1 -1
- data/spec/templates/targets/binding_document/component_node_spec.rb +2 -2
- data/spec/utils/generic_counting_pool_spec.rb +2 -2
- data/spec/utils/generic_pool_spec.rb +2 -2
- data/templates/component/controllers/main_controller.rb +1 -1
- data/templates/model/model.rb.tt +2 -2
- data/templates/newgem/app/newgem/controllers/main_controller.rb.tt +2 -2
- data/templates/project/app/main/controllers/main_controller.rb +1 -1
- data/templates/project/config.ru +1 -1
- metadata +10 -3
- data/app/volt/assets/js/vertxbus.js +0 -216
@@ -1,232 +1,234 @@
|
|
1
1
|
require 'volt/reactive/eventable'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
3
|
+
module Volt
|
4
|
+
class ReactiveArray
|
5
|
+
include Eventable
|
6
|
+
|
7
|
+
def initialize(array=[])
|
8
|
+
@array = array
|
9
|
+
@array_deps = []
|
10
|
+
@size_dep = Dependency.new
|
11
|
+
@old_size = 0
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
# Forward any missing methods to the array
|
15
|
+
def method_missing(method_name, *args, &block)
|
16
|
+
@array.send(method_name, *args, &block)
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
def ==(*args)
|
20
|
+
@array.==(*args)
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
# At the moment, each just passes through.
|
24
|
+
def each(&block)
|
25
|
+
@array.each(&block)
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
def count(&block)
|
29
|
+
if block
|
30
|
+
count = 0
|
31
|
+
size.times do |index|
|
32
|
+
if block.call(self[index]).true?
|
33
|
+
count += 1
|
34
|
+
end
|
33
35
|
end
|
34
|
-
end
|
35
|
-
|
36
|
-
return count
|
37
|
-
else
|
38
|
-
return size
|
39
|
-
end
|
40
|
-
end
|
41
36
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
val = self[index]
|
46
|
-
if yield(val).true?
|
47
|
-
result << val
|
37
|
+
return count
|
38
|
+
else
|
39
|
+
return size
|
48
40
|
end
|
49
41
|
end
|
50
42
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
def any?
|
55
|
-
if block_given?
|
43
|
+
def select
|
44
|
+
result = []
|
56
45
|
size.times do |index|
|
57
46
|
val = self[index]
|
58
|
-
|
59
47
|
if yield(val).true?
|
60
|
-
|
48
|
+
result << val
|
61
49
|
end
|
62
50
|
end
|
63
51
|
|
64
|
-
return
|
65
|
-
else
|
66
|
-
return @array.any?
|
52
|
+
return result
|
67
53
|
end
|
68
|
-
end
|
69
54
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
55
|
+
def any?
|
56
|
+
if block_given?
|
57
|
+
size.times do |index|
|
58
|
+
val = self[index]
|
74
59
|
|
75
|
-
|
76
|
-
|
60
|
+
if yield(val).true?
|
61
|
+
return true
|
62
|
+
end
|
77
63
|
end
|
78
|
-
end
|
79
64
|
|
80
|
-
|
81
|
-
|
82
|
-
|
65
|
+
return false
|
66
|
+
else
|
67
|
+
return @array.any?
|
68
|
+
end
|
83
69
|
end
|
84
|
-
end
|
85
|
-
|
86
|
-
# TODO: Handle a range
|
87
|
-
def [](index)
|
88
|
-
# Handle a negative index
|
89
|
-
index = size + index if index < 0
|
90
|
-
|
91
|
-
# Get or create the dependency
|
92
|
-
dep = (@array_deps[index] ||= Dependency.new)
|
93
70
|
|
94
|
-
|
95
|
-
|
71
|
+
def all?
|
72
|
+
if block_given?
|
73
|
+
size.times do |index|
|
74
|
+
val = self[index]
|
96
75
|
|
97
|
-
|
98
|
-
|
99
|
-
|
76
|
+
if !yield(val).true?
|
77
|
+
return false
|
78
|
+
end
|
79
|
+
end
|
100
80
|
|
101
|
-
|
81
|
+
return true
|
82
|
+
else
|
83
|
+
return @array.all?
|
84
|
+
end
|
85
|
+
end
|
102
86
|
|
103
|
-
#
|
104
|
-
|
87
|
+
# TODO: Handle a range
|
88
|
+
def [](index)
|
89
|
+
# Handle a negative index
|
90
|
+
index = size + index if index < 0
|
105
91
|
|
106
|
-
|
92
|
+
# Get or create the dependency
|
93
|
+
dep = (@array_deps[index] ||= Dependency.new)
|
107
94
|
|
108
|
-
|
109
|
-
|
95
|
+
# Track the dependency
|
96
|
+
dep.depend
|
110
97
|
|
111
|
-
|
112
|
-
|
98
|
+
# Return the index
|
99
|
+
return @array[index]
|
100
|
+
end
|
113
101
|
|
114
|
-
|
115
|
-
end
|
116
|
-
alias :length :size
|
102
|
+
def []=(index, value)
|
117
103
|
|
118
|
-
|
119
|
-
|
120
|
-
index = size + index if index < 0
|
104
|
+
# Assign the new value
|
105
|
+
@array[index] = value
|
121
106
|
|
122
|
-
|
107
|
+
trigger_for_index!(index)
|
123
108
|
|
124
|
-
|
125
|
-
|
126
|
-
index_deps.remove if index_deps
|
109
|
+
trigger_size_change!
|
110
|
+
end
|
127
111
|
|
128
|
-
|
112
|
+
def size
|
113
|
+
@size_dep.depend
|
129
114
|
|
130
|
-
|
131
|
-
# delete would change
|
132
|
-
index.upto(self.size+1) do |position|
|
133
|
-
trigger_for_index!(position)
|
115
|
+
return @array.size
|
134
116
|
end
|
135
117
|
|
136
|
-
|
118
|
+
alias :length :size
|
137
119
|
|
138
|
-
|
120
|
+
def delete_at(index)
|
121
|
+
# Handle a negative index
|
122
|
+
index = size + index if index < 0
|
139
123
|
|
140
|
-
|
141
|
-
end
|
124
|
+
model = @array.delete_at(index)
|
142
125
|
|
126
|
+
# Remove the dependency for that cell, and #remove it
|
127
|
+
index_deps = @array_deps.delete_at(index)
|
128
|
+
index_deps.remove if index_deps
|
143
129
|
|
144
|
-
|
145
|
-
index = @array.index(val)
|
146
|
-
if index
|
147
|
-
self.delete_at(index)
|
148
|
-
else
|
149
|
-
# Sometimes the model isn't loaded at the right state yet, so we
|
150
|
-
# just remove it from the persistor
|
151
|
-
@persistor.removed(val) if @persistor
|
152
|
-
end
|
153
|
-
end
|
130
|
+
trigger_removed!(index)
|
154
131
|
|
155
|
-
|
156
|
-
|
132
|
+
# Trigger a changed event for each element in the zone where the
|
133
|
+
# delete would change
|
134
|
+
index.upto(self.size+1) do |position|
|
135
|
+
trigger_for_index!(position)
|
136
|
+
end
|
137
|
+
|
138
|
+
trigger_size_change!
|
157
139
|
|
158
|
-
|
159
|
-
@array_deps = []
|
140
|
+
@persistor.removed(model) if @persistor
|
160
141
|
|
161
|
-
|
162
|
-
old_size.times do |index|
|
163
|
-
trigger_removed!(old_size - index - 1)
|
142
|
+
return model
|
164
143
|
end
|
165
144
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
145
|
+
|
146
|
+
def delete(val)
|
147
|
+
index = @array.index(val)
|
148
|
+
if index
|
149
|
+
self.delete_at(index)
|
150
|
+
else
|
151
|
+
# Sometimes the model isn't loaded at the right state yet, so we
|
152
|
+
# just remove it from the persistor
|
153
|
+
@persistor.removed(val) if @persistor
|
170
154
|
end
|
171
155
|
end
|
172
156
|
|
173
|
-
|
174
|
-
|
175
|
-
end
|
157
|
+
def clear
|
158
|
+
old_size = @array.size
|
176
159
|
|
177
|
-
|
178
|
-
|
179
|
-
result = (@array << value)
|
160
|
+
deps = @array_deps
|
161
|
+
@array_deps = []
|
180
162
|
|
181
|
-
|
182
|
-
|
183
|
-
|
163
|
+
# Trigger remove for each cell
|
164
|
+
old_size.times do |index|
|
165
|
+
trigger_removed!(old_size - index - 1)
|
166
|
+
end
|
184
167
|
|
185
|
-
|
186
|
-
|
168
|
+
# Trigger on each cell since we are clearing out the array
|
169
|
+
if deps
|
170
|
+
deps.each do |dep|
|
171
|
+
dep.changed! if dep
|
172
|
+
end
|
173
|
+
end
|
187
174
|
|
175
|
+
# clear the array
|
176
|
+
@array = []
|
177
|
+
end
|
188
178
|
|
189
|
-
|
190
|
-
|
191
|
-
|
179
|
+
# alias :__old_append :<<
|
180
|
+
def <<(value)
|
181
|
+
result = (@array << value)
|
192
182
|
|
193
|
-
|
194
|
-
|
183
|
+
trigger_for_index!(self.size-1)
|
184
|
+
trigger_added!(self.size-1)
|
185
|
+
trigger_size_change!
|
195
186
|
|
196
|
-
|
197
|
-
trigger_for_index!('changed', index)
|
198
|
-
trigger_added!(old_size + index)
|
187
|
+
return result
|
199
188
|
end
|
200
189
|
|
201
|
-
trigger_size_change!
|
202
190
|
|
203
|
-
|
204
|
-
|
191
|
+
def +(array)
|
192
|
+
raise "not implemented yet"
|
193
|
+
old_size = self.size
|
205
194
|
|
206
|
-
|
207
|
-
|
195
|
+
# TODO: += is funky here, might need to make a .plus! method
|
196
|
+
result = ReactiveArray.new(@array.dup + array)
|
208
197
|
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
198
|
+
old_size.upto(result.size-1) do |index|
|
199
|
+
trigger_for_index!('changed', index)
|
200
|
+
trigger_added!(old_size + index)
|
201
|
+
end
|
202
|
+
|
203
|
+
trigger_size_change!
|
213
204
|
|
214
|
-
|
215
|
-
trigger_added!(index+count)
|
205
|
+
return result
|
216
206
|
end
|
217
207
|
|
218
|
-
|
208
|
+
def insert(index, *objects)
|
209
|
+
result = @array.insert(index, *objects)
|
219
210
|
|
220
|
-
|
221
|
-
|
211
|
+
# All objects from index to the end have "changed"
|
212
|
+
index.upto(result.size) do |index|
|
213
|
+
trigger_for_index!(index)
|
214
|
+
end
|
222
215
|
|
216
|
+
objects.size.times do |count|
|
217
|
+
trigger_added!(index+count)
|
218
|
+
end
|
223
219
|
|
224
|
-
|
225
|
-
|
226
|
-
|
220
|
+
trigger_size_change!
|
221
|
+
|
222
|
+
return result
|
223
|
+
end
|
227
224
|
|
228
225
|
|
229
|
-
|
226
|
+
def inspect
|
227
|
+
"#<#{self.class.to_s}:#{object_id} #{@array.inspect}>"
|
228
|
+
end
|
229
|
+
|
230
|
+
|
231
|
+
private
|
230
232
|
# Check to see if the size has changed, trigger a change on size if it has
|
231
233
|
def trigger_size_change!
|
232
234
|
new_size = @array.size
|
@@ -251,7 +253,5 @@ class ReactiveArray# < Array
|
|
251
253
|
def trigger_removed!(index)
|
252
254
|
trigger!('removed', index)
|
253
255
|
end
|
254
|
-
|
255
|
-
|
256
|
-
|
256
|
+
end
|
257
257
|
end
|
@@ -1,49 +1,51 @@
|
|
1
1
|
require 'volt/reactive/hash_dependency'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
module Volt
|
4
|
+
class ReactiveHash
|
5
|
+
def initialize(values={})
|
6
|
+
@hash = values
|
7
|
+
@deps = HashDependency.new
|
8
|
+
@all_deps = Dependency.new
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
def ==(val)
|
12
|
+
@all_deps.depend
|
13
|
+
@hash == val
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
# TODO: We should finish off this class for reactivity
|
17
|
+
def method_missing(method_name, *args, &block)
|
18
|
+
@all_deps.depend
|
18
19
|
|
19
|
-
|
20
|
-
|
20
|
+
return @hash.send(method_name, *args, &block)
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
-
|
23
|
+
def [](key)
|
24
|
+
@deps.depend(key)
|
24
25
|
|
25
|
-
|
26
|
-
|
26
|
+
return @hash[key]
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
def []=(key, value)
|
30
|
+
@deps.changed!(key)
|
31
|
+
@all_deps.changed!
|
31
32
|
|
32
|
-
|
33
|
-
|
33
|
+
@hash[key] = value
|
34
|
+
end
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
def delete(key)
|
37
|
+
@deps.delete(key)
|
38
|
+
@hash.delete(key)
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
41
|
+
def clear
|
42
|
+
@hash.each_pair do |key, _|
|
43
|
+
delete(key)
|
44
|
+
end
|
43
45
|
end
|
44
|
-
end
|
45
46
|
|
46
|
-
|
47
|
-
|
47
|
+
def inspect
|
48
|
+
"#<ReactiveHash #{@hash.inspect}>"
|
49
|
+
end
|
48
50
|
end
|
49
|
-
end
|
51
|
+
end
|