isomorfeus-react 16.12.5 → 16.12.6

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
2
  SHA256:
3
- metadata.gz: 02d3da5a8c0ad549bf3a6539a220e5d95479e9a21e99392a1a77b29139cb222d
4
- data.tar.gz: aaa6f2e790085cb9bbd09b029e49d5394bcc7e5d12d27033d4bfdc7646617719
3
+ metadata.gz: 451e8c1b9c5b2271b16c96f0490b41c4657096577c05577153387057a979c959
4
+ data.tar.gz: 6190696c2c735f5eb64ab4aecf8047c3c96b0f512d79979c733d0d2fa3c7cf0d
5
5
  SHA512:
6
- metadata.gz: 6181f6153a988daf46595e245f57c81e460543dc6b9696099870f1122fad7e27c3f973c3848888849dd24abf490720888ea162a062d92437c2031d42721e7a20
7
- data.tar.gz: 2cd1c6f37bb100ef10f0bf51801c25951ca4e0797576b9e5f4db28d3054ace409ec440c2e47368e692026572506e3e40cced5f19cf5293c2e0f8299244de6646
6
+ metadata.gz: ed96b7c2325696283d75678b2ce4eb9f4c6a544b621a216a835e7b92ccf7284e6ec9c26ef7576fecf5f71687d2e1e6eec7ac67aa204437a23b088d1339d1f38c
7
+ data.tar.gz: 53c9ae932a4493352ea0733b7a66d010ad8658e1043d9ce4f4a44e1cd7b371f6b1584413b0abac641685685a365774071f42261dc81e5035250fe85f8c773061
@@ -97,9 +97,10 @@ module Isomorfeus
97
97
  `Opal.global.deepForceUpdate(#{Isomorfeus.top_component})`
98
98
  end
99
99
  end
100
- rescue
100
+ rescue Exception => e
101
101
  # TODO try mount first
102
102
  # if it fails
103
+ `console.error("force_render failed'! Error: " + #{e.message} + "! Reloading page.")`
103
104
  `location.reload()` if on_browser?
104
105
  end
105
106
  nil
@@ -47,6 +47,7 @@ module Isomorfeus
47
47
  rescue Exception => e
48
48
  if !@tried_another_time
49
49
  @tried_another_time = true
50
+ `console.warn("Deferring mount: " + #{e.message})`
50
51
  `setTimeout(Opal.Isomorfeus.TopLevel['$mount!'], 250)`
51
52
  else
52
53
  `console.error("Unable to mount '" + #{component_name} + "'! Error: " + #{e.message} + "!")`
@@ -15,7 +15,6 @@ module LucidApp
15
15
  base.include(::LucidApp::Api)
16
16
  base.include(::LucidComponent::Initializer)
17
17
  base.include(::React::Component::Features)
18
- base.include(::React::Component::Resolution)
19
18
  end
20
19
  end
21
20
  end
@@ -10,6 +10,7 @@ module LucidApp
10
10
  base.lucid_react_component = class extends Opal.global.React.Component {
11
11
  constructor(props) {
12
12
  super(props);
13
+ const oper = Opal.React;
13
14
  if (base.$default_state_defined()) {
14
15
  this.state = base.$state().$to_n();
15
16
  } else {
@@ -39,7 +40,7 @@ module LucidApp
39
40
  for (var ref in defined_refs) {
40
41
  if (defined_refs[ref] != null) {
41
42
  this[ref] = function(element) {
42
- element = Opal.React.native_element_or_component_to_ruby(element);
43
+ element = oper.native_element_or_component_to_ruby(element);
43
44
  #{`this.__ruby_instance`.instance_exec(`element`, &`defined_refs[ref]`)}
44
45
  }
45
46
  this[ref] = this[ref].bind(this);
@@ -47,7 +48,11 @@ module LucidApp
47
48
  this[ref] = Opal.global.React.createRef();
48
49
  }
49
50
  }
50
- if (base.preload_block) { this.state.preloaded = this.__ruby_instance.$execute_preload_block(); }
51
+ if (base.preload_block) {
52
+ oper.active_redux_components.push(this);
53
+ this.state.preloaded = this.__ruby_instance.$execute_preload_block();
54
+ oper.active_redux_components.pop();
55
+ }
51
56
  this.listener = this.listener.bind(this);
52
57
  this.unsubscriber = Opal.Isomorfeus.store.native.subscribe(this.listener);
53
58
  }
@@ -60,7 +65,6 @@ module LucidApp
60
65
  }
61
66
  render() {
62
67
  const oper = Opal.React;
63
- this.context = this.state.isomorfeus_store_state;
64
68
  oper.render_buffer.push([]);
65
69
  // console.log("lucid app pushed", oper.render_buffer, oper.render_buffer.toString());
66
70
  oper.active_components.push(this);
@@ -75,7 +79,7 @@ module LucidApp
75
79
  return Opal.global.React.createElement(Opal.global.LucidApplicationContext.Provider, { value: this.state.isomorfeus_store_state }, oper.render_buffer.pop());
76
80
  }
77
81
  data_access() {
78
- return this.context;
82
+ this.state.isomorfeus_store_state;
79
83
  }
80
84
  listener() {
81
85
  let next_state = Opal.Isomorfeus.store.native.getState();
@@ -67,7 +67,12 @@ module LucidComponent
67
67
  def preload(&block)
68
68
  `base.preload_block = block`
69
69
  component_did_mount do
70
- @_preload_promise.then { self.state.preloaded = true } unless self.state.preloaded
70
+ unless self.state.preloaded
71
+ @_preload_promise.then { self.state.preloaded = true }.fail do |result|
72
+ err_text = "#{self.class.name}: preloading failed, last result: #{result.nil? ? 'nil' : result}!"
73
+ `console.error(err_text)`
74
+ end
75
+ end
71
76
  end
72
77
  end
73
78
 
@@ -14,7 +14,6 @@ module LucidComponent
14
14
  base.include(::LucidComponent::Api)
15
15
  base.include(::LucidComponent::Initializer)
16
16
  base.include(::React::Component::Features)
17
- base.include(::React::Component::Resolution)
18
17
  end
19
18
  end
20
19
  end
@@ -10,6 +10,7 @@ module LucidComponent
10
10
  base.lucid_react_component = class extends Opal.global.React.Component {
11
11
  constructor(props) {
12
12
  super(props);
13
+ const oper = Opal.React;
13
14
  if (base.$default_state_defined()) {
14
15
  this.state = base.$state().$to_n();
15
16
  } else {
@@ -29,7 +30,7 @@ module LucidComponent
29
30
  for (var ref in defined_refs) {
30
31
  if (defined_refs[ref] != null) {
31
32
  this[ref] = function(element) {
32
- element = Opal.React.native_element_or_component_to_ruby(element);
33
+ element = oper.native_element_or_component_to_ruby(element);
33
34
  #{`this.__ruby_instance`.instance_exec(`element`, &`defined_refs[ref]`)}
34
35
  }
35
36
  this[ref] = this[ref].bind(this);
@@ -37,7 +38,11 @@ module LucidComponent
37
38
  this[ref] = Opal.global.React.createRef();
38
39
  }
39
40
  }
40
- if (base.preload_block) { this.state.preloaded = this.__ruby_instance.$execute_preload_block(); }
41
+ if (base.preload_block) {
42
+ oper.active_redux_components.push(this);
43
+ this.state.preloaded = this.__ruby_instance.$execute_preload_block();
44
+ oper.active_redux_components.pop();
45
+ }
41
46
  }
42
47
  static get displayName() {
43
48
  return #{component_name};
@@ -5,7 +5,6 @@ module LucidFunc
5
5
  base.include(::React::Component::Features)
6
6
  base.include(::LucidFunc::Initializer)
7
7
  base.include(::React::FunctionComponent::Api)
8
- base.include(::React::FunctionComponent::Resolution)
9
8
  base.extend(::React::FunctionComponent::EventHandler)
10
9
  base.extend(::LucidComponent::EnvironmentSupport)
11
10
  base.include(::LucidComponent::EnvironmentSupport)
@@ -6,7 +6,6 @@ module React
6
6
  base.include(::React::Component::Features)
7
7
  base.include(::React::FunctionComponent::Initializer)
8
8
  base.include(::React::FunctionComponent::Api)
9
- base.include(::React::FunctionComponent::Resolution)
10
9
  base.extend(::React::FunctionComponent::EventHandler)
11
10
  base.extend(::React::FunctionComponent::NativeComponentConstructor)
12
11
  end
@@ -6,7 +6,6 @@ module React
6
6
  base.include(::React::Component::Features)
7
7
  base.include(::React::FunctionComponent::Initializer)
8
8
  base.include(::React::FunctionComponent::Api)
9
- base.include(::React::FunctionComponent::Resolution)
10
9
  base.extend(::React::FunctionComponent::EventHandler)
11
10
  base.extend(::React::MemoComponent::NativeComponentConstructor)
12
11
  end
@@ -16,7 +16,6 @@ module LucidMaterial
16
16
  base.include(::LucidApp::Api)
17
17
  base.include(::LucidComponent::Initializer)
18
18
  base.include(::React::Component::Features)
19
- base.include(::React::Component::Resolution)
20
19
  end
21
20
  end
22
21
  end
@@ -15,7 +15,6 @@ module LucidMaterial
15
15
  base.include(::LucidComponent::Api)
16
16
  base.include(::LucidComponent::Initializer)
17
17
  base.include(::React::Component::Features)
18
- base.include(::React::Component::Resolution)
19
18
  end
20
19
  end
21
20
  end
@@ -6,7 +6,6 @@ module LucidMaterial
6
6
  base.include(::React::Component::Features)
7
7
  base.include(::LucidFunc::Initializer)
8
8
  base.include(::React::FunctionComponent::Api)
9
- base.include(::React::FunctionComponent::Resolution)
10
9
  base.extend(::React::FunctionComponent::EventHandler)
11
10
  base.extend(::LucidComponent::EnvironmentSupport)
12
11
  base.include(::LucidComponent::EnvironmentSupport)
@@ -67,6 +67,16 @@ module React
67
67
  end
68
68
  end
69
69
 
70
+ def component_fun(class_name, **ruby_props)
71
+ %x{
72
+ return function(props) {
73
+ let outer_props = Opal.React.to_native_react_props(#{ruby_props});
74
+ let new_props = Object.assign({}, props, outer_props);
75
+ return Opal.global.React.createElement(#{class_name.constantize}.react_component, new_props)
76
+ }
77
+ }
78
+ end
79
+
70
80
  def get_react_element(arg, &block)
71
81
  if block_given?
72
82
  # execute block, fetch last element from buffer
@@ -3,33 +3,62 @@ module React
3
3
  class History
4
4
  include ::Native::Wrapper
5
5
 
6
- alias_native :block, :block
7
- alias_native :create_href, :createHref
8
- alias_native :go, :go
9
- alias_native :go_back, :goBack
10
- alias_native :go_forward, :goForward
11
- alias_native :listen, :listen
12
- alias_native :push, :push
13
- alias_native :replace, :replace
6
+ def block(prompt)
7
+ @native.JS[:props].JS[:history].JS.block(prompt)
8
+ end
9
+
10
+ def create_href(location)
11
+ @native.JS[:props].JS[:history].JS.createHref(location)
12
+ end
13
+
14
+ def go(n)
15
+ @native.JS[:props].JS[:history].JS.go(n)
16
+ end
17
+
18
+ def go_back
19
+ @native.JS[:props].JS[:history].JS.goBack()
20
+ end
14
21
 
15
- alias _react_component_hitory_original_method_missing method_missing
22
+ def go_forward
23
+ @native.JS[:props].JS[:history].JS.goForward()
24
+ end
25
+
26
+ def push(*args)
27
+ @native.JS[:props].JS[:history].JS.push(*args)
28
+ end
29
+
30
+ def replace(*args)
31
+ @native.JS[:props].JS[:history].JS.replace(*args)
32
+ end
16
33
 
17
34
  def method_missing(prop, *args, &block)
18
- @native.JS[:params].JS[prop]
35
+ @native.JS[:props].JS[:history].JS[prop]
36
+ end
37
+
38
+ def listen(&block)
39
+ fun = nil
40
+ %x{
41
+ fun = function(location, action) {
42
+ let ruby_location = #{React::Component::Location.new(`{ props: { location: location }}`)}
43
+ block.$call(ruby_location, action);
44
+ }
45
+ }
46
+ unlisten = @native.JS[:props].JS[:history].JS.listen(fun)
47
+ -> { unlisten.JS.call() }
19
48
  end
20
49
 
21
50
  def location
22
51
  return @location if @location
23
- return nil unless @native.JS[:props].JS[:location]
24
- if @native.JS[:props].JS[:location].JS[:pathname]
25
- @location = React::Component::Location.new(@native.JS[:props].JS[:location])
52
+ return nil unless @native.JS[:props].JS[:history].JS[:location]
53
+ if @native.JS[:props].JS[:history].JS[:location].JS[:pathname]
54
+ @location = React::Component::Location.new(@native)
26
55
  else
27
- @native.JS[:props].JS[:location]
56
+ @native.JS[:props].JS[:history].JS[:location]
28
57
  end
29
58
  end
30
59
 
31
60
  def to_n
32
- @native
61
+ @native.JS[:props].JS[:history]
33
62
  end
34
63
  end
35
64
  end
@@ -4,7 +4,7 @@ module React
4
4
  include ::Native::Wrapper
5
5
 
6
6
  def method_missing(prop, *args, &block)
7
- @native.JS[:params].JS[prop]
7
+ @native.JS[:props].JS[:location].JS[prop]
8
8
  end
9
9
 
10
10
  def to_n
@@ -12,4 +12,4 @@ module React
12
12
  end
13
13
  end
14
14
  end
15
- end
15
+ end
@@ -4,11 +4,11 @@ module React
4
4
  include ::Native::Wrapper
5
5
 
6
6
  def method_missing(prop, *args, &block)
7
- @native.JS[:params].JS[prop]
7
+ @native.JS[:props].JS[:match].JS[:params].JS[prop]
8
8
  end
9
9
 
10
10
  def is_exact
11
- @native.JS[:isExact]
11
+ @native.JS[:props].JS[:match].JS[:isExact]
12
12
  end
13
13
 
14
14
  def params
@@ -16,16 +16,16 @@ module React
16
16
  end
17
17
 
18
18
  def path
19
- @native.JS[:path]
19
+ @native.JS[:props].JS[:match].JS[:path]
20
20
  end
21
21
 
22
22
  def url
23
- @native.JS[:url]
23
+ @native.JS[:props].JS[:match].JS[:url]
24
24
  end
25
25
 
26
26
  def to_n
27
- @native
27
+ @native.JS[:props].JS[:match]
28
28
  end
29
29
  end
30
30
  end
31
- end
31
+ end
@@ -11,7 +11,6 @@ module React
11
11
  base.include(::React::Component::Callbacks)
12
12
  base.include(::React::Component::Initializer)
13
13
  base.include(::React::Component::Features)
14
- base.include(::React::Component::Resolution)
15
14
  end
16
15
  end
17
16
  end
@@ -16,11 +16,11 @@ module React
16
16
  end
17
17
 
18
18
  def classes
19
- @classes ||= `Opal.React.Component.Styles.$new(#@native, 'classes')`
19
+ @classes ||= React::Component::Styles.new(@native, 'classes')
20
20
  end
21
21
 
22
22
  def theme
23
- @theme ||= `Opal.React.Component.Styles.$new(#@native, 'theme')`
23
+ @theme ||= React::Component::Styles.new(@native, 'theme')
24
24
  end
25
25
 
26
26
  def isomorfeus_store
@@ -29,27 +29,30 @@ module React
29
29
 
30
30
  # for router convenience
31
31
  def history
32
+ return @history if @history
32
33
  return nil if `typeof #@native.props.history === 'undefined'`
33
- if `typeof #@native.props.history.pathname !== 'undefined'`
34
- React::Component::History.new(@native.JS[:props].JS[:history])
34
+ if `typeof #@native.props.history.action !== 'undefined'`
35
+ @history = React::Component::History.new(@native)
35
36
  else
36
37
  @native.JS[:props].JS[:history]
37
38
  end
38
39
  end
39
40
 
40
41
  def location
42
+ return @location if @location
41
43
  return nil if `typeof #@native.props.location === 'undefined'`
42
44
  if `typeof #@native.props.location.pathname !== 'undefined'`
43
- React::Component::Location.new(@native.JS[:props].JS[:location])
45
+ @location = React::Component::Location.new(@native)
44
46
  else
45
47
  @native.JS[:props].JS[:location]
46
48
  end
47
49
  end
48
50
 
49
51
  def match
52
+ return @match if @match
50
53
  return nil if `typeof #@native.props.match === 'undefined'`
51
54
  if `typeof #@native.props.match.path !== 'undefined'`
52
- React::Component::Match.new(@native.JS[:props].JS[:match])
55
+ @match = React::Component::Match.new(@native)
53
56
  else
54
57
  @native.JS[:props].JS[:match]
55
58
  end
@@ -8,7 +8,7 @@ module React
8
8
  def const_missing(const_name)
9
9
  # language=JS
10
10
  %x{
11
- if (typeof Opal.global[const_name] === "object") {
11
+ if (typeof Opal.global[const_name] !== "undefined" && (const_name[0] === const_name[0].toUpperCase())) {
12
12
  var new_const = #{React::NativeConstantWrapper.new(`Opal.global[const_name]`, const_name)};
13
13
  #{Object.const_set(const_name, `new_const`)};
14
14
  return new_const;
@@ -20,7 +20,10 @@ module React
20
20
 
21
21
  # this is required for autoloading support, as the component may not be loaded and so its method is not registered.
22
22
  # must load it first, done by const_get, and next time the method will be there.
23
- alias _react_component_class_resolution_original_method_missing method_missing
23
+
24
+ unless method_defined?(:_react_component_class_resolution_original_method_missing)
25
+ alias _react_component_class_resolution_original_method_missing method_missing
26
+ end
24
27
 
25
28
  def method_missing(component_name, *args, &block)
26
29
  # check for ruby component and render it
@@ -60,8 +63,9 @@ module React
60
63
  end
61
64
  end
62
65
 
63
-
64
- alias _react_component_resolution_original_method_missing method_missing
66
+ unless method_defined?(:_react_component_resolution_original_method_missing)
67
+ alias _react_component_resolution_original_method_missing method_missing
68
+ end
65
69
 
66
70
  def method_missing(component_name, *args, &block)
67
71
  # html tags are defined as methods, so they will not end up here.
@@ -71,8 +75,7 @@ module React
71
75
  # language=JS
72
76
  %x{
73
77
  var component = null;
74
- var component_type = typeof Opal.global[component_name];
75
- if (component_type === "function" || component_type === "object") {
78
+ if (typeof Opal.global[component_name] !== "undefined" && (component_name[0] === component_name[0].toUpperCase())) {
76
79
  component = Opal.global[component_name];
77
80
  } else {
78
81
  var modules = self.$to_s().split("::");
@@ -1,3 +1,3 @@
1
1
  module React
2
- VERSION = '16.12.5'
2
+ VERSION = '16.12.6'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isomorfeus-react
3
3
  version: !ruby/object:Gem::Version
4
- version: 16.12.5
4
+ version: 16.12.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Biedermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-21 00:00:00.000000000 Z
11
+ date: 2019-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.0.4
75
+ version: 0.1.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 0.0.4
82
+ version: 0.1.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: opal-webpack-loader
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -231,7 +231,6 @@ files:
231
231
  - lib/isomorfeus_react/react/function_component/initializer.rb
232
232
  - lib/isomorfeus_react/react/function_component/mixin.rb
233
233
  - lib/isomorfeus_react/react/function_component/native_component_constructor.rb
234
- - lib/isomorfeus_react/react/function_component/resolution.rb
235
234
  - lib/isomorfeus_react/react/memo_component/base.rb
236
235
  - lib/isomorfeus_react/react/memo_component/mixin.rb
237
236
  - lib/isomorfeus_react/react/memo_component/native_component_constructor.rb
@@ -1,62 +0,0 @@
1
- module React
2
- module FunctionComponent
3
- module Resolution
4
- def self.included(base)
5
- base.instance_exec do
6
- alias _react_function_component_resolution_original_const_missing const_missing
7
-
8
- def const_missing(const_name)
9
- # language=JS
10
- %x{
11
- if (typeof Opal.global[const_name] === "object") {
12
- var new_const = #{React::NativeConstantWrapper.new(`Opal.global[const_name]`, const_name)};
13
- #{Object.const_set(const_name, `new_const`)};
14
- return new_const;
15
- } else {
16
- return #{_react_function_component_resolution_original_const_missing(const_name)};
17
- }
18
- }
19
- end
20
- end
21
- end
22
-
23
- alias _react_function_component_resolution_original_method_missing method_missing
24
-
25
- def method_missing(component_name, *args, &block)
26
- # html tags are defined as methods, so they will not end up here.
27
- # first check for native component and render it, we want to be fast for native components
28
- # second check for ruby component and render it, they are a bit slower anyway
29
- # third pass on method missing
30
- # language=JS
31
- %x{
32
- var component = null;
33
- var component_type = typeof Opal.global[component_name];
34
- if (component_type === "function" || component_type === "object") {
35
- component = Opal.global[component_name];
36
- }
37
- else {
38
- try {
39
- var constant = self.$class().$const_get(component_name, true);
40
- if (typeof constant.react_component !== 'undefined') {
41
- component = constant.react_component;
42
- }
43
- } catch(err) { component = null; }
44
- }
45
- if (!component) {
46
- try {
47
- constant = Opal.Object.$const_get(component_name);
48
- if (typeof constant.react_component !== 'undefined') {
49
- component = constant.react_component;
50
- }
51
- } catch(err) { component = null; }
52
- }
53
- if (component) {
54
- return Opal.React.internal_prepare_args_and_render(component, args, block);
55
- } else {
56
- return #{_react_function_component_resolution_original_method_missing(component_name, *args, block)};
57
- }
58
- }
59
- end
60
- end
61
- end
62
- end