volt 0.9.7.pre3 → 0.9.7.pre5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 14f0e852a5a80c23450553604545cc05f2046713
4
- data.tar.gz: 8714d6c8452571f7b556238f749504ac85bd0a4b
3
+ metadata.gz: 3cdc140dec9dafbccfdc80fbe5f9e98695b46394
4
+ data.tar.gz: c4e30bbd6a618229e594cfdbff8b40f4dcedaae8
5
5
  SHA512:
6
- metadata.gz: e359ae0d0fea64290af10f8f08f59f5fe21bd5ec623f0ed8dfde2e2612e8f6915b85f2098b499436dd25f9f73dd63b2f7061abbbb5f6946e6ea54b2b59cbb07b
7
- data.tar.gz: bcbe9de16828193c20085cbf3d953e003e6ce3e4ddcd0f9a9fe98c5987a6e29d9efb0c81bd26d2b061f71b72e7cae94550fc51bb5d7ab03a761c57fcd652d909
6
+ metadata.gz: ba0802d6f9adcbf18ec68a28b95629ecfb59a9fa2cb2ea29f3c1c8e922c7e918af509647f95d28e8f23b840c7bda0bb91ff2451df02e9794eb9236b24ce574d6
7
+ data.tar.gz: e65b951533259dacf018849c1a0e0c2cf46f23205a1d11fdd9a8ab469aaa7d6d624fc6d075950b616cad916867a3a417e4844a9e3923fcc9480c1d27f227627e
@@ -5,4 +5,6 @@
5
5
  class VoltAppProperty < Volt::Model
6
6
  field :name, String
7
7
  field :value, String
8
+
9
+ index :name, unique: true
8
10
  end
@@ -103,26 +103,12 @@ module Volt
103
103
 
104
104
  # Sets the current model on this controller
105
105
  def model=(val)
106
- if val.is_a?(Promise)
107
- # Resolve the promise before setting
108
- self.last_promise = val
106
+ # Clear the proc watcher
107
+ stop_proc_watcher
109
108
 
110
- val.then do |result|
111
- # Only assign if nothing else has been assigned since we started the resolve
112
- self.model = result if last_promise == val
113
- end.fail do |err|
114
- Volt.logger.error("Unable to resolve promise assigned to model on #{inspect}")
115
- end
116
-
117
- return
118
- end
119
-
120
- # Clear
109
+ # Clear last promise
121
110
  self.last_promise = nil
122
111
 
123
- # Start with a nil reactive value.
124
- self.current_model ||= Model.new
125
-
126
112
  if Symbol === val || String === val
127
113
  collections = [:page, :store, :params, :controller]
128
114
  if collections.include?(val.to_sym)
@@ -130,16 +116,61 @@ module Volt
130
116
  else
131
117
  fail "#{val} is not the name of a valid model, choose from: #{collections.join(', ')}"
132
118
  end
119
+
120
+ return
121
+ end
122
+ # If the val is a proc, then we need to call the proc in a watch, and
123
+ # run the rest of the assign after
124
+
125
+ if val.is_a?(Proc)
126
+ @model_proc_watcher = proc do
127
+ # unwrap in a proc
128
+ new_val = val.call
129
+
130
+ # The assignment part we don't want to watch on because it will be
131
+ # changing the current_model reactive_accessor.
132
+ u do
133
+ assign_current_model(new_val)
134
+ end
135
+ end.watch!
133
136
  else
134
- self.current_model = val
137
+ assign_current_model(val)
135
138
  end
136
139
  end
137
140
 
141
+ def stop_proc_watcher
142
+ @model_proc_watcher.stop if @model_proc_watcher
143
+ @model_proc_watcher = nil
144
+ end
145
+
146
+ def controller_removed!
147
+ stop_proc_watcher
148
+ end
149
+
150
+ def assign_current_model(val)
151
+ if val.is_a?(Promise)
152
+ # Resolve the promise before setting
153
+ self.last_promise = val
154
+
155
+ val.then do |result|
156
+ # Only assign if nothing else has been assigned since we started the resolve
157
+ self.current_model = result if last_promise == val
158
+ self.last_promise = nil
159
+ end.fail do |err|
160
+ Volt.logger.error("Unable to resolve promise assigned to ModelController: #{inspect}")
161
+ end
162
+
163
+ return
164
+ end
165
+
166
+ self.current_model = val
167
+ end
168
+
138
169
  def model
139
170
  model = self.current_model
140
171
 
141
- # If the model is a proc, call it now
142
- model = model.call if model && model.is_a?(Proc)
172
+ # # If the model is a proc, call it now
173
+ # model = model.call if model && model.is_a?(Proc)
143
174
 
144
175
  model
145
176
  end
@@ -49,10 +49,10 @@ class VoltTime
49
49
  # Live now acts just like now, except it invalidates any computations the
50
50
  # VoltTime object is used in at every interval. This makes it easy to
51
51
  # display live timer's.
52
- def live_now(interval=1000)
52
+ def live_now(seconds=1)
53
53
  dep = Volt::Dependency.new
54
54
  dep.depend
55
- Volt::Timers.client_set_timeout(interval) do
55
+ Volt::Timers.client_set_timeout(seconds * 1000) do
56
56
  dep.changed!
57
57
  end
58
58
  VoltTime.new
@@ -22,11 +22,9 @@ module Volt
22
22
 
23
23
  # setter
24
24
  define_method(:"#{method_name}=") do |obj|
25
- # Associatie the obj's foreign key
26
- obj.set(foreign_key, id)
27
-
28
- # Associate on the method name
29
- set(method_name, obj)
25
+ # Associate the local key
26
+ foreign_key_value = obj.get(foreign_key)
27
+ set(local_key, foreign_key_value)
30
28
  end
31
29
  end
32
30
 
@@ -151,7 +151,6 @@ module Volt
151
151
  end
152
152
 
153
153
  def changed(model_id, data)
154
- puts "CH: #{model_id.inspect} - #{data.inspect}"
155
154
  $loading_models = true
156
155
  Persistors::ModelStore.changed(model_id, data)
157
156
  $loading_models = false
@@ -142,6 +142,7 @@ module Volt
142
142
  # Remove existing controller and template and call _removed
143
143
  if @current_controller_handler
144
144
  @current_controller_handler.call_action('before', 'remove')
145
+ @current_controller_handler.send_controller_removed!
145
146
  end
146
147
 
147
148
  if @current_template
@@ -59,6 +59,14 @@ module Volt
59
59
  false
60
60
  end
61
61
 
62
+ # If the controller wants to know, provide a general way the controller can
63
+ # know if its being removed. This lets us cleanup any watches.
64
+ def send_controller_removed!
65
+ if @controller.respond_to?(:controller_removed!)
66
+ @controller.controller_removed!
67
+ end
68
+ end
69
+
62
70
  # Fetch the controller class
63
71
  def self.get_controller_and_action(controller_path)
64
72
  fail "Invalid controller path: #{controller_path.inspect}" unless controller_path && controller_path.size > 0
@@ -32,6 +32,10 @@ module Volt
32
32
  element = `$(event.target || event.originalEvent.target)`
33
33
 
34
34
  loop do
35
+ if `event.isPropagationStopped()`
36
+ break
37
+ end
38
+
35
39
  # Lookup the handler, make sure to not assume the group
36
40
  # exists.
37
41
  # TODO: Sometimes the event doesn't exist, but we still get
@@ -1,5 +1,5 @@
1
1
  module Volt
2
2
  module Version
3
- STRING = '0.9.7.pre3'
3
+ STRING = '0.9.7.pre5'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: volt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.7.pre3
4
+ version: 0.9.7.pre5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Stout
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-06 00:00:00.000000000 Z
11
+ date: 2015-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor