Cerebral 5.0 focuses on four key improvements:
Watch this introduction video to understand the changes:
One significant change is the removal of all addons. This was done to reduce maintenance burden and encourage a more flexible approach where you can build custom providers exactly the way you need them. For example, you can now create your own router tailored to your application’s needs.
Your application should work with minimal changes, with these exceptions:
The Compute
API has a new signature. Read more about it here.
// REMOVED
import { StateContainer } from '@cerebral/_view_'
// INSTEAD
import App from 'cerebral'
import { Container } from '@cerebral/_view_'
import main from 'path/to/main/module'
const app = App(main)
<Container app={app}>
{/* Your app */}
</Container>
The following changes will trigger deprecation warnings but won’t break your app:
// DEPRECATED
import { Controller } from 'cerebral'
const controller = Controller(...)
// NEW
import App from 'cerebral'
const app = App(...)
// DEPRECATED
import { UniversalController } from 'cerebral'
const controller = UniversalController(...)
// NEW
import { UniversalApp } from 'cerebral'
const app = UniversalApp(...)
// DEPRECATED
import { Container } from '@cerebral/react'
render(<Container controller={controller}></Container>)
// NEW
import { Container } from '@cerebral/react'
render(<Container app={app}></Container>)
// DEPRECATED
import { Module } from 'cerebral'
export default Module({})
// or
export default Module(() => {})
// NEW
export default {}
// or
export default () => {}
For TypeScript users:
import { ModuleDefinition } from 'cerebral'
const module: ModuleDefinition = {}
export default module
// DEPRECATED
import { signal, signals, module } from 'cerebral/tags'
// NEW
import { sequences, moduleState } from 'cerebral'
sequences now handles both single sequences and modules with sequences, replacing both the previous signal and signals tags.
// DEPRECATED
import * as tags from 'cerebral/tags'
// NEW
import {
string,
props,
state,
sequences,
moduleState,
moduleSequences
} from 'cerebral'
Learn more about using proxies
We’ve renamed “operators” to “factories” to better reflect their purpose:
// DEPRECATED
import { set, push, merge } from 'cerebral/operators'
// NEW
import { set, push, merge } from 'cerebral/factories'
Addons have been removed from the core library. Here’s how to replace them:
Treat forms as “complex inputs” that manage their own state with integration points to your Cerebral state. Libraries like formsy-react work well with this approach.
Use any HTTP library and expose its methods through a provider. See the HTTP guide for examples.
You can choose from several approaches:
Create a simple provider that exposes localStorage methods, or use a more comprehensive solution like local-storage.
Firebase’s API has improved significantly and is now easier to use directly. Create a provider that exposes the Firebase methods you need for your application.