Sha256: 864a80bac3ea7503f69a33b8a103adf9779c4b43dfb105be4ef4613cf8952470

Contents?: true

Size: 1.19 KB

Versions: 2

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

require "pakyow/connection"

require "pakyow/data/proxy"
require "pakyow/data/sources/ephemeral"

require "pakyow/realtime/channel"

require "pakyow/ui/recordable"

module Pakyow
  module UI
    class Handler
      def initialize(app)
        @app = app
      end

      def call(args, subscription: nil, result: nil)
        renderer = Marshal.restore(args[:metadata])[:renderer]
        renderer.presentables[:__ui_transform] = true

        # If an ephemeral caused the update, replace the value for any matching presentables.
        #
        if result.is_a?(Data::Sources::Ephemeral)
          renderer.presentables.each do |key, value|
            if value.is_a?(Data::Proxy) && value.source.is_a?(Data::Sources::Ephemeral) && value.source.type == result.type && value.source.qualifications == result.qualifications
              value.instance_variable_set(:@source, result)
            end
          end
        end

        renderer.perform

        @app.websocket_server.subscription_broadcast(
          Realtime::Channel.new(:transformation, subscription[:id]),
          { id: args[:transformation_id], calls: renderer.presenter }
        )
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pakyow-ui-1.0.0.rc2 lib/pakyow/ui/handler.rb
pakyow-ui-1.0.0.rc1 lib/pakyow/ui/handler.rb