Skip to content

Commit a41f004

Browse files
author
Guido Marucci Blas
committed
Fixes Wolox#10
ReactiveArray#observableCount was always sending 0 as the first value even in the case were the array was initialized with a non-empty array.
1 parent 5fd4657 commit a41f004

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

ReactiveArray/ReactiveArray.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public final class ReactiveArray<T>: CollectionType, MutableCollectionType, Debu
4040
return appendCurrentElements |> concat(forwardOperations)
4141
}
4242

43-
private let _mutableCount = MutableProperty<Int>(0)
43+
private let _mutableCount: MutableProperty<Int>
4444
public let observableCount:PropertyOf<Int>
4545

4646
public var isEmpty: Bool {
@@ -79,6 +79,7 @@ public final class ReactiveArray<T>: CollectionType, MutableCollectionType, Debu
7979

8080
public init(elements:[T]) {
8181
_elements = elements
82+
_mutableCount = MutableProperty(elements.count)
8283
observableCount = PropertyOf(_mutableCount)
8384

8485
_signal.observe { [unowned self](operation) in

ReactiveArrayTests/ReactiveArraySpec.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,11 +396,21 @@ class ReactiveArraySpec: QuickSpec {
396396

397397
beforeEach {
398398
countBeforeOperation = array.count
399-
producer = array.observableCount.producer |> skip(1)
399+
producer = array.observableCount.producer
400+
}
401+
402+
it("returns the initial amount of elements in the array") {
403+
producer.start(next: { count in
404+
expect(count).to(equal(countBeforeOperation))
405+
})
400406
}
401407

402408
context("when an insert operation is executed") {
403409

410+
beforeEach {
411+
producer = producer |> skip(1)
412+
}
413+
404414
it("does not update the count") {
405415
waitUntil { done in
406416
producer
@@ -421,6 +431,10 @@ class ReactiveArraySpec: QuickSpec {
421431

422432
context("when an append operation is executed") {
423433

434+
beforeEach {
435+
producer = producer |> skip(1)
436+
}
437+
424438
it("updates the count") {
425439
waitUntil { done in
426440
producer |> start(next: { count in
@@ -436,6 +450,10 @@ class ReactiveArraySpec: QuickSpec {
436450

437451
context("when a delete operation is executed") {
438452

453+
beforeEach {
454+
producer = producer |> skip(1)
455+
}
456+
439457
it("updates the count") {
440458
waitUntil { done in
441459
producer |> start(next: { count in

0 commit comments

Comments
 (0)