volt 0.6.5 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -32,7 +32,7 @@ class TemplateRenderer < BaseBinding
|
|
32
32
|
|
33
33
|
# Remove all of the sub-bindings
|
34
34
|
# @sub_bindings.each(&:remove)
|
35
|
-
|
35
|
+
|
36
36
|
@sub_bindings.each do |binding|
|
37
37
|
# puts "REMOVE: #{binding.inspect}"
|
38
38
|
binding.remove
|
@@ -40,11 +40,11 @@ class TemplateRenderer < BaseBinding
|
|
40
40
|
end
|
41
41
|
|
42
42
|
@sub_bindings = []
|
43
|
-
|
43
|
+
|
44
44
|
super
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
def remove_anchors
|
48
48
|
section.remove_anchors
|
49
49
|
end
|
50
|
-
end
|
50
|
+
end
|
@@ -4,14 +4,14 @@
|
|
4
4
|
class UrlTracker
|
5
5
|
def initialize(page)
|
6
6
|
@page = page
|
7
|
-
|
7
|
+
|
8
8
|
if Volt.client?
|
9
9
|
page.params.on('child_changed') do
|
10
10
|
@page.url.update!
|
11
11
|
end
|
12
12
|
|
13
13
|
that = self
|
14
|
-
|
14
|
+
|
15
15
|
# Setup popstate on the dom ready event. Prevents an extra
|
16
16
|
# popstate trigger
|
17
17
|
%x{
|
@@ -20,17 +20,17 @@ class UrlTracker
|
|
20
20
|
if (first === false) {
|
21
21
|
that.$url_updated();
|
22
22
|
}
|
23
|
-
|
23
|
+
|
24
24
|
first = false;
|
25
|
-
|
25
|
+
|
26
26
|
return true;
|
27
27
|
});
|
28
28
|
}
|
29
29
|
end
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
def url_updated(first_call=false)
|
33
33
|
@page.url.parse(`document.location.href`)
|
34
34
|
@page.url.update! unless first_call
|
35
35
|
end
|
36
|
-
end
|
36
|
+
end
|
@@ -1,19 +1,19 @@
|
|
1
|
-
# DestructiveMethods tracks the names of all methods that are marked as
|
2
|
-
# destructive. This lets us do an optimization where we don't need to
|
1
|
+
# DestructiveMethods tracks the names of all methods that are marked as
|
2
|
+
# destructive. This lets us do an optimization where we don't need to
|
3
3
|
# check any methods with names that aren't here, we can be sure that they
|
4
4
|
# are not destructive. If the method is tracked here, we need to check
|
5
5
|
# it on its current class.
|
6
6
|
class DestructiveMethods
|
7
7
|
@@method_names = {}
|
8
|
-
|
8
|
+
|
9
9
|
def self.add_method(method_name)
|
10
10
|
@@method_names[method_name] = true
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
# Check to see if a method might be destructive. If this returns
|
14
14
|
# false, then we can guarentee that it won't be destructive and
|
15
15
|
# we can skip a destructive check.
|
16
16
|
def self.might_be_destructive?(method_name)
|
17
17
|
return @@method_names[method_name]
|
18
18
|
end
|
19
|
-
end
|
19
|
+
end
|
@@ -2,29 +2,29 @@ CHAIN_DEBUG = false
|
|
2
2
|
|
3
3
|
class ChainListener
|
4
4
|
attr_reader :object, :callback
|
5
|
-
|
5
|
+
|
6
6
|
def initialize(event_chain, object, callback)
|
7
7
|
@event_chain = event_chain
|
8
8
|
@object = object
|
9
9
|
@callback = callback
|
10
|
-
|
10
|
+
|
11
11
|
if RUBY_PLATFORM == 'opal' && CHAIN_DEBUG
|
12
12
|
`window.chain_listeners = window.chain_listeners || 0;`
|
13
13
|
`window.chain_listeners += 1;`
|
14
14
|
`console.log('chain listeners: ', window.chain_listeners)`
|
15
15
|
end
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def remove
|
19
19
|
raise "event chain already removed" if @removed
|
20
20
|
@removed = true
|
21
21
|
@event_chain.remove_object(self)
|
22
|
-
|
22
|
+
|
23
23
|
# We need to clear these to free memory
|
24
24
|
@event_chain = nil
|
25
25
|
@object = nil
|
26
26
|
@callback = nil
|
27
|
-
|
27
|
+
|
28
28
|
if RUBY_PLATFORM == 'opal' && CHAIN_DEBUG
|
29
29
|
`window.chain_listeners -= 1;`
|
30
30
|
end
|
@@ -37,7 +37,7 @@ class EventChain
|
|
37
37
|
@main_object = main_object
|
38
38
|
@event_counts = {}
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
# Register an event listener that chains from object to self
|
42
42
|
def setup_listener(event, chain_listener)
|
43
43
|
return chain_listener.object.on(event, @main_object) do |filter, *args|
|
@@ -45,73 +45,73 @@ class EventChain
|
|
45
45
|
callback.call(event, filter, *args)
|
46
46
|
else
|
47
47
|
# Trigger on this value, when it happens on the parent
|
48
|
-
|
48
|
+
|
49
49
|
# Only pass the filter from non-reactive to reactive? This
|
50
50
|
# lets us scope the calls on a proxied object.
|
51
|
-
# Filters limit which listeners are triggered, passing them to
|
51
|
+
# Filters limit which listeners are triggered, passing them to
|
52
52
|
# the ReactiveValue's from non-reactive lets us filter at the
|
53
53
|
# reactive level as well.
|
54
54
|
filter = nil unless !chain_listener.object.reactive? && @main_object.reactive?
|
55
|
-
|
55
|
+
|
56
56
|
@main_object.trigger!(event, filter, *args)
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
# We can chain our events to any other object that includes
|
62
62
|
# Events
|
63
|
-
def add_object(object, &block)
|
64
|
-
# puts "ADD OBJECT: #{object.inspect} to #{self.inspect}"
|
65
|
-
|
63
|
+
def add_object(object, &block)
|
64
|
+
# puts "ADD OBJECT: #{object.inspect} to #{self.inspect}"
|
65
|
+
|
66
66
|
chain_listener = ChainListener.new(self, object, block)
|
67
67
|
|
68
68
|
listeners = {}
|
69
|
-
|
69
|
+
|
70
70
|
@main_object.listeners.keys.each do |event|
|
71
71
|
# Create a listener for each event
|
72
72
|
listeners[event] = setup_listener(event, chain_listener)
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
@event_chain[chain_listener] = listeners
|
76
|
-
|
76
|
+
|
77
77
|
return chain_listener
|
78
78
|
end
|
79
|
-
|
80
|
-
|
79
|
+
|
80
|
+
|
81
81
|
def remove_object(chain_listener)
|
82
82
|
@event_chain[chain_listener].each_pair do |event,listener|
|
83
83
|
# Unbind each listener
|
84
84
|
listener.remove
|
85
85
|
end
|
86
|
-
|
86
|
+
|
87
87
|
@event_chain.delete(chain_listener)
|
88
88
|
end
|
89
|
-
|
89
|
+
|
90
90
|
def add_event(event)
|
91
91
|
unless @event_counts[event]
|
92
92
|
@event_chain.each_pair do |chain_listener,listeners|
|
93
|
-
# Only add if we haven't already chained this event
|
93
|
+
# Only add if we haven't already chained this event
|
94
94
|
unless listeners[event]
|
95
95
|
listeners[event] = setup_listener(event, chain_listener)
|
96
96
|
end
|
97
97
|
end
|
98
98
|
end
|
99
|
-
|
99
|
+
|
100
100
|
@event_counts[event] ||= 0
|
101
101
|
@event_counts[event] += 1
|
102
102
|
end
|
103
|
-
|
103
|
+
|
104
104
|
# Removes the event from all events in all objects
|
105
105
|
def remove_event(event)
|
106
106
|
if @event_counts[event]
|
107
107
|
count = @event_counts[event] -= 1
|
108
|
-
|
108
|
+
|
109
109
|
if count == 0
|
110
110
|
@event_chain.each_pair do |chain_listener,listeners|
|
111
111
|
listeners[event].remove# if listeners[event]
|
112
112
|
listeners.delete(event)
|
113
113
|
end
|
114
|
-
|
114
|
+
|
115
115
|
# Also remove the event count
|
116
116
|
@event_counts.delete(event)
|
117
117
|
end
|
data/lib/volt/reactive/events.rb
CHANGED
@@ -7,7 +7,7 @@ DEBUG = false
|
|
7
7
|
# used to clear the event listener.
|
8
8
|
class Listener
|
9
9
|
attr_reader :scope_provider, :klass
|
10
|
-
|
10
|
+
|
11
11
|
def initialize(klass, event, scope_provider, callback)
|
12
12
|
@klass = klass
|
13
13
|
@event = event
|
@@ -18,41 +18,41 @@ class Listener
|
|
18
18
|
# puts "e: #{event} on #{klass.inspect}"
|
19
19
|
@@all_events ||= []
|
20
20
|
@@all_events << self
|
21
|
-
|
21
|
+
|
22
22
|
# counts = {}
|
23
23
|
# @@all_events.each do |ev|
|
24
24
|
# scope = (ev.scope_provider && ev.scope_provider.scope) || nil
|
25
|
-
#
|
25
|
+
#
|
26
26
|
# # puts `typeof(scope)`
|
27
27
|
# if `typeof(scope) !== 'undefined'`
|
28
28
|
# counts[scope] ||= 0
|
29
29
|
# counts[scope] += 1
|
30
30
|
# end
|
31
31
|
# end
|
32
|
-
#
|
32
|
+
#
|
33
33
|
# puts counts.inspect
|
34
|
-
|
34
|
+
|
35
35
|
`window.total_listeners = window.total_listeners || 0;`
|
36
36
|
`window.total_listeners += 1;`
|
37
37
|
`console.log(window.total_listeners);`
|
38
38
|
end
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
def internal?
|
42
42
|
@internal
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
def scope
|
46
46
|
@scope_provider && scope_provider.respond_to?(:scope) && @scope_provider.scope
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
def call(*args)
|
50
50
|
# raise "Triggered on removed: #{@event} on #{@klass2.inspect}" if @removed
|
51
51
|
if @removed
|
52
52
|
puts "Triggered on a removed event: #{@event}"
|
53
53
|
return
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
# Queue a live value update
|
57
57
|
if @klass.reactive?
|
58
58
|
# We are working with a reactive value. Its receiving an event meaning
|
@@ -60,7 +60,7 @@ class Listener
|
|
60
60
|
@klass.object_tracker.queue_update
|
61
61
|
# puts "Queued: #{ObjectTracker.queue.inspect}"
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
@callback.call(*args)
|
65
65
|
end
|
66
66
|
|
@@ -68,16 +68,16 @@ class Listener
|
|
68
68
|
def remove
|
69
69
|
# puts "FAIL:" if @removed
|
70
70
|
raise "event #{@event} already removed" if @removed
|
71
|
-
|
71
|
+
|
72
72
|
# puts "e rem: #{@event} on #{@klass.inspect}"
|
73
73
|
if DEBUG && RUBY_PLATFORM == 'opal'
|
74
74
|
@@all_events.delete(self) if @@all_events
|
75
|
-
|
75
|
+
|
76
76
|
`window.total_listeners -= 1;`
|
77
77
|
`console.log("Rem", window.total_listeners);`
|
78
78
|
end
|
79
|
-
|
80
|
-
|
79
|
+
|
80
|
+
|
81
81
|
@removed = true
|
82
82
|
@klass.remove_listener(@event, self)
|
83
83
|
|
@@ -91,7 +91,7 @@ class Listener
|
|
91
91
|
# @event = nil
|
92
92
|
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
95
|
def inspect
|
96
96
|
"<Listener:#{object_id} event=#{@event} scope=#{scope.inspect}#{' internal' if internal?}>"
|
97
97
|
end
|
@@ -99,26 +99,26 @@ end
|
|
99
99
|
|
100
100
|
module Events
|
101
101
|
# Add a listener for an event
|
102
|
-
def on(event, scope_provider=nil, &block)
|
102
|
+
def on(event, scope_provider=nil, &block)
|
103
|
+
|
103
104
|
|
104
|
-
|
105
105
|
# if reactive? && [:added, :removed].include?(event)
|
106
106
|
# self.object_tracker.queue_update
|
107
107
|
# ObjectTracker.process_queue
|
108
108
|
# end
|
109
109
|
|
110
110
|
|
111
|
-
# puts "Register: #{event} on #{self.inspect}"
|
111
|
+
# puts "Register: #{event} on #{self.inspect}"
|
112
112
|
event = event.to_sym
|
113
|
-
|
113
|
+
|
114
114
|
new_listener = Listener.new(self, event, scope_provider, block)
|
115
|
-
|
115
|
+
|
116
116
|
@listeners ||= {}
|
117
117
|
@listeners[event] ||= []
|
118
118
|
@listeners[event] << new_listener
|
119
119
|
|
120
120
|
first = @listeners[event].size == 1
|
121
|
-
|
121
|
+
|
122
122
|
# When events get added, we need to notify event chains so they
|
123
123
|
# can update and chain any new events.
|
124
124
|
event_chain.add_event(event) if first
|
@@ -132,7 +132,7 @@ module Events
|
|
132
132
|
|
133
133
|
return new_listener
|
134
134
|
end
|
135
|
-
|
135
|
+
|
136
136
|
def event_chain
|
137
137
|
@event_chain ||= EventChain.new(self)
|
138
138
|
end
|
@@ -146,9 +146,9 @@ module Events
|
|
146
146
|
# a listener
|
147
147
|
def remove_listener(event, listener)
|
148
148
|
event = event.to_sym
|
149
|
-
|
149
|
+
|
150
150
|
raise "Unable to delete #{event} from #{self.inspect}" unless @listeners && @listeners[event]
|
151
|
-
|
151
|
+
|
152
152
|
# if @listeners && @listeners[event]
|
153
153
|
@listeners[event].delete(listener)
|
154
154
|
|
@@ -169,14 +169,14 @@ module Events
|
|
169
169
|
end
|
170
170
|
# end
|
171
171
|
end
|
172
|
-
|
172
|
+
|
173
173
|
def trigger!(event, filter=nil, *args)
|
174
174
|
are_reactive = reactive?
|
175
175
|
# puts "TRIGGER FOR: #{event} on #{self.inspect}" if !reactive?
|
176
176
|
ObjectTracker.process_queue if !are_reactive# && !respond_to?(:skip_current_queue_flush)
|
177
|
-
|
177
|
+
|
178
178
|
event = event.to_sym
|
179
|
-
|
179
|
+
|
180
180
|
if @listeners && @listeners[event]
|
181
181
|
# puts "LISTENERS FOR #{event} on #{self.inspect} - #{@listeners[event].inspect}"
|
182
182
|
# TODO: We have to dup here because one trigger might remove another
|
@@ -187,7 +187,7 @@ module Events
|
|
187
187
|
# if we aren't reactive, we should pass to all of our reactive listeners, since they
|
188
188
|
# just proxy us.
|
189
189
|
# If the filter exists, check it
|
190
|
-
# puts "CHECK #{listener.inspect} : #{self.inspect} -- #{listener.klass.inspect}"
|
190
|
+
# puts "CHECK #{listener.inspect} : #{self.inspect} -- #{listener.klass.inspect}"
|
191
191
|
if (!filter || (!are_reactive && listener.scope_provider.reactive?) || filter.call(listener.scope))
|
192
192
|
listener.call(filter, *args)
|
193
193
|
end
|
@@ -196,19 +196,19 @@ module Events
|
|
196
196
|
|
197
197
|
nil
|
198
198
|
end
|
199
|
-
|
200
|
-
# Takes a block, which passes in
|
199
|
+
|
200
|
+
# Takes a block, which passes in
|
201
201
|
def trigger_by_scope!(event, *args, &block)
|
202
202
|
trigger!(event, block, *args)
|
203
203
|
end
|
204
|
-
|
204
|
+
|
205
205
|
# Takes an event and a list of method names, and triggers the event for each listener
|
206
206
|
# coming off of those methods.
|
207
207
|
def trigger_for_methods!(event, *method_names)
|
208
208
|
trigger_by_scope!(event, [], nil) do |scope|
|
209
209
|
if scope
|
210
210
|
method_name = scope.first
|
211
|
-
|
211
|
+
|
212
212
|
method_names.include?(method_name)
|
213
213
|
else
|
214
214
|
false
|
@@ -216,4 +216,4 @@ module Events
|
|
216
216
|
end
|
217
217
|
end
|
218
218
|
|
219
|
-
end
|
219
|
+
end
|
@@ -3,50 +3,50 @@ class ObjectTracker
|
|
3
3
|
@@queue = {}
|
4
4
|
@@cache_enabled = false
|
5
5
|
@@cache_version = 0
|
6
|
-
|
6
|
+
|
7
7
|
def self.cache_enabled
|
8
8
|
@@cache_enabled
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def self.enable_cache
|
12
12
|
clear_cache
|
13
13
|
@@cache_enabled = true
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def self.disable_cache
|
17
17
|
@@cache_enabled = false
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
def self.cache_version
|
21
21
|
@@cache_version
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
def self.clear_cache
|
25
25
|
@@cache_version = (@@cache_version || 0) + 1
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
def initialize(main_object)
|
29
29
|
@main_object = main_object
|
30
30
|
@enabled = false
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
def self.queue
|
34
34
|
@@queue
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
def queue_update
|
38
38
|
# puts "Queue: #{@main_object.inspect}"
|
39
39
|
@@queue[self] = true
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
# Run through the queue and update the followers for each
|
43
43
|
def self.process_queue
|
44
44
|
return if @@queue.size == 0
|
45
45
|
# puts "PROCESS QUEUE: #{@@queue.size}"
|
46
46
|
queue = @@queue
|
47
47
|
|
48
|
-
# puts "Update Followers #{@@queue.size}"
|
49
|
-
|
48
|
+
# puts "Update Followers #{@@queue.size}"
|
49
|
+
|
50
50
|
# Clear before running incase someone adds during
|
51
51
|
@@queue = {}
|
52
52
|
# self.enable_cache
|
@@ -54,19 +54,19 @@ class ObjectTracker
|
|
54
54
|
queue.each_pair do |object_tracker,val|
|
55
55
|
object_tracker.update_followers
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
# self.disable_cache
|
59
|
-
|
59
|
+
|
60
60
|
# puts "UPDATED FOLLOWERS"
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
def enable!
|
64
64
|
unless @enabled
|
65
65
|
@enabled = true
|
66
66
|
queue_update
|
67
67
|
end
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
def disable!
|
71
71
|
remove_followers
|
72
72
|
@@queue.delete(self)
|
@@ -76,12 +76,12 @@ class ObjectTracker
|
|
76
76
|
def update_followers
|
77
77
|
if @enabled
|
78
78
|
current_obj = @main_object.cur#(true)
|
79
|
-
|
79
|
+
|
80
80
|
# puts "UPDATE ON #{current_obj.inspect}"
|
81
|
-
|
81
|
+
|
82
82
|
if !@cached_current_obj || current_obj.object_id != @cached_current_obj.object_id
|
83
83
|
remove_followers
|
84
|
-
|
84
|
+
|
85
85
|
# Add to current
|
86
86
|
should_attach = current_obj.respond_to?(:on)
|
87
87
|
if should_attach
|
@@ -93,15 +93,15 @@ class ObjectTracker
|
|
93
93
|
else
|
94
94
|
end
|
95
95
|
end
|
96
|
-
|
96
|
+
|
97
97
|
# Remove follower
|
98
98
|
def remove_followers
|
99
99
|
# Remove from previous
|
100
100
|
if @cached_current_obj
|
101
101
|
@current_obj_chain_listener.remove
|
102
102
|
@current_obj_chain_listener = nil
|
103
|
-
|
103
|
+
|
104
104
|
@cached_current_obj = nil
|
105
105
|
end
|
106
106
|
end
|
107
|
-
end
|
107
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# Provides methods for objects that store reactive value's to trigger
|
2
2
|
module ObjectTracking
|
3
3
|
def __setup_tracking(key, value)
|
4
|
-
if value.reactive?
|
4
|
+
if value.reactive?
|
5
5
|
# TODO: We should build this in so it fires just for the current index.
|
6
6
|
# Currently this is a big performance hit.
|
7
7
|
chain_listener = event_chain.add_object(value.reactive_manager) do |event, *args|
|
@@ -11,4 +11,4 @@ module ObjectTracking
|
|
11
11
|
@reactive_element_listeners[key] = chain_listener
|
12
12
|
end
|
13
13
|
end
|
14
|
-
end
|
14
|
+
end
|