Module: Knockout::ObservableArray

Defined in:
lib/opal/knockout/observable_array.rb

Instance Method Summary collapse

Instance Method Details

#destroy(item) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/opal/knockout/observable_array.rb', line 50

def destroy(item)
  if item.is_a? Array
    `#{self}.destroyAll(#{item})`
  else
    `#{self}.destroy(#{item})`
  end
end

#destroy_allObject



66
67
68
# File 'lib/opal/knockout/observable_array.rb', line 66

def destroy_all
  `#{self}.destroyAll()`
end

#destroy_if(&block) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/opal/knockout/observable_array.rb', line 58

def destroy_if(&block)
  %x{
    #{self}.destroy(function(item) {
      return #{block.call(`item`)};
    });
  }
end

#index_of(str) ⇒ Object



70
71
72
# File 'lib/opal/knockout/observable_array.rb', line 70

def index_of(str)
  `#{self}.indexOf(#{str})`
end

#popObject



16
17
18
# File 'lib/opal/knockout/observable_array.rb', line 16

def pop
  `#{self}.pop()`
end

#push(item) ⇒ Object



12
13
14
# File 'lib/opal/knockout/observable_array.rb', line 12

def push(item)
  `#{self}.push(#{item})`
end

#remove(item) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/opal/knockout/observable_array.rb', line 28

def remove(item)
  if item.is_a? Array
    `#{self}.removeAll(#{item})`
  else
    `#{self}.remove(#{item})`
  end
end

#remove_allObject Also known as: clear



44
45
46
# File 'lib/opal/knockout/observable_array.rb', line 44

def remove_all
  `#{self}.removeAll()`
end

#remove_if(&block) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/opal/knockout/observable_array.rb', line 36

def remove_if(&block)
  %x{
    #{self}.remove(function(item) {
      return #{block.call(`item`)};
    });
  }
end

#reverseObject



24
25
26
# File 'lib/opal/knockout/observable_array.rb', line 24

def reverse
  `#{self}.reverse()`
end

#shiftObject



20
21
22
# File 'lib/opal/knockout/observable_array.rb', line 20

def shift
  `#{self}.shift()`
end

#sizeObject



4
5
6
# File 'lib/opal/knockout/observable_array.rb', line 4

def size
  self.to_a.size
end

#slice(_start = 0, _end = nil) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/opal/knockout/observable_array.rb', line 74

def slice(_start=0, _end=nil)
  if _end.nil?
    `#{self}.slice(#{_start})`
  else
    `#{self}.slice(#{_start}, #{_end})`
  end
end

#to_aObject



8
9
10
# File 'lib/opal/knockout/observable_array.rb', line 8

def to_a
  self.call
end