Sha256: bfeb846c479df575418f79bc952b71c1371b68b3d4ba43d3d7dbfa4791da7e7d

Contents?: true

Size: 1.59 KB

Versions: 20

Compression:

Stored size: 1.59 KB

Contents

module Preact
  class Context
    def self.create_application_contexts
      Preact.create_context('LucidApplicationContext', { iso_location: "/", iso_store: {}, iso_theme: {} })
      Preact.create_context('RouterContext', {})
    end

    class Provider < Preact::Component
      class << self
        attr_reader :root_context
      end

      attr_reader :context_id
      attr_reader :subs

      def initialize(props, context)
        @self_class_root = self.class.root_context
        unless props.key?(:value)
          props = props.merge({ value: @self_class_root.value })
        end
        super(props, context)
        @context_id = @self_class_root.context_id
        @child_context = { @context_id => self }
        @getChildContext = true
        @subs = []
      end

      def get_child_context
        @child_context
      end

      def render
        RPE(@props[:children])
      end

      def should_component_update?(next_props, _next_state, _context)
        if @props[:value] != next_props[:value]
          @subs.each do |subc|
            Preact._enqueue_render(subc)
          end
        end
        true
      end

      def sub(component)
        @subs << component
        component.provider_subs = @subs
      end
    end

    attr_reader :context_id
    attr_reader :Provider
    attr_accessor :value

    def initialize(default_value = nil)
      @Provider = Class.new(Provider)
      @value = default_value
      @context_id = Preact._context_id
      @Provider.instance_variable_set(:@root_context, self)
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
isomorfeus-preact-23.9.0.rc12 lib/preact/context.rb
isomorfeus-preact-23.9.0.rc11 lib/preact/context.rb
isomorfeus-preact-23.9.0.rc10 lib/preact/context.rb
isomorfeus-preact-23.9.0.rc9 lib/preact/context.rb
isomorfeus-preact-23.9.0.rc8 lib/preact/context.rb
isomorfeus-preact-23.9.0.rc7 lib/preact/context.rb
isomorfeus-preact-23.9.0.rc6 lib/preact/context.rb
isomorfeus-preact-23.9.0.rc5 lib/preact/context.rb
isomorfeus-preact-23.9.0.rc4 lib/preact/context.rb
isomorfeus-preact-23.9.0.rc3 lib/preact/context.rb
isomorfeus-preact-23.9.0.rc2 lib/preact/context.rb
isomorfeus-preact-23.9.0.rc1 lib/preact/context.rb
isomorfeus-preact-23.8.0.rc3 lib/preact/context.rb
isomorfeus-preact-23.8.0.rc2 lib/preact/context.rb
isomorfeus-preact-23.8.0.rc1 lib/preact/context.rb
isomorfeus-preact-23.7.0.rc5 lib/preact/context.rb
isomorfeus-preact-23.7.0.rc4 lib/preact/context.rb
isomorfeus-preact-23.7.0.rc3 lib/preact/context.rb
isomorfeus-preact-23.7.0.rc2 lib/preact/context.rb
isomorfeus-preact-23.7.0.rc1 lib/preact/context.rb