In the Meiosis Documentation, the Meiosis pattern is setup up either with Function Patches or Mergerino. The idea is that using Function Patches gives you the option of having one less library dependency.
On the other hand, meiosis-setup
takes a "ready-to-use" approach and includes Mergerino as a
dependency. Since Mergerino handles Function Patches, there is no need to choose between the two
when setting up Meiosis with meiosis-setup
. You can use Function Patches and/or Mergerino as you
please:
import { meiosisSetup } from 'meiosis-setup';
interface State {
// your application state type
}
const cells = meiosisSetup<State>();
cells().update(...); // Function Patch or Mergerino works
Since we are using TypeScript, we'll want to define a type for our application state to get the most out of what TypeScript offers.
Let's say we have a State
type as shown below:
interface State {
name: string;
age: number;
}
Then, after setting up Meiosis:
import { meiosisSetup } from 'meiosis-setup';
const cells = meiosisSetup<State>();
const cell = cells();
We now have a stream of cells with each cell having state
of type State
and having update
taking patches that must be compatible with State
.
As mentioned earlier, both Function Patches and Mergerino work to update the state.
In the example below, you can experiment with TypeScript support. Try the following:
cell
, add a dot (.) after cell
and see the auto-suggested cell
properties.cell.state
, add a dot (.) after state
and see the auto-suggested properties,
name
and age
.cell.update({ invalid: true });
and see the patch in error since 'invalid'
is not a property of State
.cell.update({ age: 'not valid'});
and see the patch in error since
'not valid'
is not a number
.