Archived
1
0
Fork 0

Remove unnecessary code

This commit is contained in:
Braiden Vasco 2017-07-31 03:43:48 +00:00
parent e3a829b961
commit 621568abdd
3 changed files with 4 additions and 48 deletions

View file

@ -2,53 +2,21 @@
module React module React
class Component class Component
def initialize(parent) def initialize
self.parent = parent self.props = {}.freeze
@props = {}.freeze
end end
def props=(value) def props=(value)
raise TypeError, "expected props to be a #{Hash}" unless value.is_a? Hash raise TypeError, "expected props to be a #{Hash}" unless value.is_a? Hash
raise ArgumentError, 'expected props to be frozen' unless value.frozen? 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 @props = value
end end
def trigger(event); end def trigger(event); end
def draw
render
window.refresh
end
private private
attr_reader :parent, :props attr_reader :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
def create_element(type, props = {}, &block) def create_element(type, props = {}, &block)
Element.create type, props, &block Element.create type, props, &block

View file

@ -5,7 +5,7 @@ module React
module Nodes module Nodes
class Component < Base class Component < Base
def instance def instance
result = element.type.new nil result = element.type.new
result.props = props result.props = props
result result
end end

View file

@ -2,22 +2,10 @@
module Widgets module Widgets
class Container < React::Component class Container < React::Component
def subwin(x, y, width, height)
window.subwin height, width, y, x
end
private private
def render
children.each(&:draw)
end
def focus def focus
raise NotImplementedError, "#{self.class}#focus" raise NotImplementedError, "#{self.class}#focus"
end end
def children
raise NotImplementedError, "#{self.class}#children"
end
end end
end end