From 3464e50b2f7acbfc9daa3e0fb98006f8de68cfe8 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 26 Jul 2015 09:04:34 +0300 Subject: [PATCH] better block view --- app/block_view.rb | 25 +++++++++++++++++-------- app/register_view.rb | 2 ++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/app/block_view.rb b/app/block_view.rb index 170a53c..74f274c 100644 --- a/app/block_view.rb +++ b/app/block_view.rb @@ -7,26 +7,35 @@ class BlockView include React::Component required_param :interpreter - define_state :block + define_state :block => [] + define_state :block_name => "" before_mount do - interpreter.register_event(:block_changed, self) - block! interpreter.block + interpreter.register_event(:instruction_changed, self) + update_block end - def block_changed old , bl - block! bl + def update_block + block_name! interpreter.block.name + codes = interpreter.block.codes.dup + codes.shift while( codes.index(interpreter.instruction) > 1 ) + codes.pop while(codes.length > 4) + block! codes + end + + def instruction_changed + update_block end def render return unless block div.row do div.col_md_5 do - SourceView :source => block.codes.first.source + SourceView :source => interpreter.instruction.source end div.col_md_5 do - h6 { "Block: #{block.name}"} - block.codes.each do |code| + h6 { "Block: #{block_name}"} + block.each do |code| InstructionView :interpreter => interpreter , :instruction => code end end diff --git a/app/register_view.rb b/app/register_view.rb index 61aa8f4..4e80a95 100644 --- a/app/register_view.rb +++ b/app/register_view.rb @@ -27,6 +27,8 @@ class RegisterView end object.get_instance_variables.each do |variable| div.col_md_12 do + ## deal with String + ## even better, make ObjectView object.get_instance_variable(variable).to_s.span end end