Class: Ruact::Flight::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/ruact/flight/request.rb

Overview

Central state for a single Flight render. Owns the ID allocator, chunk queues, and dedup tracker.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, bundler_config, strict_serialization: false, on_as_json_warning: nil) ⇒ Request

Returns a new instance of Request.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ruact/flight/request.rb', line 21

def initialize(model, bundler_config, strict_serialization: false, on_as_json_warning: nil)
  @strict_serialization = strict_serialization
  @on_as_json_warning   = on_as_json_warning
  @next_chunk_id = 0
  @pending_chunks = 0
  @bundler_config = bundler_config

  @completed_import_chunks  = []
  @completed_regular_chunks = []
  @completed_error_chunks   = []
  @deferred_chunks          = []

  @written_objects = {}.compare_by_identity

  # Root task is always ID 0
  @root_model = model
end

Instance Attribute Details

#bundler_configObject (readonly)

Returns the value of attribute bundler_config.



18
19
20
# File 'lib/ruact/flight/request.rb', line 18

def bundler_config
  @bundler_config
end

#completed_error_chunksObject (readonly)

E rows — flushed last



13
14
15
# File 'lib/ruact/flight/request.rb', line 13

def completed_error_chunks
  @completed_error_chunks
end

#completed_import_chunksObject (readonly)

I rows — flushed first



9
10
11
# File 'lib/ruact/flight/request.rb', line 9

def completed_import_chunks
  @completed_import_chunks
end

#completed_regular_chunksObject (readonly)

model rows



11
12
13
# File 'lib/ruact/flight/request.rb', line 11

def completed_regular_chunks
  @completed_regular_chunks
end

#deferred_chunksObject (readonly)

{ id:, element:, delay: } — emitted after root row



15
16
17
# File 'lib/ruact/flight/request.rb', line 15

def deferred_chunks
  @deferred_chunks
end

#next_chunk_idObject (readonly)

Returns the value of attribute next_chunk_id.



18
19
20
# File 'lib/ruact/flight/request.rb', line 18

def next_chunk_id
  @next_chunk_id
end

#on_as_json_warningObject (readonly)

Returns the value of attribute on_as_json_warning.



18
19
20
# File 'lib/ruact/flight/request.rb', line 18

def on_as_json_warning
  @on_as_json_warning
end

#pending_chunksObject (readonly)

Returns the value of attribute pending_chunks.



18
19
20
# File 'lib/ruact/flight/request.rb', line 18

def pending_chunks
  @pending_chunks
end

#root_modelObject (readonly)

Returns the value of attribute root_model.



18
19
20
# File 'lib/ruact/flight/request.rb', line 18

def root_model
  @root_model
end

#strict_serializationObject (readonly)

Returns the value of attribute strict_serialization.



18
19
20
# File 'lib/ruact/flight/request.rb', line 18

def strict_serialization
  @strict_serialization
end

#written_objectsObject (readonly)

object_id => “$L<hex>” reference (dedup)



17
18
19
# File 'lib/ruact/flight/request.rb', line 17

def written_objects
  @written_objects
end

Instance Method Details

#allocate_idObject



39
40
41
42
43
# File 'lib/ruact/flight/request.rb', line 39

def allocate_id
  id = @next_chunk_id
  @next_chunk_id += 1
  id
end

#decrement_pendingObject



49
50
51
# File 'lib/ruact/flight/request.rb', line 49

def decrement_pending
  @pending_chunks -= 1
end

#increment_pendingObject



45
46
47
# File 'lib/ruact/flight/request.rb', line 45

def increment_pending
  @pending_chunks += 1
end