What is a Ferp Effect?

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 Core Effects.

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 Core Effects forces these communication channels to be isolated from harming our precious application.