wishthis/node_modules/rxjs/dist/esm/internal/operators/sample.js

23 lines
820 B
JavaScript
Raw Normal View History

2023-02-08 12:35:10 +00:00
import { innerFrom } from '../observable/innerFrom';
2022-06-08 10:36:39 +00:00
import { operate } from '../util/lift';
import { noop } from '../util/noop';
import { createOperatorSubscriber } from './OperatorSubscriber';
export function sample(notifier) {
return operate((source, subscriber) => {
let hasValue = false;
let lastValue = null;
source.subscribe(createOperatorSubscriber(subscriber, (value) => {
hasValue = true;
lastValue = value;
}));
2023-02-08 12:35:10 +00:00
innerFrom(notifier).subscribe(createOperatorSubscriber(subscriber, () => {
2022-06-08 10:36:39 +00:00
if (hasValue) {
hasValue = false;
const value = lastValue;
lastValue = null;
subscriber.next(value);
}
}, noop));
});
}
//# sourceMappingURL=sample.js.map