material-motion
Version:
Makes it easy to add rich, interactive motion to your application.
52 lines • 2.55 kB
JavaScript
/** @license
* 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 * as tslib_1 from "tslib";
import { MotionObservable, } from '../../observables/proxies';
import { combineLatest, } from '../../combineLatest';
export function withReactiveNextOperator(superclass) {
return class extends superclass {
/**
* Similar to `_nextOperator`, but listens for values not just from
* upstream, but also on any arguments it receives.
*
* It calls `operation` with the most recent values from upstream and from
* the other arguments. Arguments that aren't reactive will be passed
* through as-they-are. Arguments that are reactive will cause `operation`
* to be called again for each value they emit.
*
* `_reactiveNextOperator` will not call `operation` until it has received
* a value from every argument it is subscribed to.
*/
_reactiveNextOperator(_a) {
var { operation, inputs } = _a, combineLatestOptions = tslib_1.__rest(_a, ["operation", "inputs"]);
return new MotionObservable((observer) => {
const innerOperation = operation({
emit: observer.next.bind(observer),
});
// TODO: verify this is the correct type.
//
// I added `{upstream: Observable<T>}` because otherwise `inputs` was
// getting inferred to require an `upstream` at a callsite. This
// appears to fix it, but I haven't taken the time to reason if it's
// correct.
return combineLatest(
// TypeScript doesn't like ...inputs, so we use the longhand version
Object.assign({ upstream: this }, inputs), combineLatestOptions).subscribe(innerOperation).unsubscribe;
});
}
};
}
//# sourceMappingURL=_reactiveNextOperator.js.map