rubyx-debugger/app/block_view.rb

50 lines
1.0 KiB
Ruby
Raw Normal View History

2015-07-22 21:05:31 +02:00
2015-07-25 14:28:59 +02:00
require "instruction_view"
2015-07-22 21:05:31 +02:00
class BlockView
include React::Component
2015-07-23 19:08:40 +02:00
required_param :interpreter
2015-07-22 21:05:31 +02:00
2015-07-26 08:04:34 +02:00
define_state :block => []
define_state :block_name => ""
before_mount do
2015-07-26 08:04:34 +02:00
interpreter.register_event(:instruction_changed, self)
update_block
end
2015-07-26 08:04:34 +02:00
def update_block
2015-07-28 15:16:09 +02:00
return unless interpreter.instruction
2015-07-26 08:04:34 +02:00
block_name! interpreter.block.name
codes = interpreter.block.codes.dup
2015-07-27 11:09:35 +02:00
slice = codes.index(interpreter.instruction) #- 1
codes.shift( slice ) if slice >= 0
2015-07-26 08:04:34 +02:00
codes.pop while(codes.length > 4)
block! codes
end
def instruction_changed
update_block
end
2015-07-22 21:05:31 +02:00
def render
return unless block
div.block_view do
div do
2015-07-28 15:16:09 +02:00
h4 { method_name}
h4 {"Block: #{block_name}"}
end
block.each do |code|
InstructionView :interpreter => interpreter , :instruction => code
end
2015-07-22 21:05:31 +02:00
end
end
2015-07-28 15:16:09 +02:00
def method_name
bl = interpreter.block
return bl.method if bl.method.is_a? String
"#{bl.method.for_class.name}.#{bl.method.name}"
end
2015-07-22 21:05:31 +02:00
end