rubyx-debugger/app/block_view.rb

44 lines
916 B
Ruby
Raw Normal View History

2015-07-22 21:05:31 +02:00
require "source_view"
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
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
h4 {"Block: #{block_name}"}
button.btn.btn_default { "next" }.on(:click) { interpreter.tick }
end
block.each do |code|
InstructionView :interpreter => interpreter , :instruction => code
end
2015-07-22 21:05:31 +02:00
end
end
end