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
@@ -3,127 +3,128 @@ require 'volt/models/model_wrapper'
|
|
3
3
|
require 'volt/models/model_helpers'
|
4
4
|
require 'volt/models/model_state'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
method_names
|
17
|
-
|
18
|
-
|
19
|
-
|
6
|
+
module Volt
|
7
|
+
class ArrayModel < ReactiveArray
|
8
|
+
include ModelWrapper
|
9
|
+
include ModelHelpers
|
10
|
+
include ModelState
|
11
|
+
|
12
|
+
attr_reader :parent, :path, :persistor, :options, :array
|
13
|
+
|
14
|
+
# For many methods, we want to call load data as soon as the model is interacted
|
15
|
+
# with, so we proxy the method, then call super.
|
16
|
+
def self.proxy_with_load_data(*method_names)
|
17
|
+
method_names.each do |method_name|
|
18
|
+
define_method(method_name) do |*args|
|
19
|
+
load_data
|
20
|
+
super(*args)
|
21
|
+
end
|
20
22
|
end
|
21
23
|
end
|
22
|
-
end
|
23
|
-
|
24
|
-
proxy_with_load_data :[], :size, :first, :last
|
25
24
|
|
26
|
-
|
27
|
-
@options = options
|
28
|
-
@parent = options[:parent]
|
29
|
-
@path = options[:path] || []
|
30
|
-
@persistor = setup_persistor(options[:persistor])
|
25
|
+
proxy_with_load_data :[], :size, :first, :last
|
31
26
|
|
32
|
-
array =
|
27
|
+
def initialize(array=[], options={})
|
28
|
+
@options = options
|
29
|
+
@parent = options[:parent]
|
30
|
+
@path = options[:path] || []
|
31
|
+
@persistor = setup_persistor(options[:persistor])
|
33
32
|
|
34
|
-
|
33
|
+
array = wrap_values(array)
|
35
34
|
|
36
|
-
|
37
|
-
end
|
35
|
+
super(array)
|
38
36
|
|
39
|
-
|
40
|
-
if @persistor
|
41
|
-
return @persistor.find(*args, &block)
|
42
|
-
else
|
43
|
-
raise "this model's persistance layer does not support find, try using store"
|
37
|
+
@persistor.loaded if @persistor
|
44
38
|
end
|
45
|
-
end
|
46
39
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
52
46
|
end
|
53
|
-
end
|
54
47
|
|
55
|
-
|
56
|
-
|
57
|
-
|
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
|
58
55
|
|
59
|
-
|
60
|
-
|
61
|
-
if model.is_a?(Model)
|
62
|
-
# Set the new path
|
63
|
-
model.options = @options.merge(path: @options[:path] + [:[]])
|
64
|
-
else
|
65
|
-
model = wrap_values([model]).first
|
56
|
+
def attributes
|
57
|
+
self
|
66
58
|
end
|
67
59
|
|
68
|
-
|
60
|
+
# Make sure it gets wrapped
|
61
|
+
def <<(model)
|
62
|
+
if model.is_a?(Model)
|
63
|
+
# Set the new path
|
64
|
+
model.options = @options.merge(path: @options[:path] + [:[]])
|
65
|
+
else
|
66
|
+
model = wrap_values([model]).first
|
67
|
+
end
|
69
68
|
|
70
|
-
|
69
|
+
super(model)
|
71
70
|
|
72
|
-
|
73
|
-
end
|
74
|
-
alias_method :append, :<<
|
71
|
+
@persistor.added(model, @array.size-1) if @persistor
|
75
72
|
|
76
|
-
|
77
|
-
|
78
|
-
args = wrap_values(args)
|
79
|
-
super(*args)
|
80
|
-
end
|
73
|
+
model
|
74
|
+
end
|
81
75
|
|
82
|
-
|
83
|
-
def +(*args)
|
84
|
-
args = wrap_values(args)
|
85
|
-
super(*args)
|
86
|
-
end
|
76
|
+
alias_method :append, :<<
|
87
77
|
|
88
|
-
|
89
|
-
|
90
|
-
|
78
|
+
# Make sure it gets wrapped
|
79
|
+
def inject(*args)
|
80
|
+
args = wrap_values(args)
|
81
|
+
super(*args)
|
82
|
+
end
|
91
83
|
|
92
|
-
|
93
|
-
|
94
|
-
|
84
|
+
# Make sure it gets wrapped
|
85
|
+
def +(*args)
|
86
|
+
args = wrap_values(args)
|
87
|
+
super(*args)
|
88
|
+
end
|
95
89
|
|
96
|
-
|
97
|
-
|
98
|
-
array = []
|
99
|
-
attributes.each do |value|
|
100
|
-
array << deep_unwrap(value)
|
90
|
+
def new_model(*args)
|
91
|
+
class_at_path(options[:path]).new(*args)
|
101
92
|
end
|
102
93
|
|
103
|
-
|
104
|
-
|
94
|
+
def new_array_model(*args)
|
95
|
+
ArrayModel.new(*args)
|
96
|
+
end
|
105
97
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
98
|
+
# Convert the model to an array all of the way down
|
99
|
+
def to_a
|
100
|
+
array = []
|
101
|
+
attributes.each do |value|
|
102
|
+
array << deep_unwrap(value)
|
103
|
+
end
|
104
|
+
array
|
110
105
|
end
|
111
106
|
|
112
|
-
|
113
|
-
|
114
|
-
|
107
|
+
def inspect
|
108
|
+
if @persistor && @persistor.is_a?(Persistors::ArrayStore) && state == :not_loaded
|
109
|
+
# Show a special message letting users know it is not loaded yet.
|
110
|
+
"#<#{self.class.to_s}:not loaded, access with [] or size to load>"
|
111
|
+
else
|
112
|
+
# Otherwise inspect normally
|
113
|
+
super
|
114
|
+
end
|
115
|
+
end
|
115
116
|
|
116
|
-
|
117
|
-
|
118
|
-
|
117
|
+
def buffer
|
118
|
+
model_path = options[:path] + [:[]]
|
119
|
+
model_klass = class_at_path(model_path)
|
119
120
|
|
120
|
-
|
121
|
-
|
121
|
+
new_options = options.merge(path: model_path, save_to: self).reject { |k, _| k.to_sym == :persistor }
|
122
|
+
model = model_klass.new({}, new_options)
|
122
123
|
|
123
|
-
|
124
|
-
|
124
|
+
model
|
125
|
+
end
|
125
126
|
|
126
|
-
|
127
|
+
private
|
127
128
|
# Takes the persistor if there is one and
|
128
129
|
def setup_persistor(persistor)
|
129
130
|
if persistor
|
@@ -137,5 +138,5 @@ class ArrayModel < ReactiveArray
|
|
137
138
|
@persistor.load_data
|
138
139
|
end
|
139
140
|
end
|
140
|
-
|
141
|
+
end
|
141
142
|
end
|