lib/react/component/callbacks.rb in isomorfeus-react-16.9.2 vs lib/react/component/callbacks.rb in isomorfeus-react-16.9.3
- old
+ new
@@ -58,12 +58,12 @@
def get_derived_state_from_error(&block)
# TODO convert error
%x{
var fun = function(error) {
var result = #{`this.__ruby_instance`.instance_exec(`error`, &block)};
- if (result === null) { return null; }
- if (typeof result.$to_n === 'function') { return result.$to_n() }
+ if (typeof result.$to_n === 'function') { result = result.$to_n() }
+ if (result === Opal.nil) { return null; }
return result;
}
if (self.lucid_react_component) { self.lucid_react_component.prototype.getDerivedStateFromError = fun; }
else { self.react_component.prototype.getDerivedStateFromError = fun; }
}
@@ -71,27 +71,30 @@
def get_derived_state_from_props(&block)
%x{
var fun = function(props, state) {
Opal.React.active_redux_components.push(this.__ruby_instance);
- #{`this.__ruby_instance`.instance_exec(`Opal.React.Component.Props.$new({props: props})`,
- `Opal.React.Component.State.$new({state: state})`,
- &block)};
+ var result = #{`this.__ruby_instance`.instance_exec(`Opal.React.Component.Props.$new({props: props})`,
+ `Opal.React.Component.State.$new({state: state})`, &block)};
Opal.React.active_redux_components.pop();
+ if (typeof result.$to_n === 'function') { result = result.$to_n() }
+ if (result === Opal.nil) { return null; }
+ return result;
}
if (self.lucid_react_component) { self.lucid_react_component.prototype.getDerivedStateFromProps = fun; }
else { self.react_component.prototype.getDerivedStateFromProps = fun; }
}
end
def get_snapshot_before_update(&block)
%x{
var fun = function(prev_props, prev_state) {
- Opal.React.active_redux_components.push(this.__ruby_instance);
- #{`this.__ruby_instance`.instance_exec(`Opal.React.Component.Props.$new({props: prev_props})`,
- `Opal.React.Component.State.$new({state: prev_state})`,
- &block)};
+
+ var result = #{`this.__ruby_instance`.instance_exec(`Opal.React.Component.Props.$new({props: prev_props})`,
+ `Opal.React.Component.State.$new({state: prev_state})`, &block)};
Opal.React.active_redux_components.pop();
+ if (result === Opal.nil) { return null; }
+ return result;
}
if (self.lucid_react_component) { self.lucid_react_component.prototype.getSnapshotBeforeUpdate = fun; }
else { self.react_component.prototype.getSnapshotBeforeUpdate = fun; }
}
end