rubyx-debugger/app/block_view.rb

49 lines
1.0 KiB
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.row do
div.col_md_5 do
2015-07-26 08:04:34 +02:00
SourceView :source => interpreter.instruction.source
end
div.col_md_5 do
2015-07-26 08:04:34 +02:00
h6 { "Block: #{block_name}"}
block.each do |code|
2015-07-25 14:28:59 +02:00
InstructionView :interpreter => interpreter , :instruction => code
end
2015-07-22 21:05:31 +02:00
end
div.col_md_2 do
button.btn.btn_default { "next" }.on(:click) { interpreter.tick }
end
2015-07-22 21:05:31 +02:00
end
end
end