Sha256: 06855d137783406e5c241f35515e935a3fda54a1e68ad1389314efb1a0625591

Contents?: true

Size: 1.16 KB

Versions: 4

Compression:

Stored size: 1.16 KB

Contents

module Isomorfeus
  class PreactSSR
    def initialize(component_name, props, location, locale)
      @component = component_name.is_a?(String) ? self.class.const_get(component_name) : component_name
      @props = props
      @location = location
      @locale = locale
    end

    def render(skip_ssr, keep_state)
      Isomorfeus.browser_location = Browser::Location.new(@location)
      Isomorfeus.current_locale = @locale if @locale
      Isomorfeus.ssr_response_status = 200
      NanoCSS.instance = NanoCSS.new(given_renderer: NanoCSS.global_instance.renderer.deep_dup)
      unless keep_state
        Isomorfeus.init_store
        Isomorfeus.store.clear!
        Isomorfeus.store.dispatch(type: 'I18N_INIT', data: { locale: @locale, domain: Isomorfeus.i18n_domain })
      end
      return '' if skip_ssr
      c = Isomorfeus.current_user
      if c.respond_to?(:reload)
        Thread.current[:isomorfeus_user] = LocalSystem.new
        begin
          c.reload
        ensure
          Thread.current[:isomorfeus_user] = c
        end
      end
      ::Preact.render_to_string(::Preact.create_element(@component, @props))
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
isomorfeus-preact-23.9.0.rc12 lib/isomorfeus/preact/ssr.rb
isomorfeus-preact-23.9.0.rc11 lib/isomorfeus/preact/ssr.rb
isomorfeus-preact-23.9.0.rc10 lib/isomorfeus/preact/ssr.rb
isomorfeus-preact-23.9.0.rc9 lib/isomorfeus/preact/ssr.rb