isomorfeus-react 16.13.10 → 16.13.11

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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -10
  3. data/lib/isomorfeus-react-native.rb +5 -0
  4. data/lib/isomorfeus-react-paper.rb +4 -0
  5. data/lib/isomorfeus-react.rb +6 -4
  6. data/lib/isomorfeus/props/validator.rb +2 -2
  7. data/lib/isomorfeus/{react_config.rb → react/config.rb} +0 -0
  8. data/lib/isomorfeus/react/memcached_component_cache.rb +19 -0
  9. data/lib/isomorfeus/react/redis_component_cache.rb +19 -0
  10. data/lib/isomorfeus/{thread_local_component_cache.rb → react/thread_local_component_cache.rb} +0 -0
  11. data/lib/isomorfeus_react/lucid_app/mixin.rb +1 -0
  12. data/lib/isomorfeus_react/lucid_app/native_component_constructor.rb +0 -1
  13. data/lib/isomorfeus_react/lucid_component/api.rb +0 -27
  14. data/lib/isomorfeus_react/lucid_component/mixin.rb +1 -0
  15. data/lib/isomorfeus_react/lucid_component/styles_api.rb +34 -0
  16. data/lib/isomorfeus_react/lucid_func/mixin.rb +1 -0
  17. data/lib/isomorfeus_react/react/function_component/api.rb +7 -6
  18. data/lib/isomorfeus_react_material/lucid_material/app/mixin.rb +1 -0
  19. data/lib/isomorfeus_react_material/lucid_material/app/native_component_constructor.rb +0 -1
  20. data/lib/isomorfeus_react_material/lucid_material/component/mixin.rb +1 -0
  21. data/lib/isomorfeus_react_material/lucid_material/func/mixin.rb +1 -0
  22. data/lib/isomorfeus_react_paper/lucid_paper/app/base.rb +9 -0
  23. data/lib/isomorfeus_react_paper/lucid_paper/app/mixin.rb +19 -0
  24. data/lib/isomorfeus_react_paper/lucid_paper/app/native_component_constructor.rb +32 -0
  25. data/lib/isomorfeus_react_paper/lucid_paper/component/base.rb +9 -0
  26. data/lib/isomorfeus_react_paper/lucid_paper/component/mixin.rb +18 -0
  27. data/lib/isomorfeus_react_paper/lucid_paper/component/native_component_constructor.rb +25 -0
  28. data/lib/isomorfeus_react_paper/lucid_paper/func/base.rb +9 -0
  29. data/lib/isomorfeus_react_paper/lucid_paper/func/mixin.rb +14 -0
  30. data/lib/isomorfeus_react_paper/lucid_paper/func/native_component_constructor.rb +71 -0
  31. data/lib/react.rb +6 -5
  32. data/lib/react/component/api.rb +5 -4
  33. data/lib/react/version.rb +1 -1
  34. data/lib/react_native/component/elements.rb +203 -0
  35. data/lib/react_native/lucid_app/react_native_component_constructor.rb +51 -0
  36. data/lib/react_native/lucid_component/react_native_component_constructor.rb +37 -0
  37. data/lib/react_native/lucid_func/react_native_component_constructor.rb +82 -0
  38. data/lib/react_native/react.rb +120 -0
  39. metadata +69 -22
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 53c0609232408add3a50daefcd5b1a0cc8226a5320364378000ce4a2dce7b514
4
- data.tar.gz: 8b59169b1677d0d43111bc058033f0f4e19a0fcde099d864b97ecc2ac5d66b34
3
+ metadata.gz: 02a760c7e31fcd4fc03396b90831133ff8bfc02bf7602bd337ebe554b3778150
4
+ data.tar.gz: a87209a7b20d8b88b5d9ea4f2a1306edcec75a090ecc38578ee697ad2e3139bf
5
5
  SHA512:
6
- metadata.gz: 629628dadea198a9bf3257c9eeafe9408e7bc428d7557ba01eafe35dc3ffbebf36a72f2964d4b30b944f1edfafcfdf03f05b0ebbf4a1ede6c2c6552279fdf672
7
- data.tar.gz: 6b2a9d8587857ee38d9691c62f2ce84556c33ff7fad4c3b111be986a952f7476f271ab7fa20577856a483c0d831683de0b2b6050e65e777bcd902ddfd7eda4a4
6
+ metadata.gz: c4fa758232d69952fffa9f6c0e586cb96ae537232d788018cc13c6e64f636945566fae50d9cfc4befb83a69d7d3adfd74c8ced3b452b256ad8f64d5e24285538
7
+ data.tar.gz: 836d76d4dd5522925cbae401283757d59969c512e71e7992602c98e4ed69918047addf7ebc6e661c5ac6153bcfae3747fc03b1533140f29244ea243bdfe61c55
data/README.md CHANGED
@@ -3,21 +3,13 @@
3
3
  Develop React components for Opal Ruby along with very easy to use and advanced React-Redux Components.
4
4
 
5
5
  ## Community and Support
6
- At the [Isomorfeus Framework Project](http://isomorfeus.com)
6
+ At the [Isomorfeus Framework Project](http://isomorfeus.com)
7
7
 
8
8
  ## Versioning and Compatibility
9
9
  isomorfeus-react version follows the React version which features and API it implements.
10
10
 
11
11
  ### React
12
- Isomorfeus-react 16.12.x implements features and the API of React 16.12 and should be used with React 16.12
13
-
14
- ### Preact
15
- isomorfeus-react works with preact version 10.1.x.
16
-
17
- ### Nerv
18
- isomorfeus-react works in general with nervjs 1.5.x. with some issues:
19
- - Server Side Rendering does currently not work at all.
20
- - Some specs with respect to callbacks (component_will_unmount) and styles fail.
12
+ Isomorfeus-react 16.13.x implements features and the API of React 16.13 and should be used with React 16.13
21
13
 
22
14
  ## Documentation
23
15
 
@@ -0,0 +1,5 @@
1
+ require 'react_native/react'
2
+ require 'react_native/component/elements'
3
+ require 'react_native/lucid_app/react_native_component_constructor'
4
+ require 'react_native/lucid_component/react_native_component_constructor'
5
+ require 'react_native/lucid_func/react_native_component_constructor'
@@ -0,0 +1,4 @@
1
+ require 'isomorfeus-react'
2
+
3
+ Isomorfeus.zeitwerk.push_dir('isomorfeus_react_paper')
4
+ require_tree 'isomorfeus_react_paper', :autoload
@@ -10,7 +10,7 @@ if RUBY_ENGINE == 'opal'
10
10
  require 'browser/element'
11
11
  end
12
12
 
13
- require 'isomorfeus/react_config'
13
+ require 'isomorfeus/react/config'
14
14
 
15
15
  # allow mounting of components
16
16
  if on_browser?
@@ -83,7 +83,7 @@ else
83
83
  require 'isomorfeus-redux'
84
84
  require 'isomorfeus-speednode'
85
85
  require 'react/version'
86
- require 'isomorfeus/react_config'
86
+ require 'isomorfeus/react/config'
87
87
 
88
88
  # props
89
89
  require 'isomorfeus/props/validate_hash_proxy'
@@ -99,8 +99,10 @@ else
99
99
 
100
100
  Isomorfeus.server_side_rendering = true
101
101
 
102
- # cache
103
- require 'isomorfeus/thread_local_component_cache'
102
+ # caches
103
+ require 'isomorfeus/react/thread_local_component_cache'
104
+ require 'isomorfeus/react/memcached_component_cache'
105
+ require 'isomorfeus/react/redis_component_cache'
104
106
  require 'isomorfeus/react_view_helper'
105
107
 
106
108
  Isomorfeus.component_cache_init do
@@ -139,7 +139,7 @@ module Isomorfeus
139
139
  Isomorfeus.raise_error(message: "#{@c}: #{@p} must be a String") unless @v.class == String
140
140
  case @o[:type]
141
141
  when :email
142
- Isomorfeus.raise_error(message: "#{@c}: #{@p} is not a valid email address") unless @v.match? /\A[^@\s]+@([^@\s]+\.)+[^@\s]+\z/
142
+ Isomorfeus.raise_error(message: "#{@c}: #{@p} is not a valid email address") unless @v.match?(/\A[^@\s]+@([^@\s]+\.)+[^@\s]+\z/)
143
143
  when :uri
144
144
  if RUBY_ENGINE == 'opal'
145
145
  %x{
@@ -150,7 +150,7 @@ module Isomorfeus
150
150
  }
151
151
  }
152
152
  else
153
- Isomorfeus.raise_error(message: "#{@c}: #{@p} is not a valid uri") unless @v.match? /\A#{URI.regexp}\z/
153
+ Isomorfeus.raise_error(message: "#{@c}: #{@p} is not a valid uri") unless @v.match?(/\A#{URI.regexp}\z/)
154
154
  end
155
155
  end
156
156
  end
File without changes
@@ -0,0 +1,19 @@
1
+ module Isomorfeus
2
+ module Professional
3
+ class MemcachedComponentCache
4
+ def initialize(*args)
5
+ @dalli_client = Dalli::Client.new(*args)
6
+ end
7
+
8
+ def fetch(key)
9
+ json = @dalli_client.get(key)
10
+ Oj.load(json, mode: :strict)
11
+ end
12
+
13
+ def store(key, rendered_tree, response_status, styles)
14
+ json = Oj.dump([rendered_tree, response_status, styles], mode: :strict)
15
+ @dalli_client.set(key, json)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Isomorfeus
2
+ module Professional
3
+ class RedisComponentCache
4
+ def initialize(*args)
5
+ @redis_client = Redis.new(@args)
6
+ end
7
+
8
+ def fetch(key)
9
+ json = @redis_client.get(key)
10
+ Oj.load(json, mode: :strict)
11
+ end
12
+
13
+ def store(key, rendered_tree, response_status, styles)
14
+ json = Oj.dump([rendered_tree, response_status, styles], mode: :strict)
15
+ @redis_client.set(key, json)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -14,6 +14,7 @@ module LucidApp
14
14
  base.include(::React::Component::Api)
15
15
  base.include(::React::Component::Callbacks)
16
16
  base.include(::LucidComponent::Api)
17
+ base.include(::LucidComponent::StylesApi)
17
18
  base.include(::LucidApp::Api)
18
19
  base.include(::LucidComponent::Initializer)
19
20
  base.include(::React::Component::Features)
@@ -4,7 +4,6 @@ module LucidApp
4
4
  # to do so, we convert the props to ruby hashes and then compare
5
5
  # this makes sure, that for example rubys Nil object gets handled properly
6
6
  def self.extended(base)
7
- component_name = base.to_s + 'Wrapper'
8
7
  theme_component_name = base.to_s + 'ThemeWrapper'
9
8
  # language=JS
10
9
  %x{
@@ -18,28 +18,6 @@ module LucidComponent
18
18
  end
19
19
  end
20
20
 
21
- # styles
22
- def styles(styles_hash = nil, &block)
23
- if block_given?
24
- %x{
25
- base.jss_styles = function(theme) {
26
- let wrapped_theme = Opal.React.Component.Styles.$new(theme);
27
- var result = block.$call(wrapped_theme);
28
- return result.$to_n();
29
- }
30
- }
31
- nil
32
- elsif styles_hash
33
- `base.jss_styles = #{styles_hash.to_n}` if styles_hash
34
- styles_hash
35
- elsif `typeof base.jss_styles === 'object'`
36
- `Opal.Hash.$new(base.jss_styles)`
37
- else
38
- nil
39
- end
40
- end
41
- alias_method :styles=, :styles
42
-
43
21
  # preloading
44
22
  def preload(&block)
45
23
  `base.preload_block = block`
@@ -74,11 +52,6 @@ module LucidComponent
74
52
  SessionStore
75
53
  end
76
54
 
77
- # styles
78
- def styles
79
- props.classes
80
- end
81
-
82
55
  def theme
83
56
  props.theme
84
57
  end
@@ -14,6 +14,7 @@ module LucidComponent
14
14
  base.include(::React::Component::Api)
15
15
  base.include(::React::Component::Callbacks)
16
16
  base.include(::LucidComponent::Api)
17
+ base.include(::LucidComponent::StylesApi)
17
18
  base.include(::LucidComponent::Initializer)
18
19
  base.include(::React::Component::Features)
19
20
  end
@@ -0,0 +1,34 @@
1
+ module LucidComponent
2
+ module StylesApi
3
+ def self.included(base)
4
+ base.instance_exec do
5
+ # styles
6
+ def styles(styles_hash = nil, &block)
7
+ if block_given?
8
+ %x{
9
+ base.jss_styles = function(theme) {
10
+ let wrapped_theme = Opal.React.Component.Styles.$new(theme);
11
+ var result = block.$call(wrapped_theme);
12
+ return result.$to_n();
13
+ }
14
+ }
15
+ nil
16
+ elsif styles_hash
17
+ `base.jss_styles = #{styles_hash.to_n}` if styles_hash
18
+ styles_hash
19
+ elsif `typeof base.jss_styles === 'object'`
20
+ `Opal.Hash.$new(base.jss_styles)`
21
+ else
22
+ nil
23
+ end
24
+ end
25
+ alias_method :styles=, :styles
26
+ end
27
+
28
+ # styles
29
+ def styles
30
+ props.classes
31
+ end
32
+ end
33
+ end
34
+ end
@@ -12,6 +12,7 @@ module LucidFunc
12
12
  base.include(::ReactNative::Component::Elements)
13
13
  end
14
14
  base.include(::LucidComponent::Api)
15
+ base.include(::LucidComponent::StylesApi)
15
16
  end
16
17
  end
17
18
  end
@@ -18,8 +18,8 @@ module React
18
18
  `Opal.global.React.useDebugValue(value)`
19
19
  end
20
20
 
21
- def use_effect(&block)
22
- `Opal.global.React.useEffect(function() { #{block.call} })`
21
+ def use_effect(*args, &block)
22
+ `Opal.global.React.useEffect(function() { #{block.call} }, args)`
23
23
  end
24
24
 
25
25
  def use_imperative_handle(ref, *deps, &block)
@@ -86,12 +86,13 @@ module React
86
86
  end
87
87
  alias rre render_react_element
88
88
 
89
- def method_ref(method_symbol)
89
+ def method_ref(method_symbol, *args)
90
+ method_key = "#{method_symbol}#{args}"
90
91
  %x{
91
- if (#{self}.method_refs && #{self}.method_refs[#{method_symbol}]) { return #{self}.method_refs[#{method_symbol}]; }
92
+ if (#{self}.method_refs && #{self}.method_refs[#{method_key}]) { return #{self}.method_refs[#{method_key}]; }
92
93
  if (!#{self}.method_refs) { #{self}.method_refs = {}; }
93
- #{self}.method_refs[#{method_symbol}] = #{method(method_symbol)};
94
- return #{self}.method_refs[#{method_symbol}];
94
+ #{self}.method_refs[#{method_key}] = { m: #{method(method_symbol)}, a: args };
95
+ return #{self}.method_refs[#{method_key}];
95
96
  }
96
97
  end
97
98
  alias m_ref method_ref
@@ -10,6 +10,7 @@ module LucidMaterial
10
10
  base.include(::React::Component::Api)
11
11
  base.include(::React::Component::Callbacks)
12
12
  base.include(::LucidComponent::Api)
13
+ base.include(::LucidComponent::StylesApi)
13
14
  base.include(::LucidApp::Api)
14
15
  base.include(::LucidComponent::Initializer)
15
16
  base.include(::React::Component::Features)
@@ -5,7 +5,6 @@ module LucidMaterial
5
5
  # to do so, we convert the props to ruby hashes and then compare
6
6
  # this makes sure, that for example rubys Nil object gets handled properly
7
7
  def self.extended(base)
8
- component_name = base.to_s + 'Wrapper'
9
8
  theme_component_name = base.to_s + 'ThemeWrapper'
10
9
  # language=JS
11
10
  %x{
@@ -10,6 +10,7 @@ module LucidMaterial
10
10
  base.include(::React::Component::Api)
11
11
  base.include(::React::Component::Callbacks)
12
12
  base.include(::LucidComponent::Api)
13
+ base.include(::LucidComponent::StylesApi)
13
14
  base.include(::LucidComponent::Initializer)
14
15
  base.include(::React::Component::Features)
15
16
  end
@@ -8,6 +8,7 @@ module LucidMaterial
8
8
  base.include(::React::FunctionComponent::Api)
9
9
  base.extend(::LucidMaterial::Func::NativeComponentConstructor)
10
10
  base.include(::LucidComponent::Api)
11
+ base.include(::LucidComponent::StylesApi)
11
12
  end
12
13
  end
13
14
  end
@@ -0,0 +1,9 @@
1
+ module LucidPaper
2
+ module App
3
+ class Base
4
+ def self.inherited(base)
5
+ base.include(::LucidPaper::App::Mixin)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ module LucidPaper
2
+ module App
3
+ module Mixin
4
+ def self.included(base)
5
+ base.include(::Native::Wrapper)
6
+ base.extend(::LucidApp::NativeLucidComponentConstructor)
7
+ base.extend(::LucidPaper::App::NativeComponentConstructor)
8
+ base.extend(::LucidPropDeclaration::Mixin)
9
+ base.include(::React::Component::Elements)
10
+ base.include(::React::Component::Api)
11
+ base.include(::React::Component::Callbacks)
12
+ base.include(::LucidComponent::Api)
13
+ base.include(::LucidApp::Api)
14
+ base.include(::LucidComponent::Initializer)
15
+ base.include(::React::Component::Features)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,32 @@
1
+ module LucidPaper
2
+ module App
3
+ module NativeComponentConstructor
4
+ # for should_component_update we apply ruby semantics for comparing props
5
+ # to do so, we convert the props to ruby hashes and then compare
6
+ # this makes sure, that for example rubys Nil object gets handled properly
7
+ def self.extended(base)
8
+ %x{
9
+ base.jss_theme = Opal.global.Paper.DefaultTheme;
10
+ base.themed_component = Opal.global.Paper.withTheme(base.lucid_react_component);
11
+ base.react_component = class extends Opal.global.React.Component {
12
+ constructor(props) {
13
+ super(props);
14
+ if (Opal.Isomorfeus.$top_component() == nil) { Opal.Isomorfeus['$top_component='](this); }
15
+ }
16
+ static get displayName() {
17
+ return "IsomorfeusTopLevelComponent";
18
+ }
19
+ static set displayName(new_name) {
20
+ // dont do anything here except returning the set value
21
+ return new_name;
22
+ }
23
+ render() {
24
+ let themed_component = Opal.global.React.createElement(base.themed_component, this.props);
25
+ return Opal.global.React.createElement(Opal.global.Paper.Provider, { theme: base.jss_theme }, themed_component);
26
+ }
27
+ }
28
+ }
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,9 @@
1
+ module LucidPaper
2
+ module Component
3
+ class Base
4
+ def self.inherited(base)
5
+ base.include(::LucidPaper::Component::Mixin)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,18 @@
1
+ module LucidPaper
2
+ module Component
3
+ module Mixin
4
+ def self.included(base)
5
+ base.include(::Native::Wrapper)
6
+ base.extend(::LucidComponent::NativeLucidComponentConstructor)
7
+ base.extend(::LucidPaper::Component::NativeComponentConstructor)
8
+ base.extend(::LucidPropDeclaration::Mixin)
9
+ base.include(::React::Component::Elements)
10
+ base.include(::React::Component::Api)
11
+ base.include(::React::Component::Callbacks)
12
+ base.include(::LucidComponent::Api)
13
+ base.include(::LucidComponent::Initializer)
14
+ base.include(::React::Component::Features)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,25 @@
1
+ module LucidPaper
2
+ module Component
3
+ module NativeComponentConstructor
4
+ # for should_component_update we apply ruby semantics for comparing props
5
+ # to do so, we convert the props to ruby hashes and then compare
6
+ # this makes sure, that for example rubys Nil object gets handled properly
7
+ def self.extended(base)
8
+ component_name = base.to_s + 'Wrapper'
9
+ # language=JS
10
+ %x{
11
+ base.react_component = Opal.global.React.memo(function(props) {
12
+ let classes = null;
13
+ let store;
14
+ if (base.store_updates) { store = Opal.global.React.useContext(Opal.global.LucidApplicationContext); }
15
+ let new_props = Object.assign({}, props)
16
+ new_props.store = store;
17
+ new_props.theme = Opal.global.Paper.useTheme();
18
+ return Opal.global.React.createElement(base.lucid_react_component, new_props);
19
+ }, Opal.React.props_are_equal);
20
+ base.react_component.displayName = #{component_name};
21
+ }
22
+ end
23
+ end
24
+ end
25
+ end