glimmer 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b09d96f8f2a0923f53d0685bdae8743d99d42e2c50294852d3823bbb619ddffc
4
- data.tar.gz: 50362bdb44afbd375bb580dcffc5f734c1ff372a10bbddbdeb8ec6600f9b8c06
3
+ metadata.gz: 6f23c9710bdd925d4c539caf3f610b2b7c223d606ad83f9639704cb745d760b6
4
+ data.tar.gz: f8345c248ce903b335c5dbb734b66e5b83671dac2bff9fb981292c759fe20161
5
5
  SHA512:
6
- metadata.gz: 27fb9b837708455a6d68e24f8f6a5fdca9c812e1d5b45c9fea379e51365c5a08688ad116276d6b848cb19a29b97b50be6cdfbba36332bca20b7fc0c253b29789
7
- data.tar.gz: 6cd85c6a1f08d33646e5a105293ed24fef06aecd54ccb82680ddd6e95f701fa0943ccc8370f61e39f58e7d3e531f8154e5889ddc5072bb3b24f3a7518a348a10
6
+ metadata.gz: 75c523cddf99e08c89931b29ac0c81faed4a62612d740181af2b9d9bf5ed8c861b646a1487026f2cb8773cbb22be520234f76cada898bca992ddead22e677676
7
+ data.tar.gz: 5e4771b3eda1930e9f54677e2e4be2064f89f966efe4c4b18038acba79fad60fcdb7a6f3cacb7aeede4f759e2f1e8dfd09e0f9e1070035704a782e9d98e9f320
data/README.markdown CHANGED
@@ -66,14 +66,14 @@ Please follow these instructions to make the `glimmer` command available on your
66
66
 
67
67
  Run this command to install directly:
68
68
  ```
69
- jgem install glimmer -v 0.2.3
69
+ jgem install glimmer -v 0.2.4
70
70
  ```
71
71
 
72
72
  ### Option 2: Bundler
73
73
 
74
74
  Add the following to `Gemfile`:
75
75
  ```
76
- gem 'glimmer', '~> 0.2.3'
76
+ gem 'glimmer', '~> 0.2.4'
77
77
  ```
78
78
 
79
79
  And, then run:
@@ -133,6 +133,7 @@ Data-binding examples:
133
133
  - `text bind(contact, 'address.street')`
134
134
  - `text bind(contact, 'addresses[1].street')`
135
135
  - `text bind(contact, :name, computed_by: [:first_name, :last_name])`
136
+ - `text bind(contact, 'profiles[0].name', computed_by: ['profiles[0].first_name', 'profiles[0].last_name'])`
136
137
 
137
138
  The first example binds the text property of a widget like `label` to the first name of a contact model.
138
139
 
@@ -141,7 +142,9 @@ the address of a contact. This is called nested property data binding.
141
142
 
142
143
  The third example binds the text property of a widget like `label` to the nested indexed address street of a contact. This is called nested indexed property data binding.
143
144
 
144
- The fourth example demonstrates computed value data binding whereby the value of `name` depends on changes to both `first_name` and `last_name`
145
+ The fourth example demonstrates computed value data binding whereby the value of `name` depends on changes to both `first_name` and `last_name`.
146
+
147
+ The fifth example demonstrates nested indexed computed value data binding whereby the value of `profiles[0].name` depends on changes to both nested `profiles[0].first_name` and `profiles[0].last_name`.
145
148
 
146
149
  You may learn more about Glimmer's syntax by reading the Eclipse Zone Tutorial mentioned in resources and opening up the samples under the `samples` folder.
147
150
 
@@ -56,15 +56,9 @@ class DataBindingCommandHandler
56
56
  def do_handle(parent, command_symbol, *args, &block)
57
57
  model_binding = args[0]
58
58
  widget_binding_parameters = [parent, command_symbol.to_s]
59
- widget_binding_parameters << proc {|value| model_binding.evaluate_property} if model_binding.binding_options.has_key?(:computed_by)
60
59
  widget_binding = WidgetBinding.new(*widget_binding_parameters)
61
60
  widget_binding.update(model_binding.evaluate_property)
62
- model = model_binding.model
63
61
  model_binding.add_observer(widget_binding)
64
- computed_by_property_names = model_binding.binding_options[:computed_by]
65
- computed_by_property_names&.each do |computed_by_property_name|
66
- model.add_observer(computed_by_property_name, widget_binding)
67
- end
68
62
  widget_data_binder_map = @@widget_data_binders[parent.widget.class]
69
63
  widget_data_binder = widget_data_binder_map[command_symbol.to_s.to_sym] if widget_data_binder_map
70
64
  widget_data_binder.call(parent, model_binding) if widget_data_binder
@@ -15,6 +15,11 @@ class ModelBinding
15
15
  @property_name_expression = property_name_expression
16
16
  @property_type = property_type
17
17
  @binding_options = binding_options || {}
18
+ if computed?
19
+ @computed_model_bindings = computed_by.map do |computed_by_property_expression|
20
+ self.class.new(base_model, computed_by_property_expression, :undefined, computed_binding_options)
21
+ end
22
+ end
18
23
  end
19
24
  def model
20
25
  nested_property? ? nested_model : base_model
@@ -65,6 +70,15 @@ class ModelBinding
65
70
  def property_name_expression
66
71
  @property_name_expression
67
72
  end
73
+ def computed?
74
+ !!computed_by
75
+ end
76
+ def computed_by
77
+ @binding_options[:computed_by]
78
+ end
79
+ def computed_binding_options
80
+ @binding_options.reject {|k,v| k == :computed_by}
81
+ end
68
82
  def nested_property_observers_for(observer)
69
83
  @nested_property_observers_collection ||= {}
70
84
  unless @nested_property_observers_collection.has_key?(observer)
@@ -81,6 +95,21 @@ class ModelBinding
81
95
  @nested_property_observers_collection[observer]
82
96
  end
83
97
  def add_observer(observer)
98
+ if computed?
99
+ add_computed_observers(observer)
100
+ else
101
+ add_direct_observer(observer)
102
+ end
103
+ end
104
+ def add_computed_observers(observer)
105
+ computed_observer = BlockObserver.new do |changed_value|
106
+ observer.update(evaluate_property)
107
+ end
108
+ @computed_model_bindings.each do |computed_model_binding|
109
+ computed_model_binding.add_observer(computed_observer)
110
+ end
111
+ end
112
+ def add_direct_observer(observer)
84
113
  if nested_property?
85
114
  nested_property_observers = nested_property_observers_for(observer)
86
115
  nested_models.zip(nested_property_names).each do |model, property_name|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - AndyMaleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-06 00:00:00.000000000 Z
11
+ date: 2020-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement