isomorfeus-react 16.5.1 → 16.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +8 -3
- data/lib/lucid_app/api.rb +4 -0
- data/lib/lucid_component/native_component_constructor.rb +1 -0
- data/lib/react.rb +8 -0
- data/lib/react/component/features.rb +11 -0
- data/lib/react/function_component/creator.rb +32 -1
- data/lib/react/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f5cb95862ec002593c0fa138708e7b836e5bde4cc5d98417fd9d1dc60822f3d
|
4
|
+
data.tar.gz: c675459414c7682373017e52d6d4eb4588d517f6280d8af39aa4f9e2bed73ad6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.
|
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
|

|
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.
|
data/lib/lucid_app/api.rb
CHANGED
data/lib/react.rb
CHANGED
@@ -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
|
data/lib/react/version.rb
CHANGED