You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: drafts/frp.md
+7-7Lines changed: 7 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -45,10 +45,6 @@ Note on the word "module": In his example above, Staltz uses JavaScript files as
45
45
46
46
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.
47
47
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
-
52
48
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."
@@ -59,9 +55,11 @@ If you want to understand a module, you have to understand the modules it's defi
59
55
60
56
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*.
61
57
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);`.
63
61
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."
65
63
66
64
Let's address the first part of that definition, "modifies some state outside its local environment". Removing side-effects disallows calls like these:
67
65
@@ -104,6 +102,8 @@ But how do we calculate the counts? I have two helpful metaphors for FRP: "zoomi
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.
0 commit comments