Sha256: d8630e138fbe6eff04aa08e611b6598d58f48459deadad934656f6dae062f476

Contents?: true

Size: 1.49 KB

Versions: 2

Compression:

Stored size: 1.49 KB

Contents

module LucidApp
  module NativeComponentConstructor
    # for should_component_update we apply ruby semantics for comparing props
    # to do so, we convert the props to ruby hashes and then compare
    # this makes sure, that for example rubys Nil object gets handled properly
    def self.extended(base)
      component_name = base.to_s
      # language=JS
      %x{
        base.jss_theme = {};
        base.themed_react_component = function(props) {
          let classes = null;
          let theme = Opal.global.ReactJSS.useTheme();
          if (base.jss_styles) {
            if (!base.use_styles || (Opal.Isomorfeus.development && Opal.Isomorfeus.development !== nil)) {
              let styles;
              if (typeof base.jss_styles === 'function') { styles = base.jss_styles(theme); }
              else { styles = base.jss_styles; }
              base.use_styles = Opal.global.ReactJSS.createUseStyles(styles);
            }
            classes = base.use_styles();
          }
          let themed_classes_props = Object.assign({}, props, { classes: classes, theme: theme });
          return Opal.global.React.createElement(base.lucid_react_component, themed_classes_props);
        }
        base.react_component = function(props) {
          let themed_component = Opal.global.React.createElement(base.themed_react_component, props);
          return Opal.global.React.createElement(Opal.global.ReactJSS.ThemeProvider, { theme: base.jss_theme }, themed_component);
        }
      }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
isomorfeus-react-16.11.0 lib/lucid_app/native_component_constructor.rb
isomorfeus-react-16.10.17 lib/lucid_app/native_component_constructor.rb