Module: LucidApp::Api

Defined in:
lib/isomorfeus_react/lucid_app/api.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/isomorfeus_react/lucid_app/api.rb', line 3

def self.included(base)
  base.instance_exec do
    def theme(theme_hash = nil, &block)
      if block_given?
        result = block.call(React::Component::Styles.new(`base.jss_theme`))
        %x{
          if (typeof result.$to_n === 'function') { base.jss_theme = result.$to_n(); }
          else { base.jss_theme = result; }
          return result;
        }
      elsif theme_hash
        `base.jss_theme = #{theme_hash.to_n}` if theme_hash
        theme_hash
      elsif `typeof base.jss_theme === 'object'`
        `Opal.Hash.$new(base.jss_theme)`
      else
        nil
      end
    end
    alias_method :theme=, :theme
  end
end