Sha256: 43f533ab5b50392a50eeb807229f3f15add89f96078abcd1e3306951d513c023

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

module Isomorfeus
  class PreactSSR
    def self.mount_component(component_name, props, session_id, location, locale = nil)
      rendered_tree = new(component_name, props, session_id, location, locale).render
      [rendered_tree, Isomorfeus.store.get_state, NanoCSS.instance.renderer[:raw]]
    end

    def initialize(component_name, props, session_id, location, locale = nil)
      @session_id = session_id
      @component_name = component_name
      @props = props
      @location = location
      @locale = locale
    end

    def render
      Isomorfeus.browser_location = Browser::Location.new(@location)
      Isomorfeus.current_locale = @locale
      NanoCSS.instance = NanoCSS.new(given_renderer: NanoCSS.global_instance.renderer.deep_dup)
      Isomorfeus.init_store
      Isomorfeus.store.clear!
      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
      Isomorfeus::TopLevel.render_component_to_string(@component_name, @props)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
isomorfeus-preact-22.9.0.rc2 lib/isomorfeus/preact/ssr.rb
isomorfeus-preact-22.9.0.rc1 lib/isomorfeus/preact/ssr.rb