volt 0.8.15 → 0.8.16
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/.rubocop.yml +11 -0
- data/CHANGELOG.md +11 -0
- data/Gemfile +1 -1
- data/Guardfile +2 -3
- data/Rakefile +1 -4
- data/VERSION +1 -1
- data/app/volt/controllers/notices_controller.rb +1 -1
- data/app/volt/tasks/live_query/data_store.rb +7 -7
- data/app/volt/tasks/live_query/live_query.rb +7 -9
- data/app/volt/tasks/live_query/live_query_pool.rb +13 -12
- data/app/volt/tasks/live_query/query_tracker.rb +4 -5
- data/app/volt/tasks/query_tasks.rb +9 -11
- data/app/volt/tasks/store_tasks.rb +4 -4
- data/app/volt/tasks/user_tasks.rb +1 -1
- data/bin/volt +2 -2
- data/lib/volt.rb +3 -7
- data/lib/volt/assets/test.rb +1 -2
- data/lib/volt/benchmark/benchmark.rb +3 -3
- data/lib/volt/boot.rb +1 -1
- data/lib/volt/cli.rb +18 -18
- data/lib/volt/cli/asset_compile.rb +8 -10
- data/lib/volt/cli/generate.rb +9 -11
- data/lib/volt/cli/new_gem.rb +51 -51
- data/lib/volt/config.rb +2 -3
- data/lib/volt/console.rb +1 -1
- data/lib/volt/controllers/model_controller.rb +6 -6
- data/lib/volt/data_stores/data_store.rb +1 -1
- data/lib/volt/data_stores/mongo_driver.rb +1 -1
- data/lib/volt/extra_core/array.rb +2 -2
- data/lib/volt/extra_core/blank.rb +1 -2
- data/lib/volt/extra_core/extra_core.rb +1 -1
- data/lib/volt/extra_core/inflector/methods.rb +0 -1
- data/lib/volt/extra_core/logger.rb +13 -7
- data/lib/volt/extra_core/numeric.rb +1 -1
- data/lib/volt/extra_core/string.rb +7 -7
- data/lib/volt/extra_core/stringify_keys.rb +5 -5
- data/lib/volt/models.rb +2 -2
- data/lib/volt/models/array_model.rb +18 -19
- data/lib/volt/models/cursor.rb +0 -1
- data/lib/volt/models/model.rb +17 -35
- data/lib/volt/models/model_hash_behaviour.rb +0 -2
- data/lib/volt/models/model_state.rb +1 -1
- data/lib/volt/models/model_wrapper.rb +1 -1
- data/lib/volt/models/persistors/array_store.rb +26 -13
- data/lib/volt/models/persistors/base.rb +1 -1
- data/lib/volt/models/persistors/flash.rb +2 -2
- data/lib/volt/models/persistors/local_store.rb +2 -3
- data/lib/volt/models/persistors/model_store.rb +7 -6
- data/lib/volt/models/persistors/params.rb +2 -2
- data/lib/volt/models/persistors/query/query_listener.rb +2 -0
- data/lib/volt/models/persistors/query/query_listener_pool.rb +1 -1
- data/lib/volt/models/persistors/store.rb +1 -2
- data/lib/volt/models/persistors/store_state.rb +2 -3
- data/lib/volt/models/url.rb +17 -16
- data/lib/volt/models/validations.rb +11 -14
- data/lib/volt/models/validators/length_validator.rb +3 -3
- data/lib/volt/models/validators/presence_validator.rb +2 -2
- data/lib/volt/page/bindings/attribute_binding.rb +2 -3
- data/lib/volt/page/bindings/base_binding.rb +1 -1
- data/lib/volt/page/bindings/each_binding.rb +8 -9
- data/lib/volt/page/bindings/event_binding.rb +2 -3
- data/lib/volt/page/bindings/template_binding.rb +8 -7
- data/lib/volt/page/bindings/template_binding/grouped_controllers.rb +2 -1
- data/lib/volt/page/channel.rb +10 -10
- data/lib/volt/page/channel_stub.rb +1 -1
- data/lib/volt/page/document.rb +0 -1
- data/lib/volt/page/document_events.rb +4 -4
- data/lib/volt/page/page.rb +26 -19
- data/lib/volt/page/string_template_renderer.rb +2 -2
- data/lib/volt/page/sub_context.rb +10 -4
- data/lib/volt/page/targets/attribute_section.rb +1 -1
- data/lib/volt/page/targets/attribute_target.rb +1 -2
- data/lib/volt/page/targets/base_section.rb +4 -4
- data/lib/volt/page/targets/binding_document/base_node.rb +0 -1
- data/lib/volt/page/targets/binding_document/component_node.rb +4 -5
- data/lib/volt/page/targets/dom_section.rb +21 -22
- data/lib/volt/page/targets/dom_target.rb +1 -1
- data/lib/volt/page/targets/dom_template.rb +11 -12
- data/lib/volt/page/targets/helpers/comment_searchers.rb +7 -8
- data/lib/volt/page/tasks.rb +0 -1
- data/lib/volt/page/template_renderer.rb +1 -1
- data/lib/volt/page/url_tracker.rb +3 -3
- data/lib/volt/reactive/computation.rb +5 -11
- data/lib/volt/reactive/dependency.rb +1 -3
- data/lib/volt/reactive/eventable.rb +17 -4
- data/lib/volt/reactive/hash_dependency.rb +1 -0
- data/lib/volt/reactive/reactive_accessors.rb +0 -1
- data/lib/volt/reactive/reactive_array.rb +20 -25
- data/lib/volt/reactive/reactive_hash.rb +3 -3
- data/lib/volt/router/routes.rb +11 -13
- data/lib/volt/server.rb +17 -17
- data/lib/volt/server/component_handler.rb +2 -2
- data/lib/volt/server/component_templates.rb +8 -8
- data/lib/volt/server/html_parser/attribute_scope.rb +9 -10
- data/lib/volt/server/html_parser/if_view_scope.rb +2 -2
- data/lib/volt/server/html_parser/sandlebars_parser.rb +14 -14
- data/lib/volt/server/html_parser/textarea_scope.rb +1 -2
- data/lib/volt/server/html_parser/view_handler.rb +1 -1
- data/lib/volt/server/html_parser/view_parser.rb +1 -1
- data/lib/volt/server/html_parser/view_scope.rb +10 -10
- data/lib/volt/server/rack/asset_files.rb +15 -16
- data/lib/volt/server/rack/component_code.rb +2 -2
- data/lib/volt/server/rack/component_html_renderer.rb +0 -1
- data/lib/volt/server/rack/component_paths.rb +13 -10
- data/lib/volt/server/rack/index_files.rb +4 -4
- data/lib/volt/server/rack/opal_files.rb +4 -5
- data/lib/volt/server/rack/source_map_server.rb +3 -3
- data/lib/volt/server/socket_connection_handler.rb +3 -4
- data/lib/volt/server/socket_connection_handler_stub.rb +1 -1
- data/lib/volt/spec/setup.rb +3 -3
- data/lib/volt/store/mongo.rb +2 -2
- data/lib/volt/tasks/task_handler.rb +3 -3
- data/lib/volt/utils/generic_counting_pool.rb +2 -2
- data/lib/volt/utils/generic_pool.rb +7 -8
- data/lib/volt/utils/local_storage.rb +4 -4
- data/lib/volt/volt/environment.rb +1 -1
- data/spec/apps/file_loading/app/shared/config/dependencies.rb +1 -1
- data/spec/apps/kitchen_sink/Gemfile +0 -2
- data/spec/apps/kitchen_sink/app/main/config/routes.rb +5 -5
- data/spec/apps/kitchen_sink/app/main/controllers/main_controller.rb +7 -6
- data/spec/apps/kitchen_sink/app/main/controllers/todos_controller.rb +3 -4
- data/spec/controllers/reactive_accessors_spec.rb +4 -4
- data/spec/extra_core/inflector_spec.rb +1 -1
- data/spec/extra_core/string_transformation_test_cases.rb +23 -24
- data/spec/extra_core/string_transformations_spec.rb +11 -12
- data/spec/integration/bindings_spec.rb +15 -15
- data/spec/integration/list_spec.rb +12 -13
- data/spec/integration/templates_spec.rb +3 -3
- data/spec/models/model_spec.rb +74 -80
- data/spec/models/persistors/params_spec.rb +2 -2
- data/spec/models/persistors/store_spec.rb +4 -4
- data/spec/models/validations_spec.rb +14 -23
- data/spec/page/bindings/content_binding_spec.rb +7 -8
- data/spec/page/bindings/template_binding_spec.rb +22 -24
- data/spec/page/sub_context_spec.rb +2 -2
- data/spec/reactive/computation_spec.rb +3 -3
- data/spec/reactive/reactive_array_spec.rb +12 -12
- data/spec/router/routes_spec.rb +45 -48
- data/spec/server/html_parser/sandlebars_parser_spec.rb +42 -42
- data/spec/server/html_parser/view_parser_spec.rb +132 -153
- data/spec/server/rack/asset_files_spec.rb +9 -8
- data/spec/server/rack/component_paths_spec.rb +5 -5
- data/spec/server/rack/rack_requests_spec.rb +3 -3
- data/spec/spec_helper.rb +1 -1
- data/spec/tasks/live_query_spec.rb +4 -5
- data/spec/tasks/query_tasks.rb +2 -4
- data/spec/tasks/query_tracker_spec.rb +29 -29
- data/spec/templates/targets/binding_document/component_node_spec.rb +1 -1
- data/spec/utils/generic_counting_pool_spec.rb +4 -4
- data/spec/utils/generic_pool_spec.rb +12 -12
- data/templates/component/config/routes.rb +2 -2
- data/templates/component/controllers/main_controller.rb +7 -6
- data/templates/newgem/app/newgem/config/dependencies.rb +1 -1
- data/templates/newgem/app/newgem/config/routes.rb +1 -1
- data/templates/project/app/main/config/routes.rb +2 -2
- data/templates/project/app/main/controllers/main_controller.rb +7 -6
- data/templates/project/spec/sample_spec.rb +2 -2
- data/volt.gemspec +32 -33
- metadata +3 -4
- data/lib/volt/extra_core/log.rb +0 -56
- data/lib/volt/extra_core/try.rb +0 -31
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
class Object
|
|
2
2
|
def stringify_keys
|
|
3
|
-
|
|
3
|
+
each_with_object({}) do |(key, value), hash|
|
|
4
4
|
hash[key.to_s] = value
|
|
5
|
-
|
|
5
|
+
end
|
|
6
6
|
end
|
|
7
7
|
|
|
8
8
|
def symbolize_keys
|
|
9
|
-
|
|
9
|
+
each_with_object({}) do |(key, value), hash|
|
|
10
10
|
hash[key.to_sym] = value
|
|
11
|
-
|
|
11
|
+
end
|
|
12
12
|
end
|
|
13
|
-
end
|
|
13
|
+
end
|
data/lib/volt/models.rb
CHANGED
|
@@ -11,6 +11,6 @@ if RUBY_PLATFORM == 'opal'
|
|
|
11
11
|
require 'promise.rb'
|
|
12
12
|
else
|
|
13
13
|
# Opal doesn't expose its promise library directly
|
|
14
|
-
spec = Gem::Specification.find_by_name(
|
|
15
|
-
require(spec.gem_dir +
|
|
14
|
+
spec = Gem::Specification.find_by_name('opal')
|
|
15
|
+
require(spec.gem_dir + '/stdlib/promise')
|
|
16
16
|
end
|
|
@@ -22,9 +22,23 @@ module Volt
|
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
+
# Some methods get passed down to the persistor.
|
|
26
|
+
def self.proxy_to_persistor(*method_names)
|
|
27
|
+
method_names.each do |method_name|
|
|
28
|
+
define_method(method_name) do |*args, &block|
|
|
29
|
+
if @persistor.respond_to?(method_name)
|
|
30
|
+
@persistor.send(method_name, *args, &block)
|
|
31
|
+
else
|
|
32
|
+
raise "this model's persistance layer does not support #{method_name}, try using store"
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
25
38
|
proxy_with_load_data :[], :size, :first, :last
|
|
39
|
+
proxy_to_persistor :find, :skip, :limit, :then
|
|
26
40
|
|
|
27
|
-
def initialize(array=[], options={})
|
|
41
|
+
def initialize(array = [], options = {})
|
|
28
42
|
@options = options
|
|
29
43
|
@parent = options[:parent]
|
|
30
44
|
@path = options[:path] || []
|
|
@@ -37,22 +51,6 @@ module Volt
|
|
|
37
51
|
@persistor.loaded if @persistor
|
|
38
52
|
end
|
|
39
53
|
|
|
40
|
-
def find(*args, &block)
|
|
41
|
-
if @persistor
|
|
42
|
-
return @persistor.find(*args, &block)
|
|
43
|
-
else
|
|
44
|
-
raise "this model's persistance layer does not support find, try using store"
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def then(*args, &block)
|
|
49
|
-
if @persistor
|
|
50
|
-
@persistor.then(*args, &block)
|
|
51
|
-
else
|
|
52
|
-
raise "this model's persistance layer does not support then, try using store"
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
54
|
def attributes
|
|
57
55
|
self
|
|
58
56
|
end
|
|
@@ -68,7 +66,7 @@ module Volt
|
|
|
68
66
|
|
|
69
67
|
super(model)
|
|
70
68
|
|
|
71
|
-
@persistor.added(model, @array.size-1) if @persistor
|
|
69
|
+
@persistor.added(model, @array.size - 1) if @persistor
|
|
72
70
|
|
|
73
71
|
model
|
|
74
72
|
end
|
|
@@ -107,7 +105,7 @@ module Volt
|
|
|
107
105
|
def inspect
|
|
108
106
|
if @persistor && @persistor.is_a?(Persistors::ArrayStore) && state == :not_loaded
|
|
109
107
|
# Show a special message letting users know it is not loaded yet.
|
|
110
|
-
"#<#{self.class
|
|
108
|
+
"#<#{self.class}:not loaded, access with [] or size to load>"
|
|
111
109
|
else
|
|
112
110
|
# Otherwise inspect normally
|
|
113
111
|
super
|
|
@@ -125,6 +123,7 @@ module Volt
|
|
|
125
123
|
end
|
|
126
124
|
|
|
127
125
|
private
|
|
126
|
+
|
|
128
127
|
# Takes the persistor if there is one and
|
|
129
128
|
def setup_persistor(persistor)
|
|
130
129
|
if persistor
|
data/lib/volt/models/cursor.rb
CHANGED
data/lib/volt/models/model.rb
CHANGED
|
@@ -7,7 +7,6 @@ require 'volt/models/model_state'
|
|
|
7
7
|
require 'volt/reactive/reactive_hash'
|
|
8
8
|
|
|
9
9
|
module Volt
|
|
10
|
-
|
|
11
10
|
class NilMethodCall < NoMethodError
|
|
12
11
|
end
|
|
13
12
|
|
|
@@ -110,7 +109,6 @@ module Volt
|
|
|
110
109
|
!attributes
|
|
111
110
|
end
|
|
112
111
|
|
|
113
|
-
|
|
114
112
|
def method_missing(method_name, *args, &block)
|
|
115
113
|
if method_name[0] == '_'
|
|
116
114
|
if method_name[-1] == '='
|
|
@@ -149,7 +147,7 @@ module Volt
|
|
|
149
147
|
# Reading an attribute, we may get back a nil model.
|
|
150
148
|
method_name = method_name.to_sym
|
|
151
149
|
|
|
152
|
-
if method_name[0] != '_' && @attributes
|
|
150
|
+
if method_name[0] != '_' && @attributes.nil?
|
|
153
151
|
# The method we are calling is on a nil model, return a wrapped
|
|
154
152
|
# exception.
|
|
155
153
|
return_undefined_method(method_name)
|
|
@@ -190,15 +188,13 @@ module Volt
|
|
|
190
188
|
def return_undefined_method(method_name)
|
|
191
189
|
# Methods called on nil capture an error so the user can know where
|
|
192
190
|
# their nil calls are. This error can be re-raised at a later point.
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
result.backtrace.reject! { |line| line['lib/models/model.rb'] || line['lib/models/live_value.rb'] }
|
|
201
|
-
end
|
|
191
|
+
fail NilMethodCall.new("undefined method `#{method_name}' for #{self}")
|
|
192
|
+
rescue => e
|
|
193
|
+
result = e
|
|
194
|
+
|
|
195
|
+
# Cleanup backtrace
|
|
196
|
+
# TODO: this could be better
|
|
197
|
+
result.backtrace.reject! { |line| line['lib/models/model.rb'] || line['lib/models/live_value.rb'] }
|
|
202
198
|
end
|
|
203
199
|
|
|
204
200
|
def new_model(attributes, options)
|
|
@@ -213,19 +209,6 @@ module Volt
|
|
|
213
209
|
ArrayModel.new(attributes, options)
|
|
214
210
|
end
|
|
215
211
|
|
|
216
|
-
def trigger_by_attribute!(event_name, attribute, *passed_args)
|
|
217
|
-
trigger_by_scope!(event_name, *passed_args) do |scope|
|
|
218
|
-
method_name, *args, block = scope
|
|
219
|
-
|
|
220
|
-
# TODO: Opal bug
|
|
221
|
-
args ||= []
|
|
222
|
-
|
|
223
|
-
# Any methods without _ are not directly related to one attribute, so
|
|
224
|
-
# they should all trigger
|
|
225
|
-
!method_name || method_name[0] != '_' || (method_name == attribute.to_sym && args.size == 0)
|
|
226
|
-
end
|
|
227
|
-
end
|
|
228
|
-
|
|
229
212
|
# If this model is nil, it makes it into a hash model, then
|
|
230
213
|
# sets it up to track from the parent.
|
|
231
214
|
def expand!
|
|
@@ -244,7 +227,7 @@ module Volt
|
|
|
244
227
|
if @parent
|
|
245
228
|
@parent.expand!
|
|
246
229
|
else
|
|
247
|
-
|
|
230
|
+
fail 'Model data should be stored in sub collections.'
|
|
248
231
|
end
|
|
249
232
|
|
|
250
233
|
# Grab the last section of the path, so we can do the assign on the parent
|
|
@@ -265,7 +248,7 @@ module Volt
|
|
|
265
248
|
|
|
266
249
|
def inspect
|
|
267
250
|
Computation.run_without_tracking do
|
|
268
|
-
"<#{self.class
|
|
251
|
+
"<#{self.class}:#{object_id} #{attributes.inspect}>"
|
|
269
252
|
end
|
|
270
253
|
end
|
|
271
254
|
|
|
@@ -278,19 +261,19 @@ module Volt
|
|
|
278
261
|
if save_to
|
|
279
262
|
if save_to.is_a?(ArrayModel)
|
|
280
263
|
# Add to the collection
|
|
281
|
-
new_model = save_to <<
|
|
264
|
+
new_model = save_to << attributes
|
|
282
265
|
|
|
283
266
|
# Set the buffer's id to track the main model's id
|
|
284
|
-
|
|
267
|
+
attributes[:_id] = new_model._id
|
|
285
268
|
options[:save_to] = new_model
|
|
286
269
|
|
|
287
270
|
# TODO: return a promise that resolves if the append works
|
|
288
271
|
else
|
|
289
272
|
# We have a saved model
|
|
290
|
-
return save_to.assign_attributes(
|
|
273
|
+
return save_to.assign_attributes(attributes)
|
|
291
274
|
end
|
|
292
275
|
else
|
|
293
|
-
|
|
276
|
+
fail 'Model is not a buffer, can not be saved, modifications should be persisted as they are made.'
|
|
294
277
|
end
|
|
295
278
|
|
|
296
279
|
Promise.new.resolve({})
|
|
@@ -304,7 +287,6 @@ module Volt
|
|
|
304
287
|
end
|
|
305
288
|
end
|
|
306
289
|
|
|
307
|
-
|
|
308
290
|
# Returns a buffered version of the model
|
|
309
291
|
def buffer
|
|
310
292
|
model_path = options[:path]
|
|
@@ -322,7 +304,7 @@ module Volt
|
|
|
322
304
|
if state == :loaded
|
|
323
305
|
setup_buffer(model)
|
|
324
306
|
else
|
|
325
|
-
|
|
307
|
+
parent.then do
|
|
326
308
|
setup_buffer(model)
|
|
327
309
|
end
|
|
328
310
|
end
|
|
@@ -330,10 +312,10 @@ module Volt
|
|
|
330
312
|
model
|
|
331
313
|
end
|
|
332
314
|
|
|
333
|
-
|
|
334
315
|
private
|
|
316
|
+
|
|
335
317
|
def setup_buffer(model)
|
|
336
|
-
model.attributes =
|
|
318
|
+
model.attributes = attributes
|
|
337
319
|
model.change_state_to(:loaded)
|
|
338
320
|
end
|
|
339
321
|
|
|
@@ -3,7 +3,6 @@ module Volt
|
|
|
3
3
|
# Moving this into a module cleans up the main Model class for things that
|
|
4
4
|
# make it behave like a model.
|
|
5
5
|
module ModelHashBehaviour
|
|
6
|
-
|
|
7
6
|
def delete(name)
|
|
8
7
|
name = name.to_sym
|
|
9
8
|
|
|
@@ -45,7 +44,6 @@ module Volt
|
|
|
45
44
|
(@attributes || {}).each_with_object(*args, &block)
|
|
46
45
|
end
|
|
47
46
|
|
|
48
|
-
|
|
49
47
|
# Convert the model to a hash all of the way down.
|
|
50
48
|
def to_h
|
|
51
49
|
if empty?
|
|
@@ -15,10 +15,14 @@ module Volt
|
|
|
15
15
|
@@query_pool
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
def initialize(model, tasks=nil)
|
|
18
|
+
def initialize(model, tasks = nil)
|
|
19
19
|
super
|
|
20
20
|
|
|
21
21
|
@query = @model.options[:query]
|
|
22
|
+
@limit = @model.options[:limit]
|
|
23
|
+
@skip = @model.options[:skip]
|
|
24
|
+
|
|
25
|
+
@skip = nil if @skip == 0
|
|
22
26
|
end
|
|
23
27
|
|
|
24
28
|
def event_added(event, first, first_for_event)
|
|
@@ -39,7 +43,7 @@ module Volt
|
|
|
39
43
|
|
|
40
44
|
# Called when an event is removed and we no longer want to keep in
|
|
41
45
|
# sync with the database.
|
|
42
|
-
def stop_listening(stop_watching_query=true)
|
|
46
|
+
def stop_listening(stop_watching_query = true)
|
|
43
47
|
return if @has_events
|
|
44
48
|
return if @fetch_promises && @fetch_promises.size > 0
|
|
45
49
|
|
|
@@ -68,10 +72,10 @@ module Volt
|
|
|
68
72
|
|
|
69
73
|
new_query = @query.call
|
|
70
74
|
|
|
71
|
-
run_query(@model, @query.call)
|
|
75
|
+
run_query(@model, @query.call, @skip, @limit)
|
|
72
76
|
end.watch!
|
|
73
77
|
else
|
|
74
|
-
run_query(@model, @query)
|
|
78
|
+
run_query(@model, @query, @skip, @limit)
|
|
75
79
|
end
|
|
76
80
|
end
|
|
77
81
|
end
|
|
@@ -82,7 +86,7 @@ module Volt
|
|
|
82
86
|
@model.clear
|
|
83
87
|
end
|
|
84
88
|
|
|
85
|
-
def run_query(model, query={})
|
|
89
|
+
def run_query(model, query={}, skip=nil, limit=nil)
|
|
86
90
|
@model.clear
|
|
87
91
|
|
|
88
92
|
collection = model.path.last
|
|
@@ -97,9 +101,11 @@ module Volt
|
|
|
97
101
|
end
|
|
98
102
|
end
|
|
99
103
|
|
|
100
|
-
|
|
104
|
+
# The full query contains the skip and limit
|
|
105
|
+
full_query = [query, skip, limit]
|
|
106
|
+
@query_listener = @@query_pool.lookup(collection, full_query) do
|
|
101
107
|
# Create if it does not exist
|
|
102
|
-
QueryListener.new(@@query_pool, @tasks, collection,
|
|
108
|
+
QueryListener.new(@@query_pool, @tasks, collection, full_query)
|
|
103
109
|
end
|
|
104
110
|
|
|
105
111
|
@query_listener.add_store(self)
|
|
@@ -107,18 +113,26 @@ module Volt
|
|
|
107
113
|
|
|
108
114
|
# Find can take either a query object, or a block that returns a query object. Use
|
|
109
115
|
# the block style if you need reactive updating queries
|
|
110
|
-
def find(query=nil, &block)
|
|
116
|
+
def find(query = nil, &block)
|
|
111
117
|
# Set a default query if there is no block
|
|
112
118
|
if block
|
|
113
119
|
if query
|
|
114
|
-
|
|
120
|
+
fail 'Query should not be passed in to a find if a block is specified'
|
|
115
121
|
end
|
|
116
122
|
query = block
|
|
117
123
|
else
|
|
118
124
|
query ||= {}
|
|
119
125
|
end
|
|
120
126
|
|
|
121
|
-
return Cursor.new([], @model.options.merge(:
|
|
127
|
+
return Cursor.new([], @model.options.merge(query: query))
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def limit(limit)
|
|
131
|
+
return Cursor.new([], @model.options.merge(limit: limit))
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def skip(skip)
|
|
135
|
+
return Cursor.new([], @model.options.merge(skip: skip))
|
|
122
136
|
end
|
|
123
137
|
|
|
124
138
|
# Returns a promise that is resolved/rejected when the query is complete. Any
|
|
@@ -137,7 +151,7 @@ module Volt
|
|
|
137
151
|
load_data
|
|
138
152
|
end
|
|
139
153
|
|
|
140
|
-
|
|
154
|
+
promise
|
|
141
155
|
end
|
|
142
156
|
|
|
143
157
|
# Called from backend
|
|
@@ -147,7 +161,7 @@ module Volt
|
|
|
147
161
|
data_id = data[:_id]
|
|
148
162
|
|
|
149
163
|
# Don't add if the model is already in the ArrayModel
|
|
150
|
-
|
|
164
|
+
unless @model.array.find { |v| v._id == data_id }
|
|
151
165
|
# Find the existing model, or create one
|
|
152
166
|
new_model = @@identity_map.find(data_id) do
|
|
153
167
|
new_options = @model.options.merge(path: @model.path + [:[]], parent: @model)
|
|
@@ -200,7 +214,6 @@ module Volt
|
|
|
200
214
|
StoreTasks.delete(channel_name, model.attributes[:_id])
|
|
201
215
|
end
|
|
202
216
|
end
|
|
203
|
-
|
|
204
217
|
end
|
|
205
218
|
end
|
|
206
219
|
end
|
|
@@ -4,7 +4,6 @@ require 'json'
|
|
|
4
4
|
|
|
5
5
|
module Volt
|
|
6
6
|
module Persistors
|
|
7
|
-
|
|
8
7
|
# Backs a collection in the local store
|
|
9
8
|
class LocalStore < Base
|
|
10
9
|
def initialize(model)
|
|
@@ -24,7 +23,7 @@ module Volt
|
|
|
24
23
|
end
|
|
25
24
|
end
|
|
26
25
|
|
|
27
|
-
|
|
26
|
+
node
|
|
28
27
|
end
|
|
29
28
|
|
|
30
29
|
# Called when a model is added to the collection
|
|
@@ -32,7 +31,7 @@ module Volt
|
|
|
32
31
|
root_model.persistor.save_all
|
|
33
32
|
end
|
|
34
33
|
|
|
35
|
-
def loaded(initial_state=nil)
|
|
34
|
+
def loaded(initial_state = nil)
|
|
36
35
|
# When the main model is first loaded, we pull in the data from the
|
|
37
36
|
# store if it exists
|
|
38
37
|
if @model.path == []
|
|
@@ -6,7 +6,7 @@ module Volt
|
|
|
6
6
|
class ModelStore < Store
|
|
7
7
|
include StoreState
|
|
8
8
|
|
|
9
|
-
ID_CHARS = [('a'..'f'), ('0'..'9')].map
|
|
9
|
+
ID_CHARS = [('a'..'f'), ('0'..'9')].map(&:to_a).flatten
|
|
10
10
|
|
|
11
11
|
attr_reader :model
|
|
12
12
|
attr_accessor :in_identity_map
|
|
@@ -49,11 +49,11 @@ module Volt
|
|
|
49
49
|
id = []
|
|
50
50
|
24.times { id << ID_CHARS.sample }
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
id.join
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
# Called when the model changes
|
|
56
|
-
def changed(attribute_name=nil)
|
|
56
|
+
def changed(attribute_name = nil)
|
|
57
57
|
path = @model.path
|
|
58
58
|
|
|
59
59
|
promise = Promise.new
|
|
@@ -67,8 +67,8 @@ module Volt
|
|
|
67
67
|
end
|
|
68
68
|
|
|
69
69
|
if !collection
|
|
70
|
-
puts
|
|
71
|
-
|
|
70
|
+
puts 'Attempting to save model directly on store.'
|
|
71
|
+
fail 'Attempting to save model directly on store.'
|
|
72
72
|
else
|
|
73
73
|
StoreTasks.save(collection, self_attributes).then do |errors|
|
|
74
74
|
if errors.size == 0
|
|
@@ -103,10 +103,11 @@ module Volt
|
|
|
103
103
|
end
|
|
104
104
|
|
|
105
105
|
def [](val)
|
|
106
|
-
|
|
106
|
+
fail 'Models do not support hash style lookup. Hashes inserted into other models are converted to models, see https://github.com/voltrb/volt#automatic-model-conversion'
|
|
107
107
|
end
|
|
108
108
|
|
|
109
109
|
private
|
|
110
|
+
|
|
110
111
|
# Return the attributes that are only for this store, not any sub-associations.
|
|
111
112
|
def self_attributes
|
|
112
113
|
# Don't store any sub-stores, those will do their own saving.
|