ferp-js
  • What is Ferp
  • Getting Started
    • Installing Ferp in Your Application
    • What Does Ferp Provide
  • Building Your First App
    • The Boilerplate
  • Understanding Effects in Ferp
    • What is a Ferp Effect?
    • Core Effects
    • Composing Custom Effects
    • Testing Your Effects
  • Understanding Actions in Ferp
    • What is a Ferp Action?
    • Writing Your Own Actions
    • Testing Actions
  • Understanding Subscriptions in Ferp
    • What is a Ferp Subscription?
    • Composing Custom Subscriptions
    • Testing Your Subscriptions
  • Advanced Usage
    • Third-Party Libraries and Objects
Powered by GitBook
On this page
  • Effects
  • The Inside World
  • The Outside World
  • Talk to the Outside World in Isolation

Was this helpful?

  1. Understanding Effects in Ferp

What is a Ferp Effect?

PreviousThe BoilerplateNextCore Effects

Last updated 4 years ago

Was this helpful?

Effects

A side-effect, or simply effect, is a way of talking the world outside of your Ferp application. Effects will always be a composition of the .

You effects may look something like:

effectExamples.js
import { effects } from 'ferp';

const MyAction = (state) => [state, effects.none()];

const exampleEffects = {
  effect1: effects.thunk(() => effects.none()),
  effect2: effects.defer(1234),
  effect3: effects.act(MyAction),
};

Ultimately, you will want to compose your effects to be consistent, meaningful, and easy to use.

The Inside World

When we talk about your application, there are essentially two contexts, or worlds. The first is the inside world. This is anything that lives inside of your application state. To be even more strict, it's anything in your application state that can also be serialized. This doesn't mean that your state has to be capable of being serialized to JSON or similar, but that pieces that are serializable are the inside world parts of your application. Things in the inside world are easily used, manipulated, and tested through actions.

The Outside World

There are some things that are obviously the outside world, and some that are less obvious; we should probably discuss what belongs in an effect.

Some obvious examples of the outside world are external servers and processes. To talk to them, maybe you use fetch, a file, or an IPC channel. There is a very clear boundary between your Ferp application and another application or server. Some less obvious examples are local files, accessing the system clock, generating a random number. More strictly, even modules you import in your files are in some sense a side-effect.

Talk to the Outside World in Isolation

While in some sense, the outside world is a scary place, filled with uncertainty and chaos, using Ferp's forces these communication channels to be isolated from harming our precious application.

Core Effects
Core Effects