Class: Plushie::Node
- Inherits:
-
Data
- Object
- Data
- Plushie::Node
- Defined in:
- lib/plushie/node.rb
Overview
A UI tree node. Produced by DSL methods and widget builders.
Nodes are immutable value objects representing a single widget in the view tree. The runtime diffs consecutive trees to produce patches sent to the renderer.
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#children [Array<Node>] frozen array of child nodes (empty for leaf widgets)([Array<Node>](empty) ⇒ Object
readonly
A UI tree node.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#id [String] unique widget identifier (scoped within parent containers)([String](scoped within parent containers)) ⇒ Object
readonly
A UI tree node.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#meta [Hash] frozen runtime-only metadata, never sent to the renderer or included in diffs([Hash], neversenttotherenderer) ⇒ Object
readonly
A UI tree node.
-
#props ⇒ Object
readonly
Returns the value of attribute props.
-
#props [Hash] frozen hash of property values (symbol keys)([Hash](symbol keys)) ⇒ Object
readonly
A UI tree node.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#type [String] widget type name ("button", "column", "text_input", etc.)([String]("button", "column", "text_input", etc.)) ⇒ Object
readonly
A UI tree node.
Instance Method Summary collapse
-
#initialize(id:, type:, props: {}, children: [], meta: {}) ⇒ Node
constructor
Create a new Node with string-coerced id and type, and frozen props/children/meta.
-
#with(**changes) ⇒ Node
Return a new Node with the given fields replaced.
Constructor Details
#initialize(id:, type:, props: {}, children: [], meta: {}) ⇒ Node
Create a new Node with string-coerced id and type, and frozen props/children/meta.
33 34 35 36 37 |
# File 'lib/plushie/node.rb', line 33 def initialize(id:, type:, props: {}, children: [], meta: {}) raise ArgumentError, "Node id cannot be nil" if id.nil? raise ArgumentError, "Node type cannot be nil" if type.nil? super(id: id.to_s, type: type.to_s, props: props.freeze, children: children.freeze, meta: .freeze) end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children
24 25 26 |
# File 'lib/plushie/node.rb', line 24 def children @children end |
#children [Array<Node>] frozen array of child nodes (empty for leaf widgets)([Array<Node>](empty) ⇒ Object (readonly)
A UI tree node. Produced by DSL methods and widget builders.
Nodes are immutable value objects representing a single widget in the view tree. The runtime diffs consecutive trees to produce patches sent to the renderer.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/plushie/node.rb', line 24 Node = Data.define(:id, :type, :props, :children, :meta) do # Create a new Node with string-coerced id and type, and frozen props/children/meta. # # @param id [#to_s] unique widget identifier # @param type [#to_s] widget type name # @param props [Hash] widget properties (will be frozen) # @param children [Array<Node>] child nodes (will be frozen) # @param meta [Hash] runtime-only metadata, never sent to the renderer (will be frozen) # @return [Node] def initialize(id:, type:, props: {}, children: [], meta: {}) raise ArgumentError, "Node id cannot be nil" if id.nil? raise ArgumentError, "Node type cannot be nil" if type.nil? super(id: id.to_s, type: type.to_s, props: props.freeze, children: children.freeze, meta: .freeze) end # Return a new Node with the given fields replaced. # Unspecified fields retain their current values. # # @param changes [Hash] fields to replace (:id, :type, :props, :children, :meta) # @return [Node] new Node with the changes applied def with(**changes) self.class.new(**to_h.merge(changes)) end end |
#id ⇒ Object (readonly)
Returns the value of attribute id
24 25 26 |
# File 'lib/plushie/node.rb', line 24 def id @id end |
#id [String] unique widget identifier (scoped within parent containers)([String](scoped within parent containers)) ⇒ Object (readonly)
A UI tree node. Produced by DSL methods and widget builders.
Nodes are immutable value objects representing a single widget in the view tree. The runtime diffs consecutive trees to produce patches sent to the renderer.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/plushie/node.rb', line 24 Node = Data.define(:id, :type, :props, :children, :meta) do # Create a new Node with string-coerced id and type, and frozen props/children/meta. # # @param id [#to_s] unique widget identifier # @param type [#to_s] widget type name # @param props [Hash] widget properties (will be frozen) # @param children [Array<Node>] child nodes (will be frozen) # @param meta [Hash] runtime-only metadata, never sent to the renderer (will be frozen) # @return [Node] def initialize(id:, type:, props: {}, children: [], meta: {}) raise ArgumentError, "Node id cannot be nil" if id.nil? raise ArgumentError, "Node type cannot be nil" if type.nil? super(id: id.to_s, type: type.to_s, props: props.freeze, children: children.freeze, meta: .freeze) end # Return a new Node with the given fields replaced. # Unspecified fields retain their current values. # # @param changes [Hash] fields to replace (:id, :type, :props, :children, :meta) # @return [Node] new Node with the changes applied def with(**changes) self.class.new(**to_h.merge(changes)) end end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta
24 25 26 |
# File 'lib/plushie/node.rb', line 24 def @meta end |
#meta [Hash] frozen runtime-only metadata, never sent to the renderer or included in diffs([Hash], neversenttotherenderer) ⇒ Object (readonly)
A UI tree node. Produced by DSL methods and widget builders.
Nodes are immutable value objects representing a single widget in the view tree. The runtime diffs consecutive trees to produce patches sent to the renderer.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/plushie/node.rb', line 24 Node = Data.define(:id, :type, :props, :children, :meta) do # Create a new Node with string-coerced id and type, and frozen props/children/meta. # # @param id [#to_s] unique widget identifier # @param type [#to_s] widget type name # @param props [Hash] widget properties (will be frozen) # @param children [Array<Node>] child nodes (will be frozen) # @param meta [Hash] runtime-only metadata, never sent to the renderer (will be frozen) # @return [Node] def initialize(id:, type:, props: {}, children: [], meta: {}) raise ArgumentError, "Node id cannot be nil" if id.nil? raise ArgumentError, "Node type cannot be nil" if type.nil? super(id: id.to_s, type: type.to_s, props: props.freeze, children: children.freeze, meta: .freeze) end # Return a new Node with the given fields replaced. # Unspecified fields retain their current values. # # @param changes [Hash] fields to replace (:id, :type, :props, :children, :meta) # @return [Node] new Node with the changes applied def with(**changes) self.class.new(**to_h.merge(changes)) end end |
#props ⇒ Object (readonly)
Returns the value of attribute props
24 25 26 |
# File 'lib/plushie/node.rb', line 24 def props @props end |
#props [Hash] frozen hash of property values (symbol keys)([Hash](symbol keys)) ⇒ Object (readonly)
A UI tree node. Produced by DSL methods and widget builders.
Nodes are immutable value objects representing a single widget in the view tree. The runtime diffs consecutive trees to produce patches sent to the renderer.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/plushie/node.rb', line 24 Node = Data.define(:id, :type, :props, :children, :meta) do # Create a new Node with string-coerced id and type, and frozen props/children/meta. # # @param id [#to_s] unique widget identifier # @param type [#to_s] widget type name # @param props [Hash] widget properties (will be frozen) # @param children [Array<Node>] child nodes (will be frozen) # @param meta [Hash] runtime-only metadata, never sent to the renderer (will be frozen) # @return [Node] def initialize(id:, type:, props: {}, children: [], meta: {}) raise ArgumentError, "Node id cannot be nil" if id.nil? raise ArgumentError, "Node type cannot be nil" if type.nil? super(id: id.to_s, type: type.to_s, props: props.freeze, children: children.freeze, meta: .freeze) end # Return a new Node with the given fields replaced. # Unspecified fields retain their current values. # # @param changes [Hash] fields to replace (:id, :type, :props, :children, :meta) # @return [Node] new Node with the changes applied def with(**changes) self.class.new(**to_h.merge(changes)) end end |
#type ⇒ Object (readonly)
Returns the value of attribute type
24 25 26 |
# File 'lib/plushie/node.rb', line 24 def type @type end |
#type [String] widget type name ("button", "column", "text_input", etc.)([String]("button", "column", "text_input", etc.)) ⇒ Object (readonly)
A UI tree node. Produced by DSL methods and widget builders.
Nodes are immutable value objects representing a single widget in the view tree. The runtime diffs consecutive trees to produce patches sent to the renderer.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/plushie/node.rb', line 24 Node = Data.define(:id, :type, :props, :children, :meta) do # Create a new Node with string-coerced id and type, and frozen props/children/meta. # # @param id [#to_s] unique widget identifier # @param type [#to_s] widget type name # @param props [Hash] widget properties (will be frozen) # @param children [Array<Node>] child nodes (will be frozen) # @param meta [Hash] runtime-only metadata, never sent to the renderer (will be frozen) # @return [Node] def initialize(id:, type:, props: {}, children: [], meta: {}) raise ArgumentError, "Node id cannot be nil" if id.nil? raise ArgumentError, "Node type cannot be nil" if type.nil? super(id: id.to_s, type: type.to_s, props: props.freeze, children: children.freeze, meta: .freeze) end # Return a new Node with the given fields replaced. # Unspecified fields retain their current values. # # @param changes [Hash] fields to replace (:id, :type, :props, :children, :meta) # @return [Node] new Node with the changes applied def with(**changes) self.class.new(**to_h.merge(changes)) end end |
Instance Method Details
#with(**changes) ⇒ Node
Return a new Node with the given fields replaced. Unspecified fields retain their current values.
44 45 46 |
# File 'lib/plushie/node.rb', line 44 def with(**changes) self.class.new(**to_h.merge(changes)) end |