isomorfeus-react 16.5.1 → 16.6.1

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: cba3a632d5700b2370b2dc673eabc01aebac34c508680f79b01154ce856e5051
4
- data.tar.gz: 4025af5f4037e829aacf72c91316b0da9b312209e92e242a8d8a127d58f1d109
3
+ metadata.gz: 4f5cb95862ec002593c0fa138708e7b836e5bde4cc5d98417fd9d1dc60822f3d
4
+ data.tar.gz: c675459414c7682373017e52d6d4eb4588d517f6280d8af39aa4f9e2bed73ad6
5
5
  SHA512:
6
- metadata.gz: 8b178809f4a89d23283c1b0ccfa85f8df7e720388bf5516f70aa5083e38a7e88777992cfe7c92a53de74f0aa0cb78147ead4e8af11a6d58851c266b09fe862a8
7
- data.tar.gz: a3da4df7f53d9f86b423750e5166ea214a359290c268d8e800f8254be688843732ce26d29c585dbd8f86f0b7d5580e06bf6afa2b721760024f712b95ccf9c612
6
+ metadata.gz: 02e9510d524a96550b74fba5d48b19d2d59d0c82f7c585dd6b95359422da967240d58b5f833b36526a41309ee59f16a8e8018cc168e52b2fa8396ea25f4ae240
7
+ data.tar.gz: 72dd5a6d9f1adc6943f25d406125695c3ca7ad3414e5ab61b90714ececff2ca227b828e16dc790dbcb3004508ba181153e132179de0b459045fcfb4f8f20cef6
data/README.md CHANGED
@@ -4,12 +4,12 @@ Develop React components for Opal Ruby along with very easy to use and advanced
4
4
 
5
5
  ## Versioning
6
6
  isomorfeus-react version follows the React version which features and API it implements.
7
- Isomorfeus-react 16.5.x implements features and the API of React 16.5 and should be used with React 16.5
7
+ Isomorfeus-react 16.5.x implements features and the API of React 16.6 and should be used with React 16.6
8
8
 
9
9
  ## Installation
10
10
  To install React with the matching version:
11
11
  ```
12
- yarn add react@16.5
12
+ yarn add react@16.6
13
13
  ```
14
14
  then add to the Gemfile:
15
15
  ```ruby
@@ -116,7 +116,8 @@ Its recommended to use them only if no props or state are used or if props and s
116
116
  ![React::PureComponent Data Flow](https://raw.githubusercontent.com/isomorfeus/isomorfeus-react/master/images/data_flow_component.png)
117
117
 
118
118
  ### Function Components
119
- Function Components are created using a Ruby DSL that is used within the creator class:
119
+ Function Components are created using a Ruby DSL that is used within the creator class. To create a function component that renders only
120
+ when props change, use the memo_component, which uses React.memo:
120
121
  ```ruby
121
122
  class React::FunctionComponent::Creator
122
123
  function_component 'MyComponent' do |props|
@@ -126,6 +127,10 @@ class React::FunctionComponent::Creator
126
127
  function_component 'MyObject.MyComponent' do |props|
127
128
  SPAN { props.text }
128
129
  end
130
+ # a React.memo function component:
131
+ memo_component 'MyObject.MyComponent' do |props|
132
+ SPAN { props.text }
133
+ end
129
134
  end
130
135
  ```
131
136
  This creates a native javascript components.
@@ -17,6 +17,10 @@ module LucidApp
17
17
  }
18
18
  end
19
19
  end
20
+
21
+ def context
22
+ @native.JS[:context]
23
+ end
20
24
  end
21
25
  end
22
26
  end
@@ -125,6 +125,7 @@ module LucidComponent
125
125
  return null;
126
126
  }
127
127
  }
128
+ base.lucid_react_component.contextType = Opal.global.LucidApplicationContext;
128
129
  }
129
130
  end
130
131
  end
@@ -144,4 +144,12 @@ module React
144
144
  def self.isValidElement(react_element)
145
145
  `React.isValidElement(react_element)`
146
146
  end
147
+
148
+ def self.lazy(import_statement_function)
149
+ `React.lazy(import_statement_function)`
150
+ end
151
+
152
+ def self.memo(function_component)
153
+ `React.memo(function_component)`
154
+ end
147
155
  end
@@ -42,6 +42,17 @@ module React
42
42
  Opal.React.internal_render(React.StrictMode, native_props, block);
43
43
  }
44
44
  end
45
+
46
+ def Suspense(props = `null`, &block)
47
+ %x{
48
+ var native_props = null;
49
+
50
+ if (props) {
51
+ native_props = Opal.React.to_native_react_props(args[0]);
52
+ }
53
+ Opal.React.internal_render(React.Suspense, native_props, block);
54
+ }
55
+ end
45
56
  end
46
57
  end
47
58
  end
@@ -11,7 +11,6 @@ module React
11
11
  end
12
12
 
13
13
  def self.function_component(component_name, &block)
14
-
15
14
  %x{
16
15
  var fun = function(props) {
17
16
  Opal.React.render_buffer.push([]);
@@ -42,6 +41,38 @@ module React
42
41
  }, Opal.global);
43
42
  }
44
43
  end
44
+
45
+ def self.memo_component(component_name, &block)
46
+ %x{
47
+ var fun = React.memo(function(props) {
48
+ Opal.React.render_buffer.push([]);
49
+ Opal.React.active_components.push(Opal.React.FunctionComponent.Runner.event_handlers);
50
+ #{React::FunctionComponent::Runner.new(`props`).instance_exec(&block)};
51
+ Opal.React.active_components.pop();
52
+ return Opal.React.render_buffer.pop();
53
+ });
54
+ var const_names;
55
+ if (component_name.includes('.')) {
56
+ const_names = component_name.split('.');
57
+ } else {
58
+ const_names = [component_name];
59
+ }
60
+ var const_last = const_names.length - 1;
61
+ const_names.reduce(function(prev, curr) {
62
+ if (prev && prev[curr]) {
63
+ return prev[curr];
64
+ } else {
65
+ if (const_names.indexOf(curr) === const_last) {
66
+ prev[curr] = fun;
67
+ return prev[curr];
68
+ } else {
69
+ prev[curr] = {};
70
+ return prev[curr];
71
+ }
72
+ }
73
+ }, Opal.global);
74
+ }
75
+ end
45
76
  end
46
77
  end
47
78
  end
@@ -1,3 +1,3 @@
1
1
  module React
2
- VERSION = '16.5.1'
2
+ VERSION = '16.6.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isomorfeus-react
3
3
  version: !ruby/object:Gem::Version
4
- version: 16.5.1
4
+ version: 16.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Biedermann