Class: Teek::UI::WidgetTypes Private
- Inherits:
-
Object
- Object
- Teek::UI::WidgetTypes
- Defined in:
- lib/teek/ui/widget_types.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Central registry of WidgetType descriptors, mirroring CommandInterceptors's own register/for_type shape - one registered descriptor per node type is the single source of truth WidgetDSL, Realizer, and Validator each dispatch to for that type's own build/realize/validate behavior.
Unlike CommandInterceptors (consulted per-call with a type already in hand) or WidgetValidators (many validators can share one type), exactly one descriptor owns a given type here, and consumers need the full set up front to drive codegen - so this adds two things CommandInterceptors doesn't need: WidgetTypes.each (enumerate every registered type) and WidgetTypes.on_register (subscribe to every past AND future registration, so load order between this file and a consumer like WidgetDSL never matters).
A descriptor's validator: (see WidgetType) is forwarded into
WidgetValidators right here, at registration time, so it's
dispatched through the exact same WidgetValidators.for_type call
every other validator goes through - Validator itself carries no
awareness of descriptors at all.
Class Method Summary collapse
-
.each {|widget_type| ... } ⇒ Enumerator
private
If no block given.
- .for_type(type) ⇒ WidgetType? private
-
.on_register {|widget_type| ... } ⇒ void
private
Subscribes
blockto every type registered from now on, and immediately replays every type already registered - so a subscriber (namely WidgetDSL's own codegen) sees every type regardless of whether it loaded before or after this file populated its own built-ins. -
.register(widget_type) ⇒ WidgetType
private
widget_type, for chaining.
Class Method Details
.each {|widget_type| ... } ⇒ Enumerator
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns if no block given.
58 59 60 61 62 |
# File 'lib/teek/ui/widget_types.rb', line 58 def each(&block) return enum_for(:each) unless block types.each_value(&block) end |
.for_type(type) ⇒ WidgetType?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
52 53 54 |
# File 'lib/teek/ui/widget_types.rb', line 52 def for_type(type) types[type.to_s] end |
.on_register {|widget_type| ... } ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Subscribes block to every type registered from now on, and
immediately replays every type already registered - so a
subscriber (namely Teek::UI::WidgetDSL's own codegen) sees every type
regardless of whether it loaded before or after this file
populated its own built-ins.
71 72 73 74 |
# File 'lib/teek/ui/widget_types.rb', line 71 def on_register(&block) types.each_value(&block) callbacks << block end |
.register(widget_type) ⇒ WidgetType
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns widget_type, for chaining.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/teek/ui/widget_types.rb', line 35 def register() key = .type.to_s if types.key?(key) raise ArgumentError, "widget type :#{.type} is already registered" end types[key] = if .validator WidgetValidators.register(.type) { |*args| .validator.call(*args) } end callbacks.each { |callback| callback.call() } end |