Open snaag opened 2 years ago
print('✅ debounceTime');
clicks$.pipe(
debounceTime(1000)
).subscribe(x => print('OUTPUT: -------- ' + x))
print('✅ auditTime');
clicks$.pipe(
auditTime(3000)
).subscribe(x => print('OUTPUT: -------- ' + x))
print('✅ sampleTime');
clicks$.pipe(
sampleTime(2000),
).subscribe(x => print('OUTPUT: -------- ' + x))
leading: true
print('✅ throttleTime (leading: true)');
clicks$.pipe(
throttleTime(1000, undefined, {
leading: true, trailing: false
})
).subscribe(x => print('OUTPUT: -------- ' + x))
# ⏰: 타이머 시작
# 🔚: 타이머 종료
# ⭕️: 살았음
# ❌: 무시됨
# clicked: 695 ⏰ ⭕️
# OUTPUT: -------- 695 🔚
# clicked: 1043 ❌
# clicked: 1392 ❌
# clicked: 1741 ❌
# clicked: 1988 ❌
# clicked: 2293 ⏰ ⭕️
# OUTPUT: -------- 2293 🔚
# clicked: 4035 ⏰ ⭕️
# OUTPUT: -------- 4035 🔚
# clicked: 4407 ❌
# clicked: 4744 ❌
# clicked: 4991 ❌
# clicked: 7669 ⏰ ⭕️
# OUTPUT: -------- 7669 🔚
print('✅ throttleTime (trailing: true)');
clicks$.pipe(
throttleTime(1500, undefined, {
leading: false, trailing: true
})
).subscribe(x => print('OUTPUT: -------- ' + x))
# clicked: 921 ⏰
# clicked: 1641 ❌
# clicked: 2215 ⭕️
# OUTPUT: -------- 2215 🔚
# clicked: 2823 ⏰
# clicked: 3385 ❌
# clicked: 3824 ⭕️
# OUTPUT: -------- 3824 🔚
# clicked: 4228 ⏰
# clicked: 4769 ❌
# clicked: 5252 ⭕️
# OUTPUT: -------- 5252 🔚
# clicked: 5701 ⏰
# clicked: 6231 ❌
# clicked: 6715 ⭕️
# OUTPUT: -------- 6715 🔚
auditTime
: 발행물을 발행한 이후부터 타이머 잼sampleTime
: 발행물과 무관하게 타이머는 계속 돌아감. auditTime
: 마지막 발행물만 발행됨sampleTime
:
각 발행물의 발행 시간이, (발행물과 무관하게 돌리고있는 타이머 기준으로) 1초 내에 있다면 마지막 발행물이 발행되고,
1초 뒤에 있다면 두 발행물 모두 발행됨