This repository has been archived by the owner on Aug 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ignoreUntil and simplified slop
Summary: Fixed #87 and #86 Reviewers: O2 Material Motion, O4 Material Apple platform reviewers, #material_motion, featherless Reviewed By: O2 Material Motion, O4 Material Apple platform reviewers, #material_motion, featherless Subscribers: featherless Tags: #material_motion Differential Revision: http://codereview.cc/D3170
- Loading branch information
1 parent
27edf6b
commit 86bf12b
Showing
4 changed files
with
78 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
Copyright 2016-present The Material Motion Authors. All Rights Reserved. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import UIKit | ||
|
||
extension MotionObservableConvertible where T: Equatable { | ||
/** | ||
Ignores values from upstream until the expected value is received, at which point it emits | ||
that value and all further values without modification. | ||
*/ | ||
public func ignoreUntil(_ expected: T) -> MotionObservable<T> { | ||
var shouldSend = false | ||
return _filter() { value in | ||
if value == expected { | ||
shouldSend = true | ||
} | ||
return shouldSend | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
Copyright 2017-present The Material Motion Authors. All Rights Reserved. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import XCTest | ||
import IndefiniteObservable | ||
import MaterialMotion | ||
|
||
class ignoreUntilTest: XCTestCase { | ||
func testIgnoreUntil() { | ||
|
||
let input = [20, 10, 60, 50, 10, 20, 80] | ||
let expected = [50, 10, 20, 80] | ||
let observable = MotionObservable<Int> { observer in | ||
for i in input { | ||
observer.next(i) | ||
} | ||
return noopDisconnect | ||
} | ||
|
||
var values: [Int] = [] | ||
observable.ignoreUntil(50).subscribeToValue { | ||
values.append($0) | ||
} | ||
XCTAssertEqual(values, expected) | ||
} | ||
} |