opal_hot_reloader 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e792c243fe2539e1fcfbb417073237b3cf5cc0b4
4
- data.tar.gz: 7e0b1b2057dac2d743cf89156d1f73216048f96c
2
+ SHA256:
3
+ metadata.gz: '09bbe977d7b5a66683d1fe4d39faa2cb3a3c53b29891a9a608ddb03a347a216a'
4
+ data.tar.gz: 2bed6bbdc69e7f298334766e2fe6ebc5419c7f77dec283d86e6096564a118414
5
5
  SHA512:
6
- metadata.gz: a1a81423ad3b3f0b0bc45f0a9ee040f198fcae8014837cb8c2c10cffbb164845a1edab3294e24cd68c5a6af724783297da73560e5464cf8e37c5ecd475f37501
7
- data.tar.gz: 1b5509579c380e9ed8c9294085ceaffc9e5f59e0b1f759cebf5642cd88062e833fdedaf31b19f352e27b7b5399d08e70b1c6aabfedf6d231e351943469dfedfd
6
+ metadata.gz: 80fe8d1702a510883747e678b2f31dc2dc366efd847c87e11565c8e41673c7468c8be3801d64677f51ced211bab66ddc4523df678c131c8c274efc69b1d3113b
7
+ data.tar.gz: 1ea4ef4082ede515e1be657e5dd0220abb91c247113caa812b0450debfc4876b9e8ed52e3543cd5f9bb65983a4ac176f5427a6e3c8936bf9d3970b4f24463206
@@ -1,3 +1,6 @@
1
+ * 0.1.7
2
+ - update to be compatible with latest hyperloop
3
+ - made compatible w/react error boundaries
1
4
  * 0.1.6
2
5
  - hyperloop ping tweaks
3
6
  - UTF8 encoding
@@ -1,3 +1,3 @@
1
1
  module OpalHotReloader
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
@@ -1,5 +1,6 @@
1
1
  # patches to support reloading react.rb
2
2
  module ReactrbPatchModules
3
+ # add global force_update! method
3
4
  module ReactComponent
4
5
  def add_to_global_component_list(instance)
5
6
  (@global_component_list ||= Set.new).add instance
@@ -10,22 +11,72 @@ module ReactrbPatchModules
10
11
  end
11
12
 
12
13
  def force_update!
13
- @global_component_list && @global_component_list.each(&:force_update!)
14
+ # components may be unmounted as a result of doing force_updates
15
+ # so copy the list, and then check before updating each component
16
+ return unless @global_component_list
17
+ components = @global_component_list.to_a
18
+ components.each do |comp|
19
+ next unless @global_component_list.include? comp
20
+ comp.force_update!
21
+ end
22
+ end
23
+ end
24
+
25
+ module AddForceUpdate
26
+ # latest hyperloop already has a force_update! method, but legacy hot
27
+ # reloader expects it to be defined in React::Component.
28
+ # Once older versions of Hyperloop are deprecated this can be removed.
29
+ def force_update!
30
+ Hyperloop::Component.force_update!
31
+ end
32
+ end
33
+ module AddErrBoundry
34
+ def self.included(base)
35
+ base.after_error do |*err|
36
+ @err = err
37
+ Hyperloop::Component.force_update!
38
+ end
39
+ base.define_method :render do
40
+ @err ? parse_display_and_clear_error : top_level_render
41
+ end
42
+ end
43
+
44
+ def parse_display_and_clear_error
45
+ e = @err[0]
46
+ component_stack = @err[1]['componentStack'].split("\n ")
47
+ @err = nil
48
+ display_error(e, component_stack)
49
+ end
50
+
51
+ def display_error(e, component_stack)
52
+ DIV do
53
+ DIV { "Uncaught error: #{e}" }
54
+ component_stack.each do |line|
55
+ DIV { line }
56
+ end
57
+ end
14
58
  end
15
59
  end
16
60
  end
17
61
 
62
+ # React.rb needs to be patched so the we don't keep adding callbacks
18
63
  class ReactrbPatches
19
- # React.rb needs to be patched so the we don't keep adding callbacks
20
64
  def self.patch!
21
- ::React::Component.extend ReactrbPatchModules::ReactComponent # works
22
-
23
- ::React::Callbacks.alias_method :original_run_callback, :run_callback # works
24
- # Easiest place to hook into all components lifecycles
25
- ::React::Callbacks.define_method(:run_callback) do |name, *args| # works
26
- React::Component.add_to_global_component_list self if name == :before_mount
27
- original_run_callback name, *args
28
- React::Component.remove_from_global_component_list self if name == :before_unmount
65
+ if defined?(::React::TopLevelRailsComponent) && ::React::TopLevelRailsComponent.respond_to?(:after_error)
66
+ # new style: Just add the error handler to the top level component
67
+ ::React::TopLevelRailsComponent.include ReactrbPatchModules::AddErrBoundry
68
+ # for compatibility with current opal-hot-reloader AddForceUpdate renames force_update!
69
+ ::React::Component.extend ReactrbPatchModules::AddForceUpdate
70
+ else
71
+ # old style (pre lap28 / 0.99 legacy release)
72
+ ::React::Component.extend ReactrbPatchModules::ReactComponent # works
73
+ ::React::Callbacks.alias_method :original_run_callback, :run_callback # works
74
+ # Easiest place to hook into all components lifecycles
75
+ ::React::Callbacks.define_method(:run_callback) do |name, *args| # works
76
+ React::Component.add_to_global_component_list self if name == :before_mount
77
+ original_run_callback name, *args
78
+ React::Component.remove_from_global_component_list self if name == :before_unmount
79
+ end
29
80
  end
30
81
  end
31
82
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal_hot_reloader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Forrest Chang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-07 00:00:00.000000000 Z
11
+ date: 2018-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -147,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
147
  version: '0'
148
148
  requirements: []
149
149
  rubyforge_project:
150
- rubygems_version: 2.5.1
150
+ rubygems_version: 2.7.7
151
151
  signing_key:
152
152
  specification_version: 4
153
153
  summary: Opal Hot reloader