Sha256: c494d111ffa0948146546f389283eae97f39d9481c1af873415623c5948bd4df

Contents?: true

Size: 775 Bytes

Versions: 13

Compression:

Stored size: 775 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'
    tag_method(:<<) do
      destructive!
    end
    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

13 entries across 13 versions & 1 rubygems

Version Path
volt-0.3.7 lib/volt/reactive/string_extensions.rb
volt-0.3.6 lib/volt/reactive/string_extensions.rb
volt-0.3.5 lib/volt/reactive/string_extensions.rb
volt-0.3.4 lib/volt/reactive/string_extensions.rb
volt-0.3.3 lib/volt/reactive/string_extensions.rb
volt-0.3.2 lib/volt/reactive/string_extensions.rb
volt-0.3.1 lib/volt/reactive/string_extensions.rb
volt-0.3.0 lib/volt/reactive/string_extensions.rb
volt-0.2.9 lib/volt/reactive/string_extensions.rb
volt-0.2.7 lib/volt/reactive/string_extensions.rb
volt-0.2.5 lib/volt/reactive/string_extensions.rb
volt-0.2.4 lib/volt/reactive/string_extensions.rb
volt-0.2.3 lib/volt/reactive/string_extensions.rb