Sha256: a6ee970a1982ed1818f3929370f1f6482b9d4e636be866825080e154ed13d0cc

Contents?: true

Size: 1.49 KB

Versions: 54

Compression:

Stored size: 1.49 KB

Contents

module Preact
  class Props
    def initialize(native)
      @native = native
    end

    def ==(other_props)
      %x{
        if (Opal.Preact.props_are_equal(#@native.props, #{other_props.to_n})) { return true; }
        return false;
      }
    end

    def [](prop)
      %x{
        const p = #@native.props;
        if (typeof p[prop] === 'undefined') {
          prop = Opal.Preact.lower_camelize(prop);
          if (typeof p[prop] === 'undefined') { return nil; }
        }
        return p[prop];
      }
    end

    def key?(k)
      %x{
        if (typeof #@native.props[k] !== 'undefined') { return true; }
        return false;
      }
    end

    def method_missing(prop, *args, &block)
      %x{
        const p = #@native.props;
        if (typeof p[prop] === 'undefined') {
          prop = Opal.Preact.lower_camelize(prop);
          if (typeof p[prop] === 'undefined') { return nil; }
        }
        return p[prop];
      }
    end

    def theme
      `#@native.props.iso_theme`
    end

    def params
      return @params if @params
      return nil if `typeof #@native.props.params === 'undefined'`
      @params = `Opal.Preact.Params.$new(#@native.props.params)`
    end

    def to_h
      `Opal.Hash.$new(#@native.props)`.transform_keys!(&:underscore)
    end

    def to_json
      JSON.dump(to_transport)
    end

    def to_n
      `#@native.props`
    end

    def to_transport
      {}.merge(to_h)
    end
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
isomorfeus-preact-10.9.0 lib/preact/props.rb
isomorfeus-preact-10.8.2 lib/preact/props.rb
isomorfeus-preact-10.8.1 lib/preact/props.rb
isomorfeus-preact-10.8.0 lib/preact/props.rb
isomorfeus-preact-10.7.3 lib/preact/props.rb
isomorfeus-preact-10.7.2 lib/preact/props.rb
isomorfeus-preact-10.7.1 lib/preact/props.rb
isomorfeus-preact-10.7.0 lib/preact/props.rb
isomorfeus-preact-10.6.62 lib/preact/props.rb
isomorfeus-preact-10.6.61 lib/preact/props.rb
isomorfeus-preact-10.6.60 lib/preact/props.rb
isomorfeus-preact-10.6.59 lib/preact/props.rb
isomorfeus-preact-10.6.58 lib/preact/props.rb
isomorfeus-preact-10.6.57 lib/preact/props.rb
isomorfeus-preact-10.6.56 lib/preact/props.rb
isomorfeus-preact-10.6.55 lib/preact/props.rb
isomorfeus-preact-10.6.54 lib/preact/props.rb
isomorfeus-preact-10.6.53 lib/preact/props.rb
isomorfeus-preact-10.6.52 lib/preact/props.rb
isomorfeus-preact-10.6.51 lib/preact/props.rb