isomorfeus-react 16.9.24 → 16.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. metadata +3 -85
  3. data/README.md +0 -64
  4. data/lib/browser/delegate_native.rb +0 -70
  5. data/lib/browser/element.rb +0 -176
  6. data/lib/browser/element/canvas.rb +0 -17
  7. data/lib/browser/element/media.rb +0 -78
  8. data/lib/browser/event.rb +0 -92
  9. data/lib/browser/event_target.rb +0 -39
  10. data/lib/browser/file_list.rb +0 -125
  11. data/lib/browser/iterable.rb +0 -15
  12. data/lib/isomorfeus-react-material-ui.rb +0 -10
  13. data/lib/isomorfeus-react.rb +0 -145
  14. data/lib/isomorfeus/config.rb +0 -130
  15. data/lib/isomorfeus/props/validate_hash_proxy.rb +0 -178
  16. data/lib/isomorfeus/props/validator.rb +0 -131
  17. data/lib/isomorfeus/react_view_helper.rb +0 -130
  18. data/lib/isomorfeus/top_level.rb +0 -86
  19. data/lib/isomorfeus/top_level_ssr.rb +0 -28
  20. data/lib/lucid_app/api.rb +0 -30
  21. data/lib/lucid_app/base.rb +0 -7
  22. data/lib/lucid_app/context.rb +0 -7
  23. data/lib/lucid_app/mixin.rb +0 -20
  24. data/lib/lucid_app/native_component_constructor.rb +0 -105
  25. data/lib/lucid_component/app_store_defaults.rb +0 -36
  26. data/lib/lucid_component/app_store_proxy.rb +0 -38
  27. data/lib/lucid_component/base.rb +0 -7
  28. data/lib/lucid_component/class_store_proxy.rb +0 -41
  29. data/lib/lucid_component/component_class_store_defaults.rb +0 -38
  30. data/lib/lucid_component/component_instance_store_defaults.rb +0 -35
  31. data/lib/lucid_component/event_handler.rb +0 -17
  32. data/lib/lucid_component/initializer.rb +0 -12
  33. data/lib/lucid_component/instance_store_proxy.rb +0 -45
  34. data/lib/lucid_component/mixin.rb +0 -18
  35. data/lib/lucid_component/native_component_constructor.rb +0 -116
  36. data/lib/lucid_component/reducers.rb +0 -48
  37. data/lib/lucid_component/store_api.rb +0 -38
  38. data/lib/lucid_component/styles_support.rb +0 -37
  39. data/lib/lucid_material/app/base.rb +0 -9
  40. data/lib/lucid_material/app/mixin.rb +0 -22
  41. data/lib/lucid_material/app/native_component_constructor.rb +0 -107
  42. data/lib/lucid_material/component/base.rb +0 -9
  43. data/lib/lucid_material/component/mixin.rb +0 -20
  44. data/lib/lucid_material/component/native_component_constructor.rb +0 -118
  45. data/lib/lucid_prop_declaration/mixin.rb +0 -91
  46. data/lib/react.rb +0 -195
  47. data/lib/react/active_support_support.rb +0 -13
  48. data/lib/react/children.rb +0 -35
  49. data/lib/react/component/api.rb +0 -80
  50. data/lib/react/component/base.rb +0 -9
  51. data/lib/react/component/callbacks.rb +0 -106
  52. data/lib/react/component/elements.rb +0 -60
  53. data/lib/react/component/event_handler.rb +0 -19
  54. data/lib/react/component/features.rb +0 -47
  55. data/lib/react/component/history.rb +0 -36
  56. data/lib/react/component/initializer.rb +0 -11
  57. data/lib/react/component/location.rb +0 -15
  58. data/lib/react/component/match.rb +0 -31
  59. data/lib/react/component/mixin.rb +0 -19
  60. data/lib/react/component/native_component_constructor.rb +0 -93
  61. data/lib/react/component/props.rb +0 -59
  62. data/lib/react/component/resolution.rb +0 -70
  63. data/lib/react/component/should_component_update.rb +0 -14
  64. data/lib/react/component/state.rb +0 -52
  65. data/lib/react/component/styles.rb +0 -27
  66. data/lib/react/component/unsafe_api.rb +0 -33
  67. data/lib/react/context_wrapper.rb +0 -46
  68. data/lib/react/function_component/api.rb +0 -63
  69. data/lib/react/function_component/base.rb +0 -9
  70. data/lib/react/function_component/creator.rb +0 -32
  71. data/lib/react/function_component/event_handler.rb +0 -13
  72. data/lib/react/function_component/mixin.rb +0 -14
  73. data/lib/react/function_component/resolution.rb +0 -62
  74. data/lib/react/memo_component/base.rb +0 -9
  75. data/lib/react/memo_component/creator.rb +0 -32
  76. data/lib/react/memo_component/mixin.rb +0 -14
  77. data/lib/react/native_constant_wrapper.rb +0 -26
  78. data/lib/react/pure_component/base.rb +0 -9
  79. data/lib/react/pure_component/mixin.rb +0 -18
  80. data/lib/react/ref.rb +0 -13
  81. data/lib/react/synthetic_event.rb +0 -53
  82. data/lib/react/version.rb +0 -3
  83. data/lib/react_dom.rb +0 -47
  84. data/lib/react_dom_server.rb +0 -19
@@ -1,35 +0,0 @@
1
- module LucidComponent
2
- class ComponentInstanceStoreDefaults
3
- def initialize(state, component_name)
4
- @state = {}
5
- @component_name = component_name
6
- end
7
-
8
- def method_missing(key, *args, &block)
9
- if `args.length > 0`
10
- # set initial class state
11
- key = key.chop if `key.endsWith('=')`
12
- @state[key] = args[0]
13
- current_state = Isomorfeus.store.get_state
14
- if !(current_state[:component_state].key?(@component_name) &&
15
- current_state[:component_state][@component_name].key?(:instance_defaults) &&
16
- current_state[:component_state][@component_name][:instance_defaults].key?(key))
17
- Isomorfeus.store.dispatch(type: 'COMPONENT_CLASS_STATE', class: @component_name, name: :instance_defaults, value: { key => args[0]})
18
- end
19
- else
20
- # get class state
21
-
22
- # check if we have a component local state value
23
-
24
- if @state.key?(key)
25
- return @state[key]
26
- end
27
- end
28
- nil
29
- end
30
-
31
- def to_h
32
- @state
33
- end
34
- end
35
- end
@@ -1,17 +0,0 @@
1
- module LucidComponent
2
- module EventHandler
3
- def event_handlers
4
- @event_handlers ||= []
5
- end
6
-
7
- def event_handler(name, &block)
8
- event_handlers << name
9
- %x{
10
- self.lucid_react_component.prototype[name] = function(event, info) {
11
- #{ruby_event = ::React::SyntheticEvent.new(`event`)};
12
- #{`this.__ruby_instance`.instance_exec(ruby_event, `info`, &block)};
13
- }
14
- }
15
- end
16
- end
17
- end
@@ -1,12 +0,0 @@
1
- module LucidComponent
2
- module Initializer
3
- def initialize(native_component)
4
- @native = native_component
5
- @app_store = `Opal.LucidComponent.AppStoreProxy.$new(#{self})`
6
- @class_store = `Opal.LucidComponent.ClassStoreProxy.$new(#{self})`
7
- @props = `Opal.React.Component.Props.$new(#@native)`
8
- @state = `Opal.React.Component.State.$new(#@native)`
9
- @store = `Opal.LucidComponent.InstanceStoreProxy.$new(#{self})`
10
- end
11
- end
12
- end
@@ -1,45 +0,0 @@
1
- module LucidComponent
2
- class InstanceStoreProxy
3
- def initialize(component_instance)
4
- @native_component_instance = component_instance.to_n
5
- @component_instance = component_instance
6
- @component_object_id = component_instance.object_id.to_s
7
- end
8
-
9
- def method_missing(key, *args, &block)
10
- if `args.length > 0`
11
- # set instance state, simply a dispatch
12
-
13
- action = { type: 'COMPONENT_STATE', object_id: @component_object_id, name: (`key.endsWith('=')` ? key.chop : key), value: args[0] }
14
- Isomorfeus.store.dispatch(action)
15
-
16
- else
17
- # get instance state
18
-
19
- if @native_component_instance.JS[:context].JS[:component_state].JS[@component_object_id] &&
20
- @native_component_instance.JS[:context].JS[:component_state].JS[@component_object_id].JS.hasOwnProperty(key)
21
- # check if we have a component local state value
22
- return @native_component_instance.JS[:context].JS[:component_state].JS[@component_object_id].JS[key]
23
- elsif @component_instance.class.default_instance_store_defined && @component_instance.class.store.to_h.key?(key)
24
- # check if a default value was given
25
- return @component_instance.class.store.to_h[key]
26
- end
27
-
28
- # otherwise return nil
29
- return nil
30
- end
31
- end
32
-
33
- def dispatch(action)
34
- Isomorfeus.store.dispatch(action)
35
- end
36
-
37
- def subscribe(&block)
38
- Isomorfeus.store.subscribe(&block)
39
- end
40
-
41
- def unsubscribe(unsubscriber)
42
- `unsubscriber()`
43
- end
44
- end
45
- end
@@ -1,18 +0,0 @@
1
- module LucidComponent
2
- module Mixin
3
- def self.included(base)
4
- base.include(::Native::Wrapper)
5
- base.extend(::LucidComponent::NativeComponentConstructor)
6
- base.extend(::LucidPropDeclaration::Mixin)
7
- base.extend(::LucidComponent::EventHandler)
8
- base.include(::React::Component::Elements)
9
- base.include(::React::Component::API)
10
- base.include(::React::Component::Callbacks)
11
- base.include(::LucidComponent::StoreAPI)
12
- base.include(::LucidComponent::StylesSupport)
13
- base.include(::LucidComponent::Initializer)
14
- base.include(::React::Component::Features)
15
- base.include(::React::Component::Resolution)
16
- end
17
- end
18
- end
@@ -1,116 +0,0 @@
1
- module LucidComponent
2
- module NativeComponentConstructor
3
- # for should_component_update we apply ruby semantics for comparing props
4
- # to do so, we convert the props to ruby hashes and then compare
5
- # this makes sure, that for example rubys Nil object gets handled properly
6
- def self.extended(base)
7
- component_name = base.to_s
8
- # language=JS
9
- %x{
10
- base.lucid_react_component = class extends Opal.global.React.Component {
11
- constructor(props) {
12
- super(props);
13
- if (base.$default_state_defined()) {
14
- this.state = base.$state().$to_n();
15
- } else {
16
- this.state = {};
17
- };
18
- this.__ruby_instance = base.$new(this);
19
- this.__object_id = this.__ruby_instance.$object_id().$to_s();
20
- if (!this.state.component_state) {
21
- this.state.component_state = {};
22
- this.state.component_state[this.__object_id] = {};
23
- };
24
- var event_handlers = #{base.event_handlers};
25
- for (var i = 0; i < event_handlers.length; i++) {
26
- this[event_handlers[i]] = this[event_handlers[i]].bind(this);
27
- }
28
- var defined_refs = #{base.defined_refs};
29
- for (var ref in defined_refs) {
30
- if (defined_refs[ref] != null) {
31
- this[ref] = function(element) {
32
- element = Opal.React.native_element_or_component_to_ruby(element);
33
- #{`this.__ruby_instance`.instance_exec(`element`, &`defined_refs[ref]`)}
34
- }
35
- this[ref] = this[ref].bind(this);
36
- } else {
37
- this[ref] = Opal.global.React.createRef();
38
- }
39
- }
40
- }
41
- static get displayName() {
42
- return #{component_name};
43
- }
44
- render() {
45
- Opal.React.render_buffer.push([]);
46
- Opal.React.active_components.push(this);
47
- Opal.React.active_redux_components.push(this);
48
- #{`this.__ruby_instance`.instance_exec(&`base.render_block`)};
49
- Opal.React.active_redux_components.pop();
50
- Opal.React.active_components.pop();
51
- return Opal.React.render_buffer.pop();
52
- }
53
- data_access() {
54
- return this.context;
55
- }
56
- shouldComponentUpdate(next_props, next_state) {
57
- var next_props_keys = Object.keys(next_props);
58
- var this_props_keys = Object.keys(this.props);
59
- if (next_props_keys.length !== this_props_keys.length) { return true; }
60
-
61
- var next_state_keys = Object.keys(next_state);
62
- var this_state_keys = Object.keys(this.state);
63
- if (next_state_keys.length !== this_state_keys.length) { return true; }
64
-
65
- for (var property in next_props) {
66
- if (next_props.hasOwnProperty(property)) {
67
- if (!this.props.hasOwnProperty(property)) { return true; };
68
- if (property == "children") { if (next_props.children !== this.props.children) { return true; }}
69
- else if (typeof next_props[property] !== "undefined" && next_props[property] !== null &&
70
- typeof next_props[property]['$!='] !== "undefined" &&
71
- typeof this.props[property] !== "undefined" && this.props[property] !== null &&
72
- typeof this.props[property]['$!='] !== "undefined") {
73
- if (#{ !! (`next_props[property]` != `this.props[property]`) }) { return true; };
74
- } else if (next_props[property] !== this.props[property]) { return true; };
75
- }
76
- }
77
- for (var property in next_state) {
78
- if (next_state.hasOwnProperty(property)) {
79
- if (!this.state.hasOwnProperty(property)) { return true; };
80
- if (next_state[property] !== null && typeof next_state[property]['$!='] !== "undefined" &&
81
- this.state[property] !== null && typeof this.state[property]['$!='] !== "undefined") {
82
- if (#{ !! (`next_state[property]` != `this.state[property]`) }) { return true };
83
- } else if (next_state[property] !== this.state[property]) { return true };
84
- }
85
- }
86
- return false;
87
- }
88
- validateProp(props, propName, componentName) {
89
- try { base.$validate_prop(propName, props[propName]) }
90
- catch (e) { return new Error(componentName + " Error: prop validation failed: " + e.message); }
91
- return null;
92
- }
93
- }
94
- base.lucid_react_component.contextType = Opal.global.LucidApplicationContext;
95
- base.jss_styles = null;
96
- base.jss_styles_used = null;
97
- base.use_styles = null;
98
- base.react_component = function(props) {
99
- let classes = null;
100
- let theme = Opal.global.ReactJSS.useTheme();
101
- if (base.jss_styles) {
102
- if (!base.use_styles || (Opal.Isomorfeus["$development?"]() && !Object.is(base.jss_styles, base.jss_styles_used))) {
103
- base.jss_styles_used = base.jss_styles;
104
- let styles = base.jss_styles
105
- if (typeof styles === 'function') { styles = base.jss_styles(theme); }
106
- base.use_styles = Opal.global.ReactJSS.createUseStyles(styles);
107
- }
108
- classes = base.use_styles();
109
- }
110
- let class_theme_props = Object.assign({}, props, { classes: classes, theme: theme });
111
- return Opal.global.React.createElement(base.lucid_react_component, class_theme_props);
112
- }
113
- }
114
- end
115
- end
116
- end
@@ -1,48 +0,0 @@
1
- module LucidComponent
2
- module Reducers
3
- class << self
4
- attr_reader :component_reducers_added
5
-
6
- def add_component_reducers_to_store
7
- unless component_reducers_added
8
- @_component_reducers_added = true
9
- component_reducer = Redux.create_reducer do |prev_state, action|
10
- case action[:type]
11
- when 'COMPONENT_STATE'
12
- if action.key?(:set_state)
13
- action[:set_state]
14
- else
15
- new_state = {}.merge!(prev_state) # make a copy of state
16
- new_state[action[:object_id]] = {} unless new_state.key?(action[:object_id])
17
- new_state[action[:object_id]].merge!(action[:name] => action[:value])
18
- # new_state == prev_state ? prev_state : new_state
19
- new_state
20
- end
21
- else
22
- prev_state
23
- end
24
- end
25
-
26
- component_class_reducer = Redux.create_reducer do |prev_state, action|
27
- case action[:type]
28
- when 'COMPONENT_CLASS_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 == prev_state ? prev_state : new_state
36
- new_state
37
- end
38
- else
39
- prev_state
40
- end
41
- end
42
- Redux::Store.preloaded_state_merge!(component_state: {}, component_class_state: {})
43
- Redux::Store.add_reducers(component_state: component_reducer, component_class_state: component_class_reducer)
44
- end
45
- end
46
- end
47
- end
48
- end
@@ -1,38 +0,0 @@
1
- module LucidComponent
2
- module StoreAPI
3
- def self.included(base)
4
- base.instance_exec do
5
- attr_accessor :app_store
6
- attr_accessor :class_store
7
- attr_accessor :store
8
-
9
- def default_app_store_defined
10
- @default_app_store_defined
11
- end
12
-
13
- def default_class_store_defined
14
- @default_class_store_defined
15
- end
16
-
17
- def default_instance_store_defined
18
- @default_instance_store_defined
19
- end
20
-
21
- def app_store
22
- @default_app_store_defined = true
23
- @default_app_store ||= ::LucidComponent::AppStoreDefaults.new(state, self.to_s)
24
- end
25
-
26
- def class_store
27
- @default_class_store_defined = true
28
- @default_class_store ||= ::LucidComponent::ComponentClassStoreDefaults.new(state, self.to_s)
29
- end
30
-
31
- def store
32
- @default_instance_store_defined = true
33
- @default_instance_store ||= ::LucidComponent::ComponentInstanceStoreDefaults.new(state, self.to_s)
34
- end
35
- end
36
- end
37
- end
38
- end
@@ -1,37 +0,0 @@
1
- module LucidComponent
2
- module StylesSupport
3
- def self.included(base)
4
- base.instance_exec do
5
- def styles(styles_hash = nil, &block)
6
- if block_given?
7
- %x{
8
- base.jss_styles = function(theme) {
9
- let wrapped_theme = Opal.React.Component.Styles.$new(theme);
10
- var result = block.$call(wrapped_theme);
11
- return result.$to_n();
12
- }
13
- }
14
- nil
15
- elsif styles_hash
16
- `base.jss_styles = #{styles_hash.to_n}` if styles_hash
17
- styles_hash
18
- elsif `typeof base.jss_styles === 'object'`
19
- `Opal.Hash.$new(base.jss_styles)`
20
- else
21
- nil
22
- end
23
- end
24
- alias_method :styles=, :styles
25
- end
26
-
27
- def styles
28
- props.classes
29
- end
30
-
31
- def theme
32
- props.theme
33
- end
34
- end
35
- end
36
- end
37
-
@@ -1,9 +0,0 @@
1
- module LucidMaterial
2
- module App
3
- class Base
4
- def self.inherited(base)
5
- base.include(::LucidMaterial::App::Mixin)
6
- end
7
- end
8
- end
9
- end
@@ -1,22 +0,0 @@
1
- module LucidMaterial
2
- module App
3
- module Mixin
4
- def self.included(base)
5
- base.include(::Native::Wrapper)
6
- base.extend(::LucidMaterial::App::NativeComponentConstructor)
7
- base.extend(::LucidPropDeclaration::Mixin)
8
- base.extend(::React::Component::ShouldComponentUpdate)
9
- base.extend(::LucidComponent::EventHandler)
10
- base.include(::React::Component::Elements)
11
- base.include(::React::Component::API)
12
- base.include(::React::Component::Callbacks)
13
- base.include(::LucidComponent::StoreAPI)
14
- base.include(::LucidComponent::StylesSupport)
15
- base.include(::LucidApp::API)
16
- base.include(::LucidComponent::Initializer)
17
- base.include(::React::Component::Features)
18
- base.include(::React::Component::Resolution)
19
- end
20
- end
21
- end
22
- end
@@ -1,107 +0,0 @@
1
- module LucidMaterial
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
- component_name = base.to_s
9
- # language=JS
10
- %x{
11
- base.lucid_react_component = class extends Opal.global.React.Component {
12
- constructor(props) {
13
- super(props);
14
- if (base.$default_state_defined()) {
15
- this.state = base.$state().$to_n();
16
- } else {
17
- this.state = {};
18
- };
19
- this.state.isomorfeus_store_state = Opal.Isomorfeus.store.native.getState();
20
- var current_store_state = this.state.isomorfeus_store_state;
21
- if (typeof current_store_state.component_class_state[#{component_name}] !== "undefined") {
22
- this.state.component_class_state = {};
23
- this.state.component_class_state[#{component_name}] = current_store_state.component_class_state[#{component_name}];
24
- } else {
25
- this.state.component_class_state = {};
26
- this.state.component_class_state[#{component_name}] = {};
27
- };
28
- this.__ruby_instance = base.$new(this);
29
- this.__object_id = this.__ruby_instance.$object_id().$to_s();
30
- if (Opal.Isomorfeus.$top_component() == nil) { Opal.Isomorfeus['$top_component='](this); }
31
- if (!this.state.component_state) {
32
- this.state.component_state = {};
33
- this.state.component_state[this.__object_id] = {};
34
- };
35
- var event_handlers = #{base.event_handlers};
36
- for (var i = 0; i < event_handlers.length; i++) {
37
- this[event_handlers[i]] = this[event_handlers[i]].bind(this);
38
- }
39
- var defined_refs = #{base.defined_refs};
40
- for (var ref in defined_refs) {
41
- if (defined_refs[ref] != null) {
42
- this[ref] = function(element) {
43
- element = Opal.React.native_element_or_component_to_ruby(element);
44
- #{`this.__ruby_instance`.instance_exec(`element`, &`defined_refs[ref]`)}
45
- }
46
- this[ref] = this[ref].bind(this);
47
- } else {
48
- this[ref] = Opal.global.React.createRef();
49
- }
50
- }
51
- this.listener = this.listener.bind(this);
52
- this.unsubscriber = Opal.Isomorfeus.store.native.subscribe(this.listener);
53
- }
54
- static get displayName() {
55
- return #{component_name};
56
- }
57
- render() {
58
- Opal.React.render_buffer.push([]);
59
- Opal.React.active_components.push(this);
60
- Opal.React.active_redux_components.push(this.__ruby_instance);
61
- #{`this.__ruby_instance`.instance_exec(&`base.render_block`)};
62
- Opal.React.active_redux_components.pop();
63
- Opal.React.active_components.pop();
64
- var children = Opal.React.render_buffer.pop();
65
- return Opal.global.React.createElement(Opal.global.LucidApplicationContext.Provider, { value: this.state.isomorfeus_store_state }, children);
66
- }
67
- listener() {
68
- var next_state = Opal.Isomorfeus.store.native.getState();
69
- this.setState({ isomorfeus_store_state: next_state });
70
- }
71
- componentWillUnmount() {
72
- if (typeof this.unsubscriber === "function") { this.unsubscriber(); };
73
- }
74
- validateProp(props, propName, componentName) {
75
- try { base.$validate_prop(propName, props[propName]) }
76
- catch (e) { return new Error(componentName + " Error: prop validation failed: " + e.message); }
77
- return null;
78
- }
79
- }
80
- base.jss_styles = null;
81
- base.jss_styles_used = null;
82
- base.jss_theme = Opal.global.Mui.createMuiTheme();
83
- base.use_styles = null;
84
- base.themed_react_component = function(props) {
85
- let classes = null;
86
- let theme = Opal.global.MuiStyles.useTheme();
87
- if (base.jss_styles) {
88
- if (!base.use_styles || (Opal.Isomorfeus["$development?"]() && !Object.is(base.jss_styles, base.jss_styles_used))) {
89
- base.jss_styles_used = base.jss_styles;
90
- let styles = base.jss_styles
91
- if (typeof styles === 'function') { styles = styles(theme); }
92
- base.use_styles = Opal.global.MuiStyles.makeStyles(styles);
93
- }
94
- classes = base.use_styles();
95
- }
96
- let themed_classes_props = Object.assign({}, props, { classes: classes, theme: theme });
97
- return Opal.global.React.createElement(base.lucid_react_component, themed_classes_props);
98
- }
99
- base.react_component = function(props) {
100
- let themed_component = Opal.global.React.createElement(base.themed_react_component, props);
101
- return Opal.global.React.createElement(Opal.global.MuiStyles.ThemeProvider, { theme: base.jss_theme }, themed_component);
102
- }
103
- }
104
- end
105
- end
106
- end
107
- end