Module: Ruact::ComponentRegistry
- Defined in:
- lib/ruact/component_registry.rb
Overview
Holds the client components encountered during ERB rendering. Thread-local so it’s safe under concurrent requests.
Constant Summary collapse
- THREAD_KEY =
:__rsc_component_registry__
Class Method Summary collapse
- .by_token(token) ⇒ Object
- .components ⇒ Object
- .register(name, props) ⇒ Object
- .reset ⇒ Object
- .start ⇒ Object
Class Method Details
.by_token(token) ⇒ Object
27 28 29 |
# File 'lib/ruact/component_registry.rb', line 27 def self.by_token(token) components.find { |c| c[:token] == token } end |
.components ⇒ Object
19 20 21 |
# File 'lib/ruact/component_registry.rb', line 19 def self.components Thread.current[THREAD_KEY] ||= [] # rubocop:disable Ruact/NoSharedState -- TODO: refactor to explicit arg passing (NFR8) end |
.register(name, props) ⇒ Object
13 14 15 16 17 |
# File 'lib/ruact/component_registry.rb', line 13 def self.register(name, props) token = "__RSC_#{components.length}__" components << { token: token, name: name, props: props } token end |
.reset ⇒ Object
23 24 25 |
# File 'lib/ruact/component_registry.rb', line 23 def self.reset Thread.current[THREAD_KEY] = nil # rubocop:disable Ruact/NoSharedState -- TODO: refactor to explicit arg passing (NFR8) end |
.start ⇒ Object
9 10 11 |
# File 'lib/ruact/component_registry.rb', line 9 def self.start Thread.current[THREAD_KEY] = [] # rubocop:disable Ruact/NoSharedState -- TODO: refactor to explicit arg passing (NFR8) end |