meiosis-setup with typescript: some suggestions
See original GitHub issue@foxdonut It is really impressive what you’ve achieved with the TypeScript support, so I have only a few remarks/suggestions/requests.
- Can we reduce the number of import lines?
Currently:
import Stream from 'mithril/stream';
import { toStream } from 'meiosis-setup/common';
import { App, Service, setup } from 'meiosis-setup/mergerino';
import { merge } from '../utils/mergerino';
I would prefer:
import Stream from 'mithril/stream';
import { toStream } from 'meiosis-setup/common';
import { App, Service, setup, merge } from 'meiosis-setup/mergerino';
As we are already using mergerino, it makes little sense (considering it is quite stable) to import it separately.
- What does
getCell
do? It has no documentation.
export const { states, getCell } = setup({ stream: toStream(Stream), merge, app });
- In your example, you still use:
const { states, update, actions } = meiosis({ stream: simpleStream, merge, app });
However, in your code, I do not see the actions
being exported, and instead, you export states
and getCell
? And in the mergerino
version, getCell
also has a nest
function. What is that used for?
- Considering we get
setup
frommeiosis-setup/mergerino
, it would make sense that themerge
does not have to be supplied separately, i.e. why can’t we use:
export const { states, getCell } = setup({ stream: toStream(Stream), app });
- Why is
toStream
first exported, just to convertStream
toStreamLib
? Can’t this be done internally, so instead, pass
export const { states, getCell } = setup({ stream: Stream, app });
Where Stream
is of type mithril/stream
or flyd
.
- Alternatively, as I see that you have implemented a
simpleStream
yourself, why not leave it out, so it becomes:
import { App, Service, setup } from 'meiosis-setup/mergerino';
export const { states, getCell } = setup({ app });
So the simpleStream
will be the default value for stream
, the same with merge
and mergerino
.
- When setting up the
app
, as in:
const app: App<IAppModel, IActions> = {
initial: Object.assign({}, appStateMgmt.initial) as IAppModel,
Actions: context => Object.assign({}, appStateMgmt.actions(context)) as IActions,
/** Services update the state */
services: [] as Array<Service<IAppModel>>,
};
Why do you write services
using lower-case letters, versus Actions
and Effects
? I prefer the former, but perhaps there is a specific reason for that.
- Personal style thingy: In
memory-trainer
, fileapp-state.ts
, you have the following
actions: context => { // ...
Whereas I prefer, so I don’t have to write context.update(...)
everywhere:
actions: ({ update, getState }) => { // ...
- When creating actions using arrow functions, you cannot call another action. Using
function
, you can, by usingthis
. However, Typescript coding practices do not really like the usage ofthis
. Isn’t it possible to also provide theactions
, like thestate
andupdate
function, as a parameter (in thecontext
as defined before)? So you can always get to another action. I.e. the above example would become:
actions: ({ update, getState, actions }) => { // ...
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
Thanks for closing this issue. I should have done it already, since I’m already using your improvements in the latest version. Great work, and I really love using it!
On Sat, 22 Oct 2022, 00:37 Fred Daoud, @.***> wrote:
@erikvullings heartfelt thanks for all your help and for your kind words, very much appreciated!