isomorfeus-react 16.8.1 → 16.8.2

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: 6e1f51aa98f40271693104f25f9321a0b1ce04668666efe2f6b345958f2d4687
4
- data.tar.gz: 0c823d4922443ab1b157b638438a908caff664906be19c7fbef4f0410cb3a36d
3
+ metadata.gz: 9e21d256eefe22328c08a12c7fe32ad6891c60d167f2ff44b4c24fea24ce018e
4
+ data.tar.gz: 3f142f8243283f8ef26892e96d8c10913d22b20ccf70d435f662148b0ea51f0c
5
5
  SHA512:
6
- metadata.gz: d14aa94c3504a7cf2eee50db467e468045660f4fcdc1dbc8f2beb95f7f2ad45e6ceca07c8a53b8291a354859e42e8c1d6cc2f6245ef5e2c0ab0bc2ccf4865cda
7
- data.tar.gz: 9b36d35c724f49776ec46bb4c4bf4530f7ccd3cb2b29d83ed2b8fbbb7c619dbf5c4c23a5c86c87ebd13eb8cccbe315f2f543a6bca5f7f2a102eae2c1051d4322
6
+ metadata.gz: 5da5eb77a5e0705a8f073b6841932cdfddba41bf05dd12cd417295cb5abfdfc07f2337b9197fe7d340740779311f8ed8f1c03238ae9d8eb59e4a2412f0d27d40
7
+ data.tar.gz: aff97f67736bd4901efd02936c16a236855b759c1b0b1f9c0d949700d5592a3540a3e39ddbead11b75bfb9d619f543813a8539c9471ba153acf7ad04a44dff67
@@ -1,6 +1,7 @@
1
1
  module Isomorfeus
2
2
  if RUBY_ENGINE == 'opal'
3
3
  class << self
4
+ attr_accessor :initial_state_fetched
4
5
  attr_reader :initialized
5
6
  attr_reader :env
6
7
 
@@ -1,7 +1,7 @@
1
1
  module Isomorfeus
2
2
  module ReactViewHelper
3
3
  def mount_component(component_name, props = {}, asset = 'application_ssr.js')
4
- render_result = "<div data-iso-env=\"#{Isomorfeus.env}\" data-iso-root=\"#{component_name}\" data-iso-props='#{Oj.dump(props, mode: :strict)}'>"
4
+ render_result = "<div data-iso-env=\"#{Isomorfeus.env}\" data-iso-root=\"#{component_name}\" data-iso-props='#{Oj.dump(props, mode: :strict)}'"
5
5
  if Isomorfeus.server_side_rendering
6
6
  unless Isomorfeus.ssr_contexts.key?(asset)
7
7
  asset_file_name = OpalWebpackLoader::Manifest.lookup_path_for(asset)
@@ -15,9 +15,15 @@ module Isomorfeus
15
15
  JAVASCRIPT
16
16
  end
17
17
  javascript << <<~JAVASCRIPT
18
- return global.Opal.Isomorfeus.TopLevel.$render_component_to_string('#{component_name}', #{Oj.dump(props, mode: :strict)})
18
+ var rendered_tree = global.Opal.Isomorfeus.TopLevel.$render_component_to_string('#{component_name}', #{Oj.dump(props, mode: :strict)})
19
+ var application_state = global.Opal.Isomorfeus.store.native.getState();
20
+ return [rendered_tree, application_state]
19
21
  JAVASCRIPT
20
- render_result << Isomorfeus.ssr_contexts[asset].exec(javascript)
22
+ rendered_tree, application_state = Isomorfeus.ssr_contexts[asset].exec(javascript)
23
+ render_result << "data-iso-state='#{Oj.dump(application_state, mode: :strict)}'>"
24
+ render_result << rendered_tree
25
+ else
26
+ render_result << '>'
21
27
  end
22
28
  render_result << '</div>'
23
29
  render_result
@@ -9,6 +9,13 @@ module Isomorfeus
9
9
  props_json = root_element.JS.getAttribute('data-iso-props')
10
10
  props = `Opal.Hash.$new(JSON.parse(props_json))`
11
11
  hydrated = root_element.JS.getAttribute('data-iso-hydrated')
12
+ state_json = root_element.JS.getAttribute('data-iso-state')
13
+ if state_json
14
+ state = `JSON.parse(state_json)`
15
+ Isomorfeus.store.JS[:native].JS.dispatch(`{ type: 'APPLICATION_STATE', set_state: state.application_state }`)
16
+ Isomorfeus.store.JS[:native].JS.dispatch(`{ type: 'COMPONENT_STATE', set_state: state.component_state }`)
17
+ Isomorfeus.store.JS[:native].JS.dispatch(`{ type: 'COMPONENT_CLASS_STATE', set_state: state.component_class_state }`)
18
+ end
12
19
  mount_component(component, props, root_element, hydrated)
13
20
  end
14
21
  end
@@ -10,6 +10,10 @@ module Isomorfeus
10
10
  def render_component_to_string(component_name, props_json)
11
11
  # for some reason props_json arrives already decoded
12
12
  component = component_name.constantize
13
+ unless Isomorfeus.initial_state_fetched
14
+ Isomorfeus.initial_state_fetched = true
15
+ Redux::Store.preloaded_state = Isomorfeus.store.get_state
16
+ end
13
17
  Isomorfeus.force_init!
14
18
  ReactDOMServer.render_to_string(React.create_element(component, `Opal.Hash.$new(props_json)`))
15
19
  end
@@ -2,25 +2,10 @@ module LucidComponent
2
2
  module API
3
3
  def self.included(base)
4
4
  base.instance_exec do
5
- def app_store
6
- @default_app_store_defined = true
7
- @default_app_store ||= ::React::ReduxComponent::AppStoreDefaults.new(default_props, self.to_s)
8
- end
9
-
10
- def class_store
11
- @default_class_store_defined = true
12
- @default_class_store ||= ::React::ReduxComponent::ComponentClassStoreDefaults.new(default_props, self.to_s)
13
- end
14
-
15
- def store
16
- @default_instance_store_defined = true
17
- @default_class_store ||= ::React::ReduxComponent::ComponentInstanceStoreDefaults.new(default_props, self.to_s)
18
- end
19
-
20
5
  def prop(name, options = `null`)
21
6
  name = `Opal.React.lower_camelize(name)`
22
7
  if options
23
- if options.has_key?(:default)
8
+ if options.key?(:default)
24
9
  %x{
25
10
  if (typeof self.lucid_react_component.defaultProps == "undefined") {
26
11
  self.lucid_react_component.defaultProps = { isomorfeus_store: Opal.Hash.$new() };
@@ -28,7 +13,7 @@ module LucidComponent
28
13
  self.lucid_react_component.defaultProps[name] = options.$fetch("default");
29
14
  }
30
15
  end
31
- if options.has_key?(:class)
16
+ if options.key?(:class)
32
17
  %x{
33
18
  if (typeof self.lucid_react_component.propTypes == "undefined") {
34
19
  self.lucid_react_component.propTypes = {};
@@ -38,7 +23,7 @@ module LucidComponent
38
23
  self.lucid_react_component.propTypes[name] = self.lucid_react_component.prototype.validateProp;
39
24
  self.lucid_react_component.propValidations[name].ruby_class = options.$fetch("class");
40
25
  }
41
- elsif options.has_key?(:is_a)
26
+ elsif options.key?(:is_a)
42
27
  %x{
43
28
  if (typeof self.lucid_react_component.propTypes == "undefined") {
44
29
  self.lucid_react_component.propTypes = {};
@@ -49,7 +34,7 @@ module LucidComponent
49
34
  self.lucid_react_component.propValidations[name].is_a = options.$fetch("is_a");
50
35
  }
51
36
  end
52
- if options.has_key?(:required)
37
+ if options.key?(:required)
53
38
  %x{
54
39
  if (typeof self.lucid_react_component.propTypes == "undefined") {
55
40
  self.lucid_react_component.propTypes = {};
@@ -59,7 +44,7 @@ module LucidComponent
59
44
  self.lucid_react_component.propTypes[name] = self.lucid_react_component.prototype.validateProp;
60
45
  self.lucid_react_component.propValidations[name].required = options.$fetch("required");
61
46
  }
62
- elsif !options.has_key?(:default)
47
+ elsif !options.key?(:default)
63
48
  %x{
64
49
  if (typeof self.lucid_react_component.propTypes == "undefined") {
65
50
  self.lucid_react_component.propTypes = {};
@@ -47,7 +47,7 @@ module React
47
47
  def prop(name, options = `null`)
48
48
  name = `Opal.React.lower_camelize(name)`
49
49
  if options
50
- if options.has_key?(:default)
50
+ if options.key?(:default)
51
51
  %x{
52
52
  if (typeof self.react_component.defaultProps == "undefined") {
53
53
  self.react_component.defaultProps = {};
@@ -55,23 +55,23 @@ module React
55
55
  self.react_component.defaultProps[name] = options.$fetch("default");
56
56
  }
57
57
  end
58
- if options.has_key?(:class)
58
+ if options.key?(:class)
59
59
  %x{
60
60
  Opal.React.set_validate_prop(self, name);
61
61
  self.react_component.propValidations[name].ruby_class = options.$fetch("class");
62
62
  }
63
- elsif options.has_key?(:is_a)
63
+ elsif options.key?(:is_a)
64
64
  %x{
65
65
  Opal.React.set_validate_prop(self, name);
66
66
  self.react_component.propValidations[name].is_a = options.$fetch("is_a");
67
67
  }
68
68
  end
69
- if options.has_key?(:required)
69
+ if options.key?(:required)
70
70
  %x{
71
71
  Opal.React.set_validate_prop(self, name);
72
72
  self.react_component.propValidations[name].required = options.$fetch("required");
73
73
  }
74
- elsif !options.has_key?(:default)
74
+ elsif !options.key?(:default)
75
75
  %x{
76
76
  Opal.React.set_validate_prop(self, name);
77
77
  self.react_component.propValidations[name].required = true;
@@ -31,7 +31,7 @@ module React
31
31
 
32
32
  def store
33
33
  @default_instance_store_defined = true
34
- @default_class_store ||= ::React::ReduxComponent::ComponentInstanceStoreDefaults.new(state, self.to_s)
34
+ @default_instance_store ||= ::React::ReduxComponent::ComponentInstanceStoreDefaults.new(state, self.to_s)
35
35
  end
36
36
  end
37
37
  end
@@ -16,14 +16,14 @@ module React
16
16
  key = key.chop if `key.endsWith('=')`
17
17
  @state.isomorfeus_store[:application_state][key] = args[0]
18
18
  current_state = Isomorfeus.store.get_state
19
- if !(current_state[:application_state].has_key?(key))
19
+ if !(current_state[:application_state].key?(key))
20
20
  Isomorfeus.store.dispatch(type: 'APPLICATION_STATE', name: key, value: args[0])
21
21
  end
22
22
  else
23
23
  # get class state
24
24
 
25
25
  # check if we have a component local state value
26
- if @state.isomorfeus_store[:application_state].has_key?(key)
26
+ if @state.isomorfeus_store[:application_state].key?(key)
27
27
  return @state.isomorfeus_store[:application_state][key]
28
28
  end
29
29
  end
@@ -18,7 +18,7 @@ module React
18
18
  # check if we have a component local state value
19
19
  if `this.native_component_instance[this.access_key]["isomorfeus_store"]["application_state"].hasOwnProperty(key)`
20
20
  return @native_component_instance.JS[@access_key].JS[:isomorfeus_store].JS[:application_state].JS[key]
21
- elsif @component_instance.class.default_app_store_defined && @component_instance.class.app_store.to_h.has_key?(key)
21
+ elsif @component_instance.class.default_app_store_defined && @component_instance.class.app_store.to_h.key?(key)
22
22
  # check if a default value was given
23
23
  return @component_instance.class.app_store.to_h[key]
24
24
  end
@@ -21,7 +21,7 @@ module React
21
21
  if @native_component_instance.JS[@access_key].JS[:isomorfeus_store].JS[:component_class_state].JS[@component_name] &&
22
22
  @native_component_instance.JS[@access_key].JS[:isomorfeus_store].JS[:component_class_state].JS[@component_name].JS.hasOwnProperty(key)
23
23
  return @native_component_instance.JS[@access_key].JS[:isomorfeus_store].JS[:component_class_state].JS[@component_name].JS[key]
24
- elsif @component_instance.class.default_class_store_defined && @component_instance.class.class_store.to_h.has_key?(key)
24
+ elsif @component_instance.class.default_class_store_defined && @component_instance.class.class_store.to_h.key?(key)
25
25
  # check if a default value was given
26
26
  return @component_instance.class.class_store.to_h[key]
27
27
  end
@@ -17,7 +17,7 @@ module React
17
17
  key = key.chop if `key.endsWith('=')`
18
18
  @state.isomorfeus_store[:component_class_state][@component_name][key] = args[0]
19
19
  current_state = Isomorfeus.store.get_state
20
- if !(current_state[:component_class_state].has_key?(@component_name) && current_state[:component_class_state][@component_name].has_key?(key))
20
+ if !(current_state[:component_class_state].key?(@component_name) && current_state[:component_class_state][@component_name].key?(key))
21
21
  Isomorfeus.store.dispatch(type: 'COMPONENT_CLASS_STATE', class: @component_name, name: key, value: args[0])
22
22
  end
23
23
  else
@@ -25,7 +25,7 @@ module React
25
25
 
26
26
  # check if we have a component local state value
27
27
 
28
- if @state.isomorfeus_store[:component_class_state][@component_name].has_key?(key)
28
+ if @state.isomorfeus_store[:component_class_state][@component_name].key?(key)
29
29
  return @state.isomorfeus_store[:component_class_state][@component_name][key]
30
30
  end
31
31
  end
@@ -12,9 +12,9 @@ module React
12
12
  key = key.chop if `key.endsWith('=')`
13
13
  @state[key] = args[0]
14
14
  current_state = Isomorfeus.store.get_state
15
- if !(current_state[:component_class_state].has_key?(@component_name) &&
16
- current_state[:component_class_state][@component_name].has_key?(:instance_defaults) &&
17
- current_state[:component_class_state][@component_name][:instance_defaults].has_key?(key))
15
+ if !(current_state[:component_state].key?(@component_name) &&
16
+ current_state[:component_state][@component_name].key?(:instance_defaults) &&
17
+ current_state[:component_state][@component_name][:instance_defaults].key?(key))
18
18
  Isomorfeus.store.dispatch(type: 'COMPONENT_CLASS_STATE', class: @component_name, name: :instance_defaults, value: { key => args[0]})
19
19
  end
20
20
  else
@@ -22,7 +22,7 @@ module React
22
22
 
23
23
  # check if we have a component local state value
24
24
 
25
- if @state.has_key?(key)
25
+ if @state.key?(key)
26
26
  return @state[key]
27
27
  end
28
28
  end
@@ -32,10 +32,6 @@ module React
32
32
  def to_h
33
33
  @state
34
34
  end
35
-
36
- def to_n
37
- @state.to_n
38
- end
39
35
  end
40
36
  end
41
37
  end
@@ -24,7 +24,7 @@ module React
24
24
  @native_component_instance.JS[@access_key].JS[:isomorfeus_store].JS[:component_state].JS[@component_object_id].JS.hasOwnProperty(key)
25
25
  # check if we have a component local state value
26
26
  return @native_component_instance.JS[@access_key].JS[:isomorfeus_store].JS[:component_state].JS[@component_object_id].JS[key]
27
- elsif @component_instance.class.default_instance_store_defined && @component_instance.class.store.to_h.has_key?(key)
27
+ elsif @component_instance.class.default_instance_store_defined && @component_instance.class.store.to_h.key?(key)
28
28
  # check if a default value was given
29
29
  return @component_instance.class.store.to_h[key]
30
30
  end
@@ -10,10 +10,14 @@ module React
10
10
  component_reducer = Redux.create_reducer do |prev_state, action|
11
11
  case action[:type]
12
12
  when 'COMPONENT_STATE'
13
- new_state = {}.merge!(prev_state) # make a copy of state
14
- new_state[action[:object_id]] = {} unless new_state.has_key?(action[:object_id])
15
- new_state[action[:object_id]].merge!(action[:name] => action[:value])
16
- new_state
13
+ if action.key?(:set_state)
14
+ action[:set_state]
15
+ else
16
+ new_state = {}.merge!(prev_state) # make a copy of state
17
+ new_state[action[:object_id]] = {} unless new_state.key?(action[:object_id])
18
+ new_state[action[:object_id]].merge!(action[:name] => action[:value])
19
+ new_state
20
+ end
17
21
  else
18
22
  prev_state
19
23
  end
@@ -22,10 +26,14 @@ module React
22
26
  component_class_reducer = Redux.create_reducer do |prev_state, action|
23
27
  case action[:type]
24
28
  when 'COMPONENT_CLASS_STATE'
25
- new_state = {}.merge!(prev_state) # make a copy of state
26
- new_state[action[:class]] = {} unless new_state.has_key?(action[:class])
27
- new_state[action[:class]].merge!(action[:name] => action[:value])
28
- new_state
29
+ if action.key?(:set_state)
30
+ action[:set_state]
31
+ else
32
+ new_state = {}.merge!(prev_state) # make a copy of state
33
+ new_state[action[:class]] = {} unless new_state.key?(action[:class])
34
+ new_state[action[:class]].merge!(action[:name] => action[:value])
35
+ new_state
36
+ end
29
37
  else
30
38
  prev_state
31
39
  end
data/lib/react/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module React
2
- VERSION = '16.8.1'
2
+ VERSION = '16.8.2'
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.8.1
4
+ version: 16.8.2
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-06-09 00:00:00.000000000 Z
11
+ date: 2019-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 4.0.5
89
+ version: 4.0.7
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 4.0.5
96
+ version: 4.0.7
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: isomorfeus-speednode
99
99
  requirement: !ruby/object:Gem::Requirement