snaag / TIL

https://github.com/snaag/todo3/issues
3 stars 0 forks source link

22-03-13-SUN #5

Open snaag opened 2 years ago

snaag commented 2 years ago
snaag commented 2 years ago

operators

snaag commented 2 years ago

Log

1. debounceTime(N)

image

print('✅ debounceTime');
clicks$.pipe(
  debounceTime(1000)
).subscribe(x => print('OUTPUT: -------- ' + x))

2. auditTime(N)

image

print('✅ auditTime');
clicks$.pipe(
    auditTime(3000)
).subscribe(x => print('OUTPUT: -------- ' + x))

3. sampleTime(N)

image

print('✅ sampleTime');
clicks$.pipe(
    sampleTime(2000),
).subscribe(x => print('OUTPUT: -------- ' + x))

4-1. throttleTime(N, scheduler, { leading: true, trailing: false})

image

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 🔚

4-2. throttleTime(N, scheduler, { leading: false, trailing: true})

image

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 🔚
snaag commented 2 years ago

auditTime, sampleTime 차이 => 타이머

image image

snaag commented 2 years ago

auditTime 과 throttleTime (trailing: true) 의 차이

image image