reactive-record 0.7.9 → 0.7.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/reactive-record.rb +1 -0
- data/lib/reactive_record/active_record/error.rb +22 -0
- data/lib/reactive_record/active_record/instance_methods.rb +4 -0
- data/lib/reactive_record/active_record/reactive_record/base.rb +10 -2
- data/lib/reactive_record/active_record/reactive_record/isomorphic_base.rb +16 -13
- data/lib/reactive_record/server_data_cache.rb +5 -1
- data/lib/reactive_record/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f87f4c7dd6020944c3ae979759a058f28c5fc5b2
|
4
|
+
data.tar.gz: f169ab4179b0ef77f3ba0c38257bf09d69e3fd07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 872a3fb5c181c87913f4db432e093a84126e69959b408b3c68e4a5585680eb0aa4cf8965286968b92619ac83f4ea1b94cadbf149b6a6abf2079e2f97309182bf
|
7
|
+
data.tar.gz: 4117a18f6141462ccf5af5bc8e8dde69df493577fbd46c10e03e8c7f9ed710eeb8ecf477653199989ebf3d5dcd587aa2af1471d34605a056024bbfcb12b6775a
|
data/lib/reactive-record.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
if RUBY_ENGINE == 'opal'
|
2
2
|
|
3
3
|
require "reactive-ruby"
|
4
|
+
require "reactive_record/active_record/error"
|
4
5
|
require "reactive_record/server_data_cache"
|
5
6
|
require "reactive_record/active_record/reactive_record/while_loading"
|
6
7
|
require "reactive_record/active_record/reactive_record/isomorphic_base"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module ActiveModel
|
2
|
+
|
3
|
+
class Error
|
4
|
+
|
5
|
+
attr_reader :messages
|
6
|
+
|
7
|
+
def initialize(msgs = {})
|
8
|
+
@messages = msgs || {}
|
9
|
+
@messages.each { |attribute, messages| @messages[attribute] = messages.uniq }
|
10
|
+
end
|
11
|
+
|
12
|
+
def [](attribute)
|
13
|
+
messages[attribute]
|
14
|
+
end
|
15
|
+
|
16
|
+
def empty?
|
17
|
+
messages.empty?
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -208,12 +208,18 @@ module ReactiveRecord
|
|
208
208
|
end
|
209
209
|
false
|
210
210
|
end
|
211
|
+
|
212
|
+
|
213
|
+
def errors
|
214
|
+
@errors ||= ActiveModel::Error.new
|
215
|
+
end
|
211
216
|
|
212
217
|
def sync!(hash = {}) # does NOT notify (see saved! for notification)
|
213
218
|
@attributes.merge! hash
|
214
219
|
@synced_attributes = @attributes.dup
|
215
220
|
@synced_attributes.each { |key, value| @synced_attributes[key] = value.dup_for_sync if value.is_a? Collection }
|
216
221
|
@saving = false
|
222
|
+
@errors = nil
|
217
223
|
self
|
218
224
|
end
|
219
225
|
|
@@ -228,6 +234,7 @@ module ReactiveRecord
|
|
228
234
|
@ar_instance.send("#{attribute}=", @synced_attributes[attribute])
|
229
235
|
end
|
230
236
|
@attributes.delete_if { |attribute, value| !@synced_attributes.has_key?(attribute) }
|
237
|
+
@errors = nil
|
231
238
|
end
|
232
239
|
|
233
240
|
def saving!
|
@@ -235,9 +242,10 @@ module ReactiveRecord
|
|
235
242
|
@saving = true
|
236
243
|
end
|
237
244
|
|
238
|
-
def saved!(
|
245
|
+
def saved!(errors = nil) # sets saving to false AND notifies
|
239
246
|
@saving = false
|
240
|
-
React::State.set_state(self, self, :saved) unless data_loading? or
|
247
|
+
React::State.set_state(self, self, :saved) unless data_loading? or errors
|
248
|
+
@errors = ActiveModel::Error.new(errors)
|
241
249
|
self
|
242
250
|
end
|
243
251
|
|
@@ -242,25 +242,28 @@ module ReactiveRecord
|
|
242
242
|
promise = Promise.new
|
243
243
|
|
244
244
|
HTTP.post(`window.ReactiveRecordEnginePath`+"/save", payload: {models: models, associations: associations}).then do |response|
|
245
|
-
|
245
|
+
begin
|
246
|
+
response.json[:models] = response.json[:saved_models].collect do |item|
|
247
|
+
backing_records[item[0]].ar_instance
|
248
|
+
end
|
249
|
+
|
246
250
|
if response.json[:success]
|
247
|
-
response.json[:saved_models].each
|
248
|
-
internal_id, klass, attributes = item
|
249
|
-
backing_records[internal_id].sync!(attributes)
|
250
|
-
end
|
251
|
+
response.json[:saved_models].each { | item | backing_records[item[0]].sync!(item[2]) }
|
251
252
|
else
|
252
|
-
|
253
|
+
response.json[:saved_models].each { | item | backing_records[item[0]].saved! item[3] }
|
253
254
|
log("Reactive Record Save Failed: #{response.json[:message]}", :error)
|
254
|
-
response.json[:saved_models].each do |
|
255
|
-
log(" Model: #{
|
255
|
+
response.json[:saved_models].each do | item |
|
256
|
+
log(" Model: #{item[1]}[#{item[0]}] Attributes: #{item[2]} Errors: #{item[3]}", :error) if item[3]
|
256
257
|
end
|
257
258
|
end
|
258
|
-
|
259
|
-
yield response.json[:success], response.json[:message], response.json[:
|
259
|
+
|
260
|
+
yield response.json[:success], response.json[:message], response.json[:models] if block
|
260
261
|
promise.resolve response.json
|
261
262
|
|
262
|
-
backing_records.each { |
|
263
|
-
|
263
|
+
backing_records.each { |id, record| record.saved! } if response.json(:success)
|
264
|
+
rescue Exception => e
|
265
|
+
puts "whahhh #{e}"
|
266
|
+
end
|
264
267
|
end
|
265
268
|
promise
|
266
269
|
else
|
@@ -329,7 +332,7 @@ module ReactiveRecord
|
|
329
332
|
unless model.frozen?
|
330
333
|
saved = model.check_permission_with_acting_user(acting_user, new_models.include?(model) ? :create_permitted? : :update_permitted?).save
|
331
334
|
has_errors ||= !saved
|
332
|
-
[reactive_record_id, model.class.name, model.attributes, (saved ? nil : model.errors.
|
335
|
+
[reactive_record_id, model.class.name, model.attributes, (saved ? nil : model.errors.messages)]
|
333
336
|
end
|
334
337
|
end.compact
|
335
338
|
|
@@ -211,7 +211,11 @@ module ReactiveRecord
|
|
211
211
|
def as_hash(children = [@ar_object])
|
212
212
|
if @parent
|
213
213
|
if method == "*"
|
214
|
-
@
|
214
|
+
if @ar_object.is_a? Array # this happens when a scope is empty there is test case, but
|
215
|
+
@parent.as_hash({}) # does it work for all edge cases?
|
216
|
+
else
|
217
|
+
@parent.as_hash({@ar_object.id => children})
|
218
|
+
end
|
215
219
|
elsif @ar_object.class < ActiveRecord::Base and children.is_a? Hash
|
216
220
|
@parent.as_hash({method => children.merge({
|
217
221
|
:id => [@ar_object.id],
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reactive-record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mitch VanDuyn
|
@@ -155,6 +155,7 @@ files:
|
|
155
155
|
- lib/reactive_record/active_record/associations.rb
|
156
156
|
- lib/reactive_record/active_record/base.rb
|
157
157
|
- lib/reactive_record/active_record/class_methods.rb
|
158
|
+
- lib/reactive_record/active_record/error.rb
|
158
159
|
- lib/reactive_record/active_record/instance_methods.rb
|
159
160
|
- lib/reactive_record/active_record/reactive_record/base.rb
|
160
161
|
- lib/reactive_record/active_record/reactive_record/collection.rb
|