From 621568abddbf8da5f0fe642c068d81dbcf623089 Mon Sep 17 00:00:00 2001 From: Braiden Vasco Date: Mon, 31 Jul 2017 03:43:48 +0000 Subject: [PATCH] Remove unnecessary code --- lib/react/component.rb | 38 +++-------------------------- lib/react/curses/nodes/component.rb | 2 +- lib/widgets/container.rb | 12 --------- 3 files changed, 4 insertions(+), 48 deletions(-) diff --git a/lib/react/component.rb b/lib/react/component.rb index fedae4a..9b21ae9 100644 --- a/lib/react/component.rb +++ b/lib/react/component.rb @@ -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 diff --git a/lib/react/curses/nodes/component.rb b/lib/react/curses/nodes/component.rb index 64d0cf3..387917d 100644 --- a/lib/react/curses/nodes/component.rb +++ b/lib/react/curses/nodes/component.rb @@ -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 diff --git a/lib/widgets/container.rb b/lib/widgets/container.rb index b63858c..e19ded2 100644 --- a/lib/widgets/container.rb +++ b/lib/widgets/container.rb @@ -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