πŸ“•[μ±…] 쏙쏙 λ“€μ–΄μ˜€λŠ” ν•¨μˆ˜ν˜• μ½”λ”© - 45,46

rivolt0421Β·2023λ…„ 5μ›” 11일
1

πŸ“•μ±…

λͺ©λ‘ 보기
25/26

514p ~ 534p

μš”μ•½

λ°˜μ‘ν˜• μ•„ν‚€ν…μ²˜

원인과 효과λ₯Ό λΆ„λ¦¬ν•˜μ—¬ μ„€κ³„ν•œλ‹€.
원인(X)이 λ°œμƒν•˜λ©΄ μ–Έμ œλ‚˜ 효과(Y)λ₯Ό μΌμœΌν‚¨λ‹€.
데이터 λ³€ν™˜ 단계λ₯Ό νŒŒμ΄ν”„λΌμΈμœΌλ‘œ κ΅¬μ„±ν•˜μ—¬ μ²˜λ¦¬ν•œλ‹€.
계산을 μ‘°ν•©ν•˜μ—¬ λ³΅μž‘ν•œ λ™μž‘μ„ λ§Œλ“€ 수 μžˆλ‹€.

μ–΄λ‹ˆμ–Έ μ•„ν‚€ν…μ²˜

μ½”λ“œμ˜ 결합도와 응집도λ₯Ό κ΄€λ¦¬ν•˜κΈ° μœ„ν•΄ μ‚¬μš©ν•œλ‹€.
λ™μΌν•œ 효과λ₯Ό μ—¬λŸ¬ κ΅°λ°μ—μ„œ μ‚¬μš©ν•˜λŠ” 경우, ν•˜λ‚˜μ˜ ꡰ데둜 κ²°ν•©ν•˜μ—¬ 쀑볡을 쀄일 수 μžˆλ‹€.
원인과 효과의 쀑심을 λΆ„λ¦¬ν•˜μ—¬ μœ μ§€λ³΄μˆ˜μ„±μ„ ν–₯μƒμ‹œν‚¨λ‹€.
단일 이벀트 λŒ€μ‹  데이터 μŠ€νŠΈλ¦Όμ„ μ‚¬μš©ν•˜λŠ” 경우, RX(λ°˜μ‘ν˜• ν™•μž₯ 라이브러리)λ₯Ό ν™œμš©ν•  수 μžˆλ‹€.
μ™ΈλΆ€ 슀트림 μ„œλΉ„μŠ€(Kafka, RabbitMQ λ“±)λ₯Ό μ‚¬μš©ν•˜μ—¬ νŒŒμ΄ν”„λΌμΈμ„ κ΅¬ν˜„ν•  수 μžˆλ‹€.

Cell

function ValueCell(initialValue) {
  let currentValue = initialValue;
  return {
    val: () => {
      return currentValue;
    },
    update: (f) => {
      const oldValue = currentValue;
      const newValue = f(oldValue);
      currentValue = newValue;
    },
  };
}

cell = ValueCell(1);
console.log(cell.val());
cell.update((x) => x + 1);
console.log(cell.val());


1
2

κ°μ‹œμž <Watcher, Observer, listener, eventHandler, callback>

function ValueCell(initialValue) {
  let currentValue = initialValue;
  let watchers = [];
  return {
    val: () => {
      return currentValue;
    },
    update: (f) => {
      const oldValue = currentValue;
      const newValue = f(oldValue);
      if (oldValue !== newValue) {
        currentValue = newValue;
        watchers.forEach((watcher) => watcher(newValue));
      }
    },
    addWatcher: (f) => {
      watchers.push(f);
    },
  };
}

cell = ValueCell(1);
console.log(cell.val());
cell.update((x) => x + 1);
console.log(cell.val());

cell.addWatcher((x) => console.log('watcher1', x));
cell.addWatcher((x) => console.log('watcher2', x));

cell.update((x) => x + 1);

1
2
watcher1 3
watcher2 3

FormulaCell은 νŒŒμƒλœ 값을 κ³„μ‚°ν•œλ‹€.
λ‹€λ₯Έμ…€μ˜ λ³€ν™”κ°€ κ°μ§€λ˜λ©΄ 값을 λ‹€μ‹œ κ³„μ‚°ν•œλ‹€.

function ValueCell(initialValue) {
  let currentValue = initialValue;
  let watchers = [];
  return {
    val: () => {
      return currentValue;
    },
    update: (f) => {
      const oldValue = currentValue;
      const newValue = f(oldValue);
      if (oldValue !== newValue) {
        currentValue = newValue;
        watchers.forEach((watcher) => watcher(newValue));
      }
    },
    addWatcher: (f) => {
      watchers.push(f);
    },
  };
}

function FormulaCell(upstreamCell, f) {
  //계산을 ν•œ 값을 μ΄ˆκΈ°κ°’μœΌλ‘œ μ„ΈνŒ…
  let myCell = ValueCell(f(upstreamCell.val()));

  upstreamCell.addWatcher((newUpstreamValue) => {
    myCell.update((currentValue) => {
      return f(newUpstreamValue);
    });
  });
  return {
    val: myCell.val,
    addWatcher: myCell.addWatcher,
  };
}

// A1 셀에 2λ₯Ό μ„ΈνŒ…ν•˜κ³ , A2 셀에 3을 μ„ΈνŒ…ν•©λ‹ˆλ‹€.
let A1 = ValueCell(2);
let A2 = FormulaCell(A1, (a) => a + 3);

console.log(A1.val()); // 2
console.log(A2.val()); // 5

// A1 μ…€μ˜ 값을 5둜 λ³€κ²½ν•©λ‹ˆλ‹€.
A1.update(() => 5);

console.log(A1.val()); // 5
console.log(A2.val()); // 8

// B1 셀에 4λ₯Ό μ„ΈνŒ…ν•˜κ³ , B2 셀에 B1 μ…€μ˜ 값에 2λ₯Ό κ³±ν•˜λŠ” 계산식을 μ„€μ •ν•©λ‹ˆλ‹€.
let B1 = ValueCell(4);
let B2 = FormulaCell(B1, (b) => b * 2);

console.log(B1.val()); // 4
console.log(B2.val()); // 8

// B1 μ…€μ˜ 값을 6으둜 λ³€κ²½ν•©λ‹ˆλ‹€.
B1.update(() => 6);

console.log(B1.val()); // 6
console.log(B2.val()); // 12

발췌

λ©”λͺ¨

차후에 더 정리해야 ν•œλ‹€.

profile
I think I think too much.

2개의 λŒ“κΈ€

comment-user-thumbnail
2023λ…„ 5μ›” 16일

였였... 벌써 λ‹€ μ½μ–΄κ°€λ„€μš” γ…‹γ…‹γ…‹ πŸ‘πŸ‘πŸ‘

1개의 λ‹΅κΈ€