Features

All application logic is defined within a Feature. Combing a React context with react-states allows us to drive both UI and side effects with only dispatching and consuming explicit state.

Consuming a feature

Implementing a Feature

The main file is called Feature.tsx. The naming conventions within a feature is generic, meaning every type and variable points to "feature" and not the domain the feature represents. This keeps feature implementations as similar as possible, you only parse the implementation details and not the generic types and variables. You will rather use the index.ts file to expose named exports.

Creating data types

Sometimes features consumes data from the environment. Typically the types returned from an environment interface is exactly what you want to expose in the state of your feature, but not always. No matter all the types that a feature consumes should also be exported from the feature. That means:

This pattern ensures that whenever a type is inferred from a feature, you will always find it on the feature itself. This means you can discover all the types a feature defines by looking at its exports.

Exploding features

Certain features might have many transition effects and/or states. In that case it can be an idea to split the feature into parts.

The index file exports a named version of the provider and types.

The Feature file should only contain the definition of the provider component itself.

All types are defined in its own file.

The reducer file holds the definition of transitions in the reducer.

The effects file can have multiple effect definitions. Splitting the states between the effects, even having multiple effects on the same state. Organize them in related groups.

Last updated

Was this helpful?