Skip to content

Commit 185b24a

Browse files
author
Steve Krouse
committed
small frp essay edits
1 parent 7722af2 commit 185b24a

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

drafts/frp.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ Note on the word "module": In his example above, Staltz uses JavaScript files as
4545

4646
Staltz understates the non-modularity of the Interactive pattern. Let's say you wish to understand the behavior of X. You grep for `X.update` in all modules. For each module `X.update` appears in, you have to go to the call site(s) and understand that module well enough to know what triggers that line of code, and the value of the arguments it will pass in. If you're lucky, all that information is self-contained, but you'll likely be forced to understand yet more modules to understand how *this* module affects X.
4747

48-
The Interactive Pattern, representative of most JavaScript UI frameworks, is not modularly comprehensible, because data dependencies are implicit, because the language permits side-effects, such as mutable state, which allows `bar.updateSomething(someValue);`.
49-
50-
The Reactive Pattern is modularly comprehensibility because it enforces explicit dependencies, by disallowing side-effects.
51-
5248
Consider the program `A` of the Reactive Pattern, which is explicitly defined in terms of its modules. In this picture read an arrow from B to A as "A is defined in terms of B."
5349

5450
<iframe width="500" height="300" src="https://mermaidjs.github.io/mermaid-live-editor/#/view/eyJjb2RlIjoiXG5ncmFwaCBCVFxuICAgIFxuQi0tPkFcbkMtLT5BXG5ELS0-QVxuRS0tPkFcbkYtLT5CXG5HLS0-QlxuSC0tPkJcbkktLT5DXG5KLS0-Q1xuSy0tPkRcbkwtLT5FXG5NLS0-RVxuTi0tPkVcbk8tLT5FXG5LLS0-TlxuUS0tPk5cbiIsIm1lcm1haWQiOnsidGhlbWUiOiJkZWZhdWx0In19" frameborder="0" allowfullscreen></iframe>
@@ -59,9 +55,11 @@ If you want to understand a module, you have to understand the modules it's defi
5955

6056
This allows you to *categorically rule out all the modules you do not have to read* in order to comprehend the relevant module(s). In the above example, that's all the modules that are not highlighted. If a module is not an explicit dependency (or dependency of a dependency...), it's not relevant. In fact, it's explicitly *independent*.
6157

62-
## Disallowing side-effects: only pure functions
58+
## Only pure functions (disallowing side-effects)
59+
60+
The Interactive Pattern, representative of most JavaScript UI frameworks, is not modularly comprehensible, because data dependencies are implicit, because the language permits side-effects, such as mutable state, which allows `bar.updateSomething(someValue);`.
6361

64-
The Reactive Pattern enforces explicit dependencies disallowing side-effects. As defined in Wikipedia, a side-effect "modifies some state outside its local environment or has an observable interaction with the outside world."
62+
The Reactive Pattern is modularly comprehensibility because it enforces explicit dependencies, by disallowing side-effects. As defined in Wikipedia, a side-effect "modifies some state outside its local environment or has an observable interaction with the outside world."
6563

6664
Let's address the first part of that definition, "modifies some state outside its local environment". Removing side-effects disallows calls like these:
6765

@@ -104,6 +102,8 @@ But how do we calculate the counts? I have two helpful metaphors for FRP: "zoomi
104102
var count = 0
105103
document.getElementById("counter-button").onclick = e => {
106104
count++
105+
// Before FRP, we'd have to do:
106+
// document.getElementById("counter-button").innerText = count;
107107
}
108108
```
109109

@@ -114,7 +114,7 @@ const count = document.getElementById("counter-button").clicks
114114
.reduce((accumulator, currentValue) => accumulator + 1)
115115
```
116116

117-
You may be wondering how `count` can be a `const`, even though it will update as the button is clicked. This is because `count` is itself a stream of values that can be used as a dependency in streams defined elsewhere.
117+
You may be wondering how `count` can be a `const`, even though it will update as the button is clicked. This is because `count` is itself a stream of values that can be used as a dependency in streams defined elsewhere. `count` is constant in the sense that there's no code anywhere that can modify `count` besides its definition above. `count` is read-only.
118118

119119
TODO:
120120

0 commit comments

Comments
 (0)