From 7e34ae003e6c3693be3b14a5e5fad122fd96fcf8 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Mon, 27 Jul 2015 12:09:35 +0300 Subject: [PATCH] integrating the sources to views --- app/block_view.rb | 2 +- app/source_view.rb | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/app/block_view.rb b/app/block_view.rb index 49ae27b..bae7d4f 100644 --- a/app/block_view.rb +++ b/app/block_view.rb @@ -18,7 +18,7 @@ class BlockView def update_block block_name! interpreter.block.name codes = interpreter.block.codes.dup - slice = codes.index(interpreter.instruction) - 1 + slice = codes.index(interpreter.instruction) #- 1 codes.shift( slice ) if slice >= 0 codes.pop while(codes.length > 4) block! codes diff --git a/app/source_view.rb b/app/source_view.rb index d5fabbb..8ec5fd4 100644 --- a/app/source_view.rb +++ b/app/source_view.rb @@ -2,13 +2,30 @@ class SourceView include React::Component - required_param :source, type: Virtual::Instruction + required_param :source + define_state :sources => [] + + before_update do + text = source_text(source) + return if sources.last == text + sources << text + sources.shift if sources.length > 5 + end def render div.row do "Virtual Machine Instruction".br - source.class.name + sources.each do |s| + s.br + end end end + def source_text + if source.is_a? Virtual::Instruction + return source.class.name + else + return "Method: #{source.name}" + end + end end