glimmer 0.10.4 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +379 -0
- data/CONTRIBUTING.md +62 -0
- data/LICENSE.txt +1 -1
- data/PROCESS.md +35 -0
- data/README.md +441 -3546
- data/VERSION +1 -1
- data/glimmer.gemspec +83 -0
- data/lib/glimmer.rb +32 -15
- data/lib/glimmer/config.rb +22 -1
- data/lib/glimmer/data_binding/model_binding.rb +38 -28
- data/lib/glimmer/data_binding/observable.rb +21 -0
- data/lib/glimmer/data_binding/observable_array.rb +51 -46
- data/lib/glimmer/data_binding/observable_model.rb +62 -21
- data/lib/glimmer/data_binding/observer.rb +24 -2
- data/lib/glimmer/dsl/engine.rb +66 -58
- data/lib/glimmer/dsl/expression.rb +21 -0
- data/lib/glimmer/dsl/expression_handler.rb +21 -0
- data/lib/glimmer/dsl/parent_expression.rb +21 -0
- data/lib/glimmer/dsl/static_expression.rb +21 -0
- data/lib/glimmer/dsl/top_level_expression.rb +21 -0
- data/lib/glimmer/error.rb +21 -0
- data/lib/glimmer/invalid_keyword_error.rb +21 -0
- metadata +43 -21
- data/lib/glimmer/excluded_keyword_error.rb +0 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
1.0.4
|
data/glimmer.gemspec
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: glimmer 1.0.4 ruby lib
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "glimmer".freeze
|
9
|
+
s.version = "1.0.4"
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib".freeze]
|
13
|
+
s.authors = ["AndyMaleh".freeze]
|
14
|
+
s.date = "2020-11-21"
|
15
|
+
s.description = "Glimmer is a Ruby DSL Framework consisting of a DSL Engine and Observable/Observer/Data-Binding Library. Used in the Glimmer DSL for SWT (JRuby Desktop Development GUI Library), the Glimmer DSL for Tk (Ruby Desktop Development GUI Library), the Glimmer DSL for Opal (Web GUI Adapter for Desktop Apps), the Glimmer DSL for XML (& HTML), and the Glimmer DSL for CSS.".freeze
|
16
|
+
s.email = "andy.am@gmail.com".freeze
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"CHANGELOG.md",
|
19
|
+
"LICENSE.txt",
|
20
|
+
"README.md"
|
21
|
+
]
|
22
|
+
s.files = [
|
23
|
+
"CHANGELOG.md",
|
24
|
+
"CONTRIBUTING.md",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"PROCESS.md",
|
27
|
+
"README.md",
|
28
|
+
"VERSION",
|
29
|
+
"glimmer.gemspec",
|
30
|
+
"lib/glimmer.rb",
|
31
|
+
"lib/glimmer/config.rb",
|
32
|
+
"lib/glimmer/data_binding/model_binding.rb",
|
33
|
+
"lib/glimmer/data_binding/observable.rb",
|
34
|
+
"lib/glimmer/data_binding/observable_array.rb",
|
35
|
+
"lib/glimmer/data_binding/observable_model.rb",
|
36
|
+
"lib/glimmer/data_binding/observer.rb",
|
37
|
+
"lib/glimmer/dsl/engine.rb",
|
38
|
+
"lib/glimmer/dsl/expression.rb",
|
39
|
+
"lib/glimmer/dsl/expression_handler.rb",
|
40
|
+
"lib/glimmer/dsl/parent_expression.rb",
|
41
|
+
"lib/glimmer/dsl/static_expression.rb",
|
42
|
+
"lib/glimmer/dsl/top_level_expression.rb",
|
43
|
+
"lib/glimmer/error.rb",
|
44
|
+
"lib/glimmer/invalid_keyword_error.rb"
|
45
|
+
]
|
46
|
+
s.homepage = "http://github.com/AndyObtiva/glimmer".freeze
|
47
|
+
s.licenses = ["MIT".freeze]
|
48
|
+
s.rubygems_version = "3.1.4".freeze
|
49
|
+
s.summary = "Glimmer Ruby DSL Engine".freeze
|
50
|
+
|
51
|
+
if s.respond_to? :specification_version then
|
52
|
+
s.specification_version = 4
|
53
|
+
end
|
54
|
+
|
55
|
+
if s.respond_to? :add_runtime_dependency then
|
56
|
+
s.add_runtime_dependency(%q<array_include_methods>.freeze, [">= 1.0.4", "< 2.0.0"])
|
57
|
+
s.add_runtime_dependency(%q<facets>.freeze, [">= 3.1.0", "< 4.0.0"])
|
58
|
+
s.add_development_dependency(%q<rspec-mocks>.freeze, ["~> 3.5.0"])
|
59
|
+
s.add_development_dependency(%q<rspec>.freeze, ["~> 3.5.0"])
|
60
|
+
s.add_development_dependency(%q<puts_debuggerer>.freeze, ["~> 0.10.0"])
|
61
|
+
s.add_development_dependency(%q<rake>.freeze, [">= 10.1.0", "< 14.0.0"])
|
62
|
+
s.add_development_dependency(%q<jeweler>.freeze, [">= 2.0.0", "< 3.0.0"])
|
63
|
+
s.add_development_dependency(%q<rdoc>.freeze, [">= 6.2.1", "< 7.0.0"])
|
64
|
+
s.add_development_dependency(%q<coveralls>.freeze, ["= 0.8.23"])
|
65
|
+
s.add_development_dependency(%q<simplecov>.freeze, ["~> 0.16.1"])
|
66
|
+
s.add_development_dependency(%q<simplecov-lcov>.freeze, ["~> 0.7.0"])
|
67
|
+
s.add_development_dependency(%q<rake-tui>.freeze, [">= 0"])
|
68
|
+
else
|
69
|
+
s.add_dependency(%q<array_include_methods>.freeze, [">= 1.0.4", "< 2.0.0"])
|
70
|
+
s.add_dependency(%q<facets>.freeze, [">= 3.1.0", "< 4.0.0"])
|
71
|
+
s.add_dependency(%q<rspec-mocks>.freeze, ["~> 3.5.0"])
|
72
|
+
s.add_dependency(%q<rspec>.freeze, ["~> 3.5.0"])
|
73
|
+
s.add_dependency(%q<puts_debuggerer>.freeze, ["~> 0.10.0"])
|
74
|
+
s.add_dependency(%q<rake>.freeze, [">= 10.1.0", "< 14.0.0"])
|
75
|
+
s.add_dependency(%q<jeweler>.freeze, [">= 2.0.0", "< 3.0.0"])
|
76
|
+
s.add_dependency(%q<rdoc>.freeze, [">= 6.2.1", "< 7.0.0"])
|
77
|
+
s.add_dependency(%q<coveralls>.freeze, ["= 0.8.23"])
|
78
|
+
s.add_dependency(%q<simplecov>.freeze, ["~> 0.16.1"])
|
79
|
+
s.add_dependency(%q<simplecov-lcov>.freeze, ["~> 0.7.0"])
|
80
|
+
s.add_dependency(%q<rake-tui>.freeze, [">= 0"])
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
data/lib/glimmer.rb
CHANGED
@@ -1,7 +1,24 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
1
|
+
# Copyright (c) 2007-2020 Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
5
22
|
require 'logger'
|
6
23
|
require 'set'
|
7
24
|
require 'array_include_methods'
|
@@ -38,22 +55,23 @@ module Glimmer
|
|
38
55
|
end
|
39
56
|
|
40
57
|
def method_missing(method_symbol, *args, &block)
|
41
|
-
new_loop_data = [method_symbol, args, block]
|
42
|
-
if new_loop_data == Glimmer.loop_last_data
|
43
|
-
Glimmer.loop_increment!
|
44
|
-
raise "Glimmer looped #{Config.loop_max_count} times with keyword '#{new_loop_data[0]}'! Check code for errors." if Glimmer.loop == Config.loop_max_count
|
45
|
-
else
|
46
|
-
Glimmer.loop_reset!
|
47
|
-
end
|
48
|
-
Glimmer.loop_last_data = new_loop_data
|
49
58
|
# This if statement speeds up Glimmer in girb or whenever directly including on main object
|
50
59
|
is_excluded = Config.excluded_keyword_checkers.reduce(false) {|result, checker| result || instance_exec(method_symbol, *args, &checker) }
|
51
60
|
if is_excluded
|
52
61
|
Glimmer::Config.logger.debug "Glimmer excluded keyword: #{method_symbol}" if Glimmer::Config.log_excluded_keywords?
|
53
62
|
super(method_symbol, *args, &block)
|
63
|
+
else
|
64
|
+
new_loop_data = [method_symbol, args, block]
|
65
|
+
if new_loop_data == Glimmer.loop_last_data
|
66
|
+
Glimmer.loop_increment!
|
67
|
+
raise "Glimmer looped #{Config.loop_max_count} times with keyword '#{new_loop_data[0]}'! Check code for errors." if Glimmer.loop == Config.loop_max_count
|
68
|
+
else
|
69
|
+
Glimmer.loop_reset!
|
70
|
+
end
|
71
|
+
Glimmer.loop_last_data = new_loop_data
|
72
|
+
Glimmer::Config.logger.info {"Interpreting keyword: #{method_symbol}"}
|
73
|
+
Glimmer::DSL::Engine.interpret(method_symbol, *args, &block)
|
54
74
|
end
|
55
|
-
Glimmer::Config.logger.info {"Interpreting keyword: #{method_symbol}"}
|
56
|
-
Glimmer::DSL::Engine.interpret(method_symbol, *args, &block)
|
57
75
|
rescue InvalidKeywordError => e
|
58
76
|
Glimmer::Config.logger.error {"Encountered an invalid keyword at this object: #{self}"}
|
59
77
|
Glimmer::Config.logger.error {e.full_message}
|
@@ -62,6 +80,5 @@ module Glimmer
|
|
62
80
|
end
|
63
81
|
|
64
82
|
require 'glimmer/error'
|
65
|
-
require 'glimmer/excluded_keyword_error'
|
66
83
|
require 'glimmer/invalid_keyword_error'
|
67
84
|
require 'glimmer/dsl/engine'
|
data/lib/glimmer/config.rb
CHANGED
@@ -1,8 +1,29 @@
|
|
1
|
+
# Copyright (c) 2007-2020 Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
1
22
|
module Glimmer
|
2
23
|
module Config
|
3
24
|
class << self
|
4
25
|
LOOP_MAX_COUNT_DEFAULT = 100
|
5
|
-
REGEX_METHODS_EXCLUDED = /^(to_|\[)/
|
26
|
+
REGEX_METHODS_EXCLUDED = /^(to_|\[|load_iseq)/
|
6
27
|
|
7
28
|
attr_writer :loop_max_count
|
8
29
|
attr_accessor :log_excluded_keywords
|
@@ -1,3 +1,24 @@
|
|
1
|
+
# Copyright (c) 2007-2020 Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
1
22
|
require 'glimmer/data_binding/observable'
|
2
23
|
require 'glimmer/data_binding/observer'
|
3
24
|
|
@@ -7,7 +28,7 @@ module Glimmer
|
|
7
28
|
include Observable
|
8
29
|
include Observer
|
9
30
|
|
10
|
-
attr_reader :binding_options
|
31
|
+
attr_reader :binding_options, :property_name_expression
|
11
32
|
|
12
33
|
def initialize(base_model, property_name_expression, binding_options = nil)
|
13
34
|
@base_model = base_model
|
@@ -60,19 +81,10 @@ module Glimmer
|
|
60
81
|
end
|
61
82
|
|
62
83
|
def apply_converter(converter, value)
|
63
|
-
if converter.nil?
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
value.send(converter)
|
68
|
-
else
|
69
|
-
raise Glimmer::Error, "Unsupported bind converter: #{converter.inspect}"
|
70
|
-
end
|
71
|
-
elsif converter.respond_to?(:call, value)
|
72
|
-
converter.call(value)
|
73
|
-
else
|
74
|
-
raise Glimmer::Error, "Unsupported bind converter: #{converter.inspect}"
|
75
|
-
end
|
84
|
+
return value if converter.nil?
|
85
|
+
return value.send(converter) if (converter.is_a?(String) || converter.is_a?(Symbol)) && value.respond_to?(converter)
|
86
|
+
return converter.call(value) if converter.respond_to?(:call, value)
|
87
|
+
raise Glimmer::Error, "Unsupported bind converter: #{converter.inspect}"
|
76
88
|
end
|
77
89
|
|
78
90
|
# All nested property names
|
@@ -99,10 +111,6 @@ module Glimmer
|
|
99
111
|
property_name_expression.match(/[.\[]/)
|
100
112
|
end
|
101
113
|
|
102
|
-
def property_name_expression
|
103
|
-
@property_name_expression
|
104
|
-
end
|
105
|
-
|
106
114
|
def computed?
|
107
115
|
!computed_by.empty?
|
108
116
|
end
|
@@ -179,17 +187,19 @@ module Glimmer
|
|
179
187
|
model, property_name = zip
|
180
188
|
nested_property_observer = nested_property_observers[property_name]
|
181
189
|
previous_index = i - 1
|
182
|
-
|
183
|
-
|
184
|
-
|
190
|
+
if previous_index.negative?
|
191
|
+
parent_model = self
|
192
|
+
parent_property_name = nil
|
193
|
+
parent_observer = observer
|
194
|
+
else
|
195
|
+
parent_model = nested_models[previous_index]
|
196
|
+
parent_property_name = nested_property_names[previous_index]
|
197
|
+
parent_observer = nested_property_observers[parent_property_name]
|
198
|
+
end
|
185
199
|
parent_property_name = nil if parent_property_name.to_s.start_with?('[')
|
186
200
|
unless model.nil?
|
187
|
-
|
188
|
-
|
189
|
-
observer_registration = nested_property_observer.observe(model)
|
190
|
-
else
|
191
|
-
observer_registration = nested_property_observer.observe(model, property_name)
|
192
|
-
end
|
201
|
+
# TODO figure out a way to deal with this more uniformly
|
202
|
+
observer_registration = property_indexed?(property_name) ? nested_property_observer.observe(model) : nested_property_observer.observe(model, property_name)
|
193
203
|
parent_registration = parent_observer.registration_for(parent_model, parent_property_name)
|
194
204
|
parent_observer.add_dependent(parent_registration => observer_registration)
|
195
205
|
end
|
@@ -203,7 +213,7 @@ module Glimmer
|
|
203
213
|
end
|
204
214
|
|
205
215
|
def evaluate_property
|
206
|
-
value = nil
|
216
|
+
value = nil
|
207
217
|
value = invoke_property_reader(model, property_name) unless model.nil?
|
208
218
|
convert_on_read(value)
|
209
219
|
end
|
@@ -1,3 +1,24 @@
|
|
1
|
+
# Copyright (c) 2007-2020 Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
1
22
|
require 'glimmer/error'
|
2
23
|
|
3
24
|
module Glimmer
|
@@ -1,13 +1,32 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# Copyright (c) 2007-2020 Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
3
21
|
|
22
|
+
require 'set'
|
4
23
|
require 'glimmer/data_binding/observable'
|
24
|
+
require 'array_include_methods'
|
5
25
|
|
6
26
|
using ArrayIncludeMethods
|
7
27
|
|
8
28
|
module Glimmer
|
9
29
|
module DataBinding
|
10
|
-
# TODO prefix utility methods with double-underscore
|
11
30
|
module ObservableArray
|
12
31
|
include Observable
|
13
32
|
|
@@ -29,7 +48,7 @@ module Glimmer
|
|
29
48
|
def add_element_observer(element, observer)
|
30
49
|
element_properties_for(observer).each do |property|
|
31
50
|
observer.observe(element, property)
|
32
|
-
end
|
51
|
+
end
|
33
52
|
end
|
34
53
|
|
35
54
|
def remove_observer(observer, *element_properties)
|
@@ -37,30 +56,26 @@ module Glimmer
|
|
37
56
|
if !element_properties.empty?
|
38
57
|
old_element_properties = element_properties_for(observer)
|
39
58
|
observer_element_properties[observer] = element_properties_for(observer) - Set.new(element_properties)
|
40
|
-
each
|
41
|
-
element_properties.each do |property|
|
42
|
-
observer.unobserve(element, property)
|
43
|
-
end
|
44
|
-
end
|
59
|
+
each { |element| element_properties.each { |property| observer.unobserve(element, property) } }
|
45
60
|
end
|
46
61
|
if element_properties_for(observer).empty?
|
47
62
|
property_observer_list.delete(observer)
|
48
63
|
observer_element_properties.delete(observer)
|
49
64
|
each { |element| remove_element_observer(element, observer) }
|
50
|
-
end
|
65
|
+
end
|
51
66
|
observer
|
52
67
|
end
|
53
68
|
|
54
69
|
def remove_element_observers(element)
|
55
70
|
property_observer_list.each do |observer|
|
56
71
|
remove_element_observer(element, observer)
|
57
|
-
end
|
72
|
+
end
|
58
73
|
end
|
59
74
|
|
60
75
|
def remove_element_observer(element, observer)
|
61
76
|
element_properties_for(observer).each do |property|
|
62
77
|
observer.unobserve(element, property)
|
63
|
-
end
|
78
|
+
end
|
64
79
|
end
|
65
80
|
|
66
81
|
def has_observer?(observer)
|
@@ -89,17 +104,18 @@ module Glimmer
|
|
89
104
|
|
90
105
|
def <<(element)
|
91
106
|
super(element).tap do
|
92
|
-
add_element_observers(element)
|
107
|
+
add_element_observers(element)
|
93
108
|
notify_observers
|
94
109
|
end
|
95
110
|
end
|
96
111
|
alias push <<
|
112
|
+
alias append <<
|
97
113
|
|
98
114
|
def []=(index, value)
|
99
115
|
old_value = self[index]
|
100
116
|
unregister_dependent_observers(old_value)
|
101
117
|
remove_element_observers(old_value)
|
102
|
-
add_element_observers(value)
|
118
|
+
add_element_observers(value)
|
103
119
|
super(index, value).tap do
|
104
120
|
notify_observers
|
105
121
|
end
|
@@ -135,7 +151,7 @@ module Glimmer
|
|
135
151
|
if block_given?
|
136
152
|
old_array = Array.new(self)
|
137
153
|
super(&block).tap do |new_array|
|
138
|
-
(old_array - new_array).each do |element|
|
154
|
+
(old_array - new_array).each do |element|
|
139
155
|
unregister_dependent_observers(element)
|
140
156
|
remove_element_observers(element)
|
141
157
|
end
|
@@ -169,9 +185,7 @@ module Glimmer
|
|
169
185
|
remove_element_observers(old_value)
|
170
186
|
end
|
171
187
|
super(&block).tap do
|
172
|
-
each
|
173
|
-
add_element_observers(element)
|
174
|
-
end
|
188
|
+
each { |element| add_element_observers(element) }
|
175
189
|
notify_observers
|
176
190
|
end
|
177
191
|
else
|
@@ -181,9 +195,7 @@ module Glimmer
|
|
181
195
|
alias map! collect!
|
182
196
|
|
183
197
|
def compact!
|
184
|
-
super.tap
|
185
|
-
notify_observers
|
186
|
-
end
|
198
|
+
super.tap { notify_observers }
|
187
199
|
end
|
188
200
|
|
189
201
|
def flatten!(level=nil)
|
@@ -192,17 +204,13 @@ module Glimmer
|
|
192
204
|
remove_element_observers(old_value)
|
193
205
|
end
|
194
206
|
(level.nil? ? super() : super(level)).tap do
|
195
|
-
each
|
196
|
-
add_element_observers(element)
|
197
|
-
end
|
207
|
+
each { |element| add_element_observers(element) }
|
198
208
|
notify_observers
|
199
209
|
end
|
200
210
|
end
|
201
211
|
|
202
212
|
def rotate!(count=1)
|
203
|
-
super(count).tap
|
204
|
-
notify_observers
|
205
|
-
end
|
213
|
+
super(count).tap { notify_observers }
|
206
214
|
end
|
207
215
|
|
208
216
|
def select!(&block)
|
@@ -221,9 +229,7 @@ module Glimmer
|
|
221
229
|
end
|
222
230
|
|
223
231
|
def shuffle!(hash = nil)
|
224
|
-
(hash.nil? ? super() : super(random: hash[:random])).tap
|
225
|
-
notify_observers
|
226
|
-
end
|
232
|
+
(hash.nil? ? super() : super(random: hash[:random])).tap { notify_observers }
|
227
233
|
end
|
228
234
|
|
229
235
|
def slice!(arg1, arg2=nil)
|
@@ -238,15 +244,11 @@ module Glimmer
|
|
238
244
|
end
|
239
245
|
|
240
246
|
def sort!(&block)
|
241
|
-
(block.nil? ? super() : super(&block)).tap
|
242
|
-
notify_observers
|
243
|
-
end
|
247
|
+
(block.nil? ? super() : super(&block)).tap { notify_observers }
|
244
248
|
end
|
245
249
|
|
246
250
|
def sort_by!(&block)
|
247
|
-
(block.nil? ? super() : super(&block)).tap
|
248
|
-
notify_observers
|
249
|
-
end
|
251
|
+
(block.nil? ? super() : super(&block)).tap { notify_observers }
|
250
252
|
end
|
251
253
|
|
252
254
|
def uniq!(&block)
|
@@ -255,15 +257,23 @@ module Glimmer
|
|
255
257
|
remove_element_observers(old_value)
|
256
258
|
end
|
257
259
|
(block.nil? ? super() : super(&block)).tap do
|
258
|
-
each
|
259
|
-
add_element_observers(element)
|
260
|
-
end
|
260
|
+
each { |element| add_element_observers(element) }
|
261
261
|
notify_observers
|
262
262
|
end
|
263
263
|
end
|
264
264
|
|
265
|
+
def unshift(element)
|
266
|
+
super(element).tap do
|
267
|
+
add_element_observers(element)
|
268
|
+
notify_observers
|
269
|
+
end
|
270
|
+
end
|
271
|
+
alias prepend unshift
|
272
|
+
|
265
273
|
def reject!(&block)
|
266
|
-
if
|
274
|
+
if block.nil?
|
275
|
+
super
|
276
|
+
else
|
267
277
|
old_array = Array.new(self)
|
268
278
|
super(&block).tap do
|
269
279
|
(old_array - self).each do |old_value|
|
@@ -272,17 +282,12 @@ module Glimmer
|
|
272
282
|
end
|
273
283
|
notify_observers
|
274
284
|
end
|
275
|
-
else
|
276
|
-
super
|
277
285
|
end
|
278
286
|
end
|
279
287
|
|
280
288
|
def unregister_dependent_observers(old_value)
|
281
|
-
# TODO look into optimizing this
|
282
289
|
return unless old_value.is_a?(ObservableModel) || old_value.is_a?(ObservableArray)
|
283
|
-
property_observer_list.each
|
284
|
-
observer.unregister_dependents_with_observable(observer.registration_for(self), old_value)
|
285
|
-
end
|
290
|
+
property_observer_list.each { |observer| observer.unregister_dependents_with_observable(observer.registration_for(self), old_value) }
|
286
291
|
end
|
287
292
|
end
|
288
293
|
end
|