Skip to content

Commit 7faf1f9

Browse files
committed
one more time to fix #173 and duplicate dispatches
1 parent 6eb9163 commit 7faf1f9

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

ruby/hyper-model/lib/reactive_record/active_record/reactive_record/isomorphic_base.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -464,9 +464,9 @@ def self.save_records(models, associations, acting_user, validate, save)
464464
dont_save_list.delete(parent)
465465

466466

467-
if reactive_records[association[:child_id]]&.new_record?
468-
dont_save_list << reactive_records[association[:child_id]]
469-
end
467+
# if reactive_records[association[:child_id]]&.new_record?
468+
# dont_save_list << reactive_records[association[:child_id]]
469+
# end
470470
#if false and parent.new?
471471
#parent.send("#{association[:attribute]}") << reactive_records[association[:child_id]]
472472
# puts "updated"
@@ -478,10 +478,10 @@ def self.save_records(models, associations, acting_user, validate, save)
478478
parent.send("#{association[:attribute]}=", reactive_records[association[:child_id]])
479479
dont_save_list.delete(parent)
480480

481-
if parent.class.reflect_on_association(association[:attribute].to_sym).macro == :has_one &&
482-
reactive_records[association[:child_id]]&.new_record?
483-
dont_save_list << reactive_records[association[:child_id]]
484-
end
481+
# if parent.class.reflect_on_association(association[:attribute].to_sym).macro == :has_one &&
482+
# reactive_records[association[:child_id]]&.new_record?
483+
# dont_save_list << reactive_records[association[:child_id]]
484+
# end
485485
end
486486
end if associations
487487
# get rid of any records that don't require further processing, as a side effect
@@ -493,7 +493,8 @@ def self.save_records(models, associations, acting_user, validate, save)
493493
next true if dont_save_list.include?(record) # skip if the record is on the don't save list
494494
next true if record.changed.include?(record.class.primary_key) # happens on an aggregate
495495
#next true if record.persisted? # record may be have been saved as result of has_one assignment
496-
next record.persisted? if record.id && !record.changed? # throw out any existing records with no changes
496+
# next false if record.id && !record.changed? # throw out any existing records with no changes
497+
next record.persisted? if record.id && !record.changed?
497498
# if we get to here save the record and return true to keep it
498499
op = new_models.include?(record) ? :create_permitted? : :update_permitted?
499500
record.check_permission_with_acting_user(acting_user, op).save(validate: false) || true

ruby/hyper-model/lib/reactive_record/broadcast.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,12 @@ def receive(params)
177177

178178
# once we have received all the data from all the channels (applies to create and update only)
179179
# we yield and process the record
180-
yield complete! if @channels == @received
180+
181+
# pusher fake can send duplicate records which will result in a nil broadcast
182+
# so we also check that before yielding
183+
if @channels == @received && (broadcast = complete!)
184+
yield broadcast
185+
end
181186
end
182187
end
183188

0 commit comments

Comments
 (0)