Class: Phlex::Reactive::Component::CollectionDefinition

Inherits:
Data
  • Object
show all
Defined in:
lib/phlex/reactive/component.rb

Overview

A declared add/remove-row collection (issue #35): the list contract tied into one unit — the per-row item component, the container DOM id rows live in, an optional companion count id, an optional empty-state component, and a size resolver (a proc evaluated against the container instance) used to re-render the count and toggle the empty-state at the 0<->1 boundary. count/empty/size are nil when not declared, and the corresponding stream is simply omitted — so a list with just rows still works.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#containerObject (readonly)

Returns the value of attribute container

Returns:

  • (Object)

    the current value of container



104
105
106
# File 'lib/phlex/reactive/component.rb', line 104

def container
  @container
end

#countObject (readonly)

Returns the value of attribute count

Returns:

  • (Object)

    the current value of count



104
105
106
# File 'lib/phlex/reactive/component.rb', line 104

def count
  @count
end

#emptyObject (readonly)

Returns the value of attribute empty

Returns:

  • (Object)

    the current value of empty



104
105
106
# File 'lib/phlex/reactive/component.rb', line 104

def empty
  @empty
end

#itemObject (readonly)

Returns the value of attribute item

Returns:

  • (Object)

    the current value of item



104
105
106
# File 'lib/phlex/reactive/component.rb', line 104

def item
  @item
end

#nameObject (readonly)

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



104
105
106
# File 'lib/phlex/reactive/component.rb', line 104

def name
  @name
end

#sizeObject (readonly)

Returns the value of attribute size

Returns:

  • (Object)

    the current value of size



104
105
106
# File 'lib/phlex/reactive/component.rb', line 104

def size
  @size
end

Instance Method Details

#size_for(component) ⇒ Object

The collection's current size, evaluated against the bound container instance (instance_exec so the proc reads the component's ivars / association). nil when no resolver was declared — callers skip the count/empty streams that need a number.



109
110
111
# File 'lib/phlex/reactive/component.rb', line 109

def size_for(component)
  size && component.instance_exec(&size)
end