Skip to content

Instantly share code, notes, and snippets.

@mokargas
Last active February 22, 2017 00:50
Show Gist options
  • Save mokargas/f39337419a0ecf0a2c08776c763ef6d9 to your computer and use it in GitHub Desktop.
Save mokargas/f39337419a0ecf0a2c08776c763ef6d9 to your computer and use it in GitHub Desktop.
Simple Explanations: What is Functional Reactive Programming (FRP)?

WIP: Still searching for a simple explanation for all levels of developer (and non-devs as well)

Feel free to chime in with corrections, ideas, helpful comments.

Beats:##

  • Ideally, we want no side effects in FRP
  • Observer patterns. Subscription concept
  • Declarative in nature rather than imperative. (Ref: Definition of imperative/declarative)
  • Time varying functions, not mutable state

Concepts/Examples:##

  • Observable vs Iterator. HoF's over a collection, rather than iterating through a collection. (HoF's in JS: Array.filter? Array.map? Array.reduce)

Pros:##

  • Straightforward and easy to compose asynchronous tasks. e.g fetch(url).then(someAction).filter(item=>item.name == 'john')
  • Great for UI events, especially ones that don't "require" state.
  • Don't mutate state
  • Quicker change detection. Only need "shallow" referential checks, no deep equalaity checks along an object graph (Like the DOM in React) because our data is immutable from the get go.
  • Observables are a lot faster in general, esp in Anguar 2 (provide reference)

Cons:##

  • Depending on libraries, can be a steep learning curve
  • Mindset, or thinking 'functionally' can be a hard to get used to, can be tough to master
  • Subscription based patterns are easy to mess up / leak mem if improperly implemented
  • DSL's (Domain Specific Languages) can proliferate. React uses a kind of soft-DSL
  • Don't model real-world things like OOP paradigms do. Cognitively more intense to use. Better thought of algorithmically IMHO

Further Links:##

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment