Sha256: d631ca767b28150894f614d64c6a53ee07e311002d95a286e332fb38d28964a4

Contents?: true

Size: 725 Bytes

Versions: 42

Compression:

Stored size: 725 Bytes

Contents

class String
  include ReactiveTags
  
  alias :__old_plus :+
  if RUBY_PLATFORM != 'opal'
    alias :__old_concat :<<
  end
  # alias :concat :__old_concat

  # In volt, we want a value + reactive strings to return a reactive string.  So we
  # over-ride + to check for when we are adding a reactive string to a string.
  def +(val)
    result = __old_plus(val.cur)
    if val.reactive? && !result.reactive?
      result = ReactiveValue.new(result)
    end
  
    return result
  end

  if RUBY_PLATFORM != 'opal'
    def <<(val)
      if val.reactive?
        raise "Cannot append a reactive string to non-reactive string.  Use + instead"
      end
      result = __old_concat(val)
  
      return result
    end
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
volt-0.3.9 lib/volt/reactive/string_extensions.rb
volt-0.3.8 lib/volt/reactive/string_extensions.rb