Remove unnecessary code
This commit is contained in:
parent
e3a829b961
commit
621568abdd
3 changed files with 4 additions and 48 deletions
|
@ -2,53 +2,21 @@
|
|||
|
||||
module React
|
||||
class Component
|
||||
def initialize(parent)
|
||||
self.parent = parent
|
||||
@props = {}.freeze
|
||||
def initialize
|
||||
self.props = {}.freeze
|
||||
end
|
||||
|
||||
def props=(value)
|
||||
raise TypeError, "expected props to be a #{Hash}" unless value.is_a? Hash
|
||||
raise ArgumentError, 'expected props to be frozen' unless value.frozen?
|
||||
|
||||
@window = nil if props[:x] != value[:x] || props[:y] != value[:y] ||
|
||||
props[:width] != value[:width] || props[:height] != value[:height]
|
||||
|
||||
@props = value
|
||||
end
|
||||
|
||||
def trigger(event); end
|
||||
|
||||
def draw
|
||||
render
|
||||
window.refresh
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
attr_reader :parent, :props
|
||||
|
||||
def parent=(value)
|
||||
return if value.nil?
|
||||
raise TypeError, "expected #parent to be a #{Component}" unless value.is_a? Component
|
||||
@parent = value
|
||||
end
|
||||
|
||||
def window
|
||||
@window ||= parent&.subwin(props[:x], props[:y], props[:width], props[:height]) || ::Curses.stdscr
|
||||
end
|
||||
|
||||
def render
|
||||
raise NotImplementedError, "#{self.class}#render"
|
||||
end
|
||||
|
||||
def setpos(x, y)
|
||||
window.setpos y, x
|
||||
end
|
||||
|
||||
def addstr(s)
|
||||
window.addstr s
|
||||
end
|
||||
attr_reader :props
|
||||
|
||||
def create_element(type, props = {}, &block)
|
||||
Element.create type, props, &block
|
||||
|
|
|
@ -5,7 +5,7 @@ module React
|
|||
module Nodes
|
||||
class Component < Base
|
||||
def instance
|
||||
result = element.type.new nil
|
||||
result = element.type.new
|
||||
result.props = props
|
||||
result
|
||||
end
|
||||
|
|
|
@ -2,22 +2,10 @@
|
|||
|
||||
module Widgets
|
||||
class Container < React::Component
|
||||
def subwin(x, y, width, height)
|
||||
window.subwin height, width, y, x
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def render
|
||||
children.each(&:draw)
|
||||
end
|
||||
|
||||
def focus
|
||||
raise NotImplementedError, "#{self.class}#focus"
|
||||
end
|
||||
|
||||
def children
|
||||
raise NotImplementedError, "#{self.class}#children"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Reference in a new issue