reactive-record 0.7.8 → 0.7.9

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: 5cf9494b1346a998d25e757a2753208692fde69b
4
- data.tar.gz: 46ab8888020d0076cd9f53fea513519f8eba9910
3
+ metadata.gz: 870be529a755c9588ae0f02b65dd10ee67c8d21b
4
+ data.tar.gz: 561c75ec7f9243d9ae106b733aa5356f57e93829
5
5
  SHA512:
6
- metadata.gz: 0910cbdc2a1a2fb315b0ebcc055d6f6be39ad8091ffb428f72e5898417f81a0a8e14fbaf83c49e39e9d6dc6dafc1c46fd4e6f22495ff9dbd1ab1fa26f642a495
7
- data.tar.gz: 0361491939e7ae8af1a226f4e59db7f6345a16f9237be03b5cda683919b1a0657c338600649d5891a0c3108236e33de29a505e283e8d09e838018c0a41a772f6
6
+ metadata.gz: 5c502888fcd4ef5ea988a3a20a639b4d2bf3b3bdf4df0248b479162772b8ab073d234004697e79b0d121b6eb25209412344401ba1c4b0a0a1ef20cca98aa9f33
7
+ data.tar.gz: 57f3139aeaaab187cd2c30dbae45884a44920a7b6162679e02e573fd99f2074933a7c4b24da87969f9a967fb86d442a04242154c8b2702141ec8f553fe16ed82
@@ -73,6 +73,10 @@ module ActiveRecord
73
73
  @backing_record.destroy &block
74
74
  end
75
75
 
76
+ def new?
77
+ @backing_record.new?
78
+ end
79
+
76
80
  end
77
81
 
78
82
  end
@@ -209,12 +209,11 @@ module ReactiveRecord
209
209
  false
210
210
  end
211
211
 
212
- def sync!(hash = {})
212
+ def sync!(hash = {}) # does NOT notify (see saved! for notification)
213
213
  @attributes.merge! hash
214
214
  @synced_attributes = @attributes.dup
215
215
  @synced_attributes.each { |key, value| @synced_attributes[key] = value.dup_for_sync if value.is_a? Collection }
216
216
  @saving = false
217
- React::State.set_state(self, self, :synced) unless data_loading?
218
217
  self
219
218
  end
220
219
 
@@ -236,10 +235,20 @@ module ReactiveRecord
236
235
  @saving = true
237
236
  end
238
237
 
238
+ def saved!(failed = nil) # sets saving to false AND notifies
239
+ @saving = false
240
+ React::State.set_state(self, self, :saved) unless data_loading? or failed
241
+ self
242
+ end
243
+
239
244
  def saving?
240
245
  React::State.get_state(self, self)
241
246
  @saving
242
247
  end
248
+
249
+ def new?
250
+ !id and !vector
251
+ end
243
252
 
244
253
  def find_association(association, id)
245
254
  inverse_of = association.inverse_of
@@ -265,7 +274,7 @@ module ReactiveRecord
265
274
 
266
275
  def apply_method(method)
267
276
  # Fills in the value returned by sending "method" to the corresponding server side db instance
268
- if id or vector
277
+ if !new?
269
278
  sync_attribute(
270
279
  method,
271
280
  if association = @model.reflect_on_association(method)
@@ -243,16 +243,24 @@ module ReactiveRecord
243
243
 
244
244
  HTTP.post(`window.ReactiveRecordEnginePath`+"/save", payload: {models: models, associations: associations}).then do |response|
245
245
 
246
- response.json[:saved_models].each do |item|
247
- internal_id, klass, attributes = item
248
- backing_records[internal_id].sync!(attributes)
249
- end
250
- log("Reactive Record Save Failed: #{response.json[:message]}", :error) unless response.json[:success]
251
- response.json[:saved_models].each do |model|
252
- log(" Model: #{model[1]} Attributes: #{model[2]} Errors: #{model[3]}", :error) if model[3]
246
+ if response.json[:success]
247
+ response.json[:saved_models].each do |item|
248
+ internal_id, klass, attributes = item
249
+ backing_records[internal_id].sync!(attributes)
250
+ end
251
+ else
252
+ backing_records.each { |item| backing_records[item[0]].saved! false }
253
+ log("Reactive Record Save Failed: #{response.json[:message]}", :error)
254
+ response.json[:saved_models].each do |model|
255
+ log(" Model: #{model[1]} Attributes: #{model[2]} Errors: #{model[3]}", :error) if model[3]
256
+ end
253
257
  end
258
+
254
259
  yield response.json[:success], response.json[:message], response.json[:saved_models] if block
255
260
  promise.resolve response.json
261
+
262
+ backing_records.each { |item| backing_records[item[0]].saved! } if response.json(:success)
263
+
256
264
  end
257
265
  promise
258
266
  else
@@ -1,3 +1,3 @@
1
1
  module ReactiveRecord
2
- VERSION = "0.7.8"
2
+ VERSION = "0.7.9"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reactive-record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.8
4
+ version: 0.7.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mitch VanDuyn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-02 00:00:00.000000000 Z
11
+ date: 2015-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails