Skip to content

Commit c5f4dc9

Browse files
committed
hot loader fixes
1 parent f315c6e commit c5f4dc9

File tree

4 files changed

+17
-84
lines changed

4 files changed

+17
-84
lines changed

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

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,6 @@ def [](index)
7777
(@collection.length..index).each do |i|
7878
new_dummy_record = ReactiveRecord::Base.new_from_vector(@target_klass, nil, *@vector, "*#{i}")
7979
new_dummy_record.attributes[@association.inverse_of] = @owner if @association && !@association.through_association?
80-
<<<<<<< Updated upstream
81-
=======
82-
# HMT-TODO: the above needs to be looked into... if we are a hmt then don't we need to create a dummy on the joins collection as well?
83-
# or maybe this just does not work for HMT?
84-
>>>>>>> Stashed changes
8580
@collection << new_dummy_record
8681
end
8782
end
@@ -217,11 +212,7 @@ def related_records_for(record)
217212
return [] unless attrs[@association.inverse_of] == @owner
218213
if !@association.through_association
219214
[record]
220-
<<<<<<< Updated upstream
221215
elsif (source = attrs[@association.source])
222-
=======
223-
elsif (source = attrs[@association.source]) && source.is_a?(@target_klass)
224-
>>>>>>> Stashed changes
225216
[source]
226217
else
227218
[]
@@ -242,12 +233,7 @@ def live_scopes
242233
end
243234

244235
def in_this_collection(related_records)
245-
<<<<<<< Updated upstream
246236
return related_records unless @association
247-
=======
248-
# HMT-TODO: I don't think we can get a set of related records here with a through association unless they are part of the collection
249-
return related_records if !@association || @association.through_association?
250-
>>>>>>> Stashed changes
251237
related_records.select do |r|
252238
r.backing_record.attributes[@association.inverse_of] == @owner
253239
end
@@ -420,15 +406,7 @@ def push_and_update_belongs_to(id)
420406
def set_belongs_to(child)
421407
if @owner
422408
# TODO this is major broken...current
423-
<<<<<<< Updated upstream
424409
child.send("#{@association.inverse_of}=", @owner) if @association && !@association.through_association
425-
=======
426-
if (through_association = @association.through_association)
427-
# HMT-TODO: create a new record with owner and child
428-
else
429-
child.send("#{@association.inverse_of}=", @owner) if @association && !@association.through_association
430-
end
431-
>>>>>>> Stashed changes
432410
elsif @parent
433411
@parent.set_belongs_to(child)
434412
end
@@ -443,7 +421,6 @@ def set_belongs_to(child)
443421

444422
def update_child(item)
445423
backing_record = item.backing_record
446-
<<<<<<< Updated upstream
447424
if backing_record && @owner && @association && !@association.through_association? && item.attributes[@association.inverse_of] != @owner
448425
inverse_of = @association.inverse_of
449426
current_association = item.attributes[inverse_of]
@@ -452,44 +429,11 @@ def update_child(item)
452429
if current_association && current_association.attributes[@association.attribute]
453430
current_association.attributes[@association.attribute].delete(item)
454431
end
455-
=======
456-
# HMT TODO: The following && !association.through_association was commented out, causing wrong class items to be added to
457-
# associations
458-
# Why was it commented out.
459-
if backing_record && @owner && @association && item.attributes[@association.inverse_of] != @owner && !@association.through_association?
460-
inverse_of = @association.inverse_of
461-
current_association_value = item.attributes[inverse_of]
462-
backing_record.virgin = false unless backing_record.data_loading?
463-
#backing_record.update_belongs_to(inverse_of, @owner)
464-
backing_record.set_belongs_to_via_has_many(@association, @owner)
465-
# following is handled by update_belongs_to and is redundant
466-
# unless current_association_value.nil? # might be a dummy value which responds to nil
467-
# current_association = @association.inverse.inverse(current_association_value)
468-
# current_association_attribute = current_association.attribute
469-
# if current_association.collection? && current_association_value.attributes[current_association_attribute]
470-
# current_association.attributes[current_association_attribute].delete(item)
471-
# end
472-
# end
473-
>>>>>>> Stashed changes
474432
@owner.backing_record.sync_has_many(@association.attribute)
475433
end
476434
end
477435

478436
def push(item)
479-
<<<<<<< Updated upstream
480-
=======
481-
if (through_association = @association&.through_association)
482-
through_association.klass.create(@association.inverse_of => @owner, @association.source => item)
483-
self
484-
else
485-
_internal_push(item)
486-
end
487-
end
488-
489-
alias << push
490-
491-
def _internal_push(item)
492-
>>>>>>> Stashed changes
493437
item.itself # force get of at least the id
494438
if collection
495439
self.force_push item
@@ -505,11 +449,8 @@ def _internal_push(item)
505449
self
506450
end
507451

508-
<<<<<<< Updated upstream
509452
alias << push
510453

511-
=======
512-
>>>>>>> Stashed changes
513454
def sort!(*args, &block)
514455
replace(sort(*args, &block))
515456
end
@@ -582,33 +523,20 @@ def internal_replace(new_array)
582523
if new_array.is_a? Collection
583524
@dummy_collection = new_array.dummy_collection
584525
@dummy_record = new_array.dummy_record
585-
<<<<<<< Updated upstream
586526
new_array.collection.each { |item| self << item } if new_array.collection
587527
else
588528
@dummy_collection = @dummy_record = nil
589529
new_array.each { |item| self << item }
590-
=======
591-
new_array.collection.each { |item| _internal_push item } if new_array.collection
592-
else
593-
@dummy_collection = @dummy_record = nil
594-
new_array.each { |item| _internal_push item }
595-
>>>>>>> Stashed changes
596530
end
597531
notify_of_change new_array
598532
end
599533

600534
def delete(item)
601535
unsaved_children.delete(item)
602536
notify_of_change(
603-
<<<<<<< Updated upstream
604537
if @owner && @association && !@association.through_association?
605538
inverse_of = @association.inverse_of
606539
if (backing_record = item.backing_record) && item.attributes[inverse_of] == @owner
607-
=======
608-
if @owner && @association
609-
inverse_of = @association.inverse_of
610-
if (backing_record = item.backing_record) && item.attributes[inverse_of] == @owner && !@association.through_association?
611-
>>>>>>> Stashed changes
612540
# the if prevents double update if delete is being called from << (see << above)
613541
backing_record.update_belongs_to(inverse_of, nil)
614542
end
@@ -634,11 +562,6 @@ def loading?
634562
@dummy_collection.loading?
635563
end
636564

637-
<<<<<<< Updated upstream
638-
def loaded?
639-
false && @collection && (!@dummy_collection || !@dummy_collection.loading?) && (!@owner || @owner.id || @vector.length > 1)
640-
end
641-
=======
642565
# def loading?
643566
# !@collection || (@dummy_collection && @dummy_collection.loading?) || (@owner && [email protected] && @vector && @vector.length <= 1)
644567
# end
@@ -647,7 +570,6 @@ def loaded?
647570
# @collection && (!@dummy_collection || !@dummy_collection.loading?) && (!@owner || @owner.id || !@vector || @vector.length > 1)
648571
# #false && @collection && (!@dummy_collection || !@dummy_collection.loading?) && (!@owner || @owner.id || @vector.length > 1)
649572
# end
650-
>>>>>>> Stashed changes
651573

652574
def empty?
653575
# should be handled by method missing below, but opal-rspec does not deal well

ruby/hyperstack-config/lib/hyperstack-config.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def self.naming_convention
3838
require 'hyperstack/on_error'
3939
Hyperstack.define_setting :hotloader_port, 25222
4040
Hyperstack.define_setting :hotloader_ping, nil
41+
Hyperstack.define_setting :hotloader_ignore_callback_mapping, false
4142
Hyperstack.import 'opal', gem: true
4243
Hyperstack.import 'browser', client_only: true
4344
Hyperstack.import 'hyperstack-config', gem: true
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
console.log('hotloader config doing its thing')
21
if ((typeof(window) !== 'undefined') && (window.Hyperstack==undefined || window.Hyperstack.hotloader==undefined)) {
32
window.Hyperstack = { hotloader: function(port, ping) { }}
43
}
54
//if (typeof(Hyperstack) === 'undefined') { Hyperstack = {} }
65
Hyperstack.hotloader.port = <%= Hyperstack.hotloader_port %>
76
Hyperstack.hotloader.ping = <%= !!Hyperstack.hotloader_ping %>
7+
Hyperstack.hotloader.ignore_callback_mapping = <%= !(!Hyperstack.hotloader_ignore_callback_mapping && Rails.configuration.assets.debug) %>

ruby/hyperstack-config/lib/hyperstack/hotloader.rb

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,29 @@ def self.callbacks
1919
@@callbacks ||= Hash.new { |h, k| h[k] = Array.new }
2020
end
2121

22-
STACKDIRS = ['hyperstack/', 'corelib/']
22+
STACKDIRS = ['hyperstack', 'corelib']
2323

2424
def self.file_name(frame)
25+
return unless frame
2526
file_name = `#{frame}.fileName`
26-
match = %r{^(.+\/assets\/)(.+\/)(.+\/)}.match(file_name)
27-
return unless match && match[2] == match[3] && !STACKDIRS.include?(match[2])
28-
file_name.gsub(match[1] + match[2], '')
27+
match = %r{^(.+\/assets)\/}.match(file_name)
28+
return unless match
29+
file_name = file_name.gsub(match[0], '').split('/')
30+
n = (file_name.length - 1) / 2
31+
return unless file_name[0..n - 1] == file_name[n..2 * n - 1]
32+
return if STACKDIRS.include?(file_name[0])
33+
"#{match[0]}#{file_name[0..n - 1].join('/')}/#{file_name[-1]}"
2934
end
3035

3136
def self.when_file_updates(&block)
37+
return if `Hyperstack.hotloader.ignore_callback_mapping`
3238
return callbacks[$_hyperstack_reloader_file_name] << block if $_hyperstack_reloader_file_name
3339
callback = lambda do |frames|
34-
frames.collect(&method(:file_name)).each { |name| callbacks[name] << block if name }
40+
# StackTrace.get maps the stack frames back to the source maps
41+
# we then associate any files in the call stack that match our application file pattern
42+
# with the block, which will remove any callbacks defined when those files were executing.
43+
# Note that StackTrace.getSync gives us the raw .js file names so it will not work
44+
frames.collect(&method(:file_name)).compact.uniq.each { |name| callbacks[name] << block if name }
3545
end
3646
error = lambda do |e|
3747
`console.error(#{"hyperstack hot loader could not find source file for callback: #{e}"})`

0 commit comments

Comments
 (0)