question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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.

  1. 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.

  1. What does getCell do? It has no documentation.
export const { states, getCell } = setup({ stream: toStream(Stream), merge, app });
  1. 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?

  1. Considering we get setup from meiosis-setup/mergerino, it would make sense that the merge does not have to be supplied separately, i.e. why can’t we use:
export const { states, getCell } = setup({ stream: toStream(Stream), app });
  1. Why is toStream first exported, just to convert Stream to StreamLib? 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.

  1. 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.

  1. 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.

  1. Personal style thingy: In memory-trainer, file app-state.ts, you have the following
actions: context => { // ...

Whereas I prefer, so I don’t have to write context.update(...) everywhere:

actions: ({ update, getState }) => { // ...
  1. When creating actions using arrow functions, you cannot call another action. Using function, you can, by using this. However, Typescript coding practices do not really like the usage of this. Isn’t it possible to also provide the actions, like the state and update function, as a parameter (in the context 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:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
erikvullingscommented, Oct 22, 2022

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:

Closed #172 https://github.com/foxdonut/meiosis/issues/172 as completed.

— Reply to this email directly, view it on GitHub https://github.com/foxdonut/meiosis/issues/172#event-7643834922, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAX6YO24YFAMIFEEOKO44SDWEMEKZANCNFSM5PPECC5Q . You are receiving this because you were mentioned.Message ID: @.***>

0reactions
foxdonutcommented, Oct 28, 2022

@erikvullings heartfelt thanks for all your help and for your kind words, very much appreciated!

Read more comments on GitHub >

github_iconTop Results From Across the Web

foxdonut/meiosis - Gitter
@foxdonut When I import { meiosisSetup } from 'meiosis-setup', vite fails with the following error. ... Any idea what could be causing that?...
Read more >
meiosis-setup - npm
Start using meiosis-setup in your project by running `npm i ... TypeScript icon, indicating that this package has built-in type declarations.
Read more >
Documentation - Do's and Don'ts - TypeScript
Recommendations for writing d.ts files. ... Don't use the return type any for callbacks whose value will be ignored: ts. /* WRONG */....
Read more >
Typescript Tips and tricks for JS Developers (Part1) - Medium
I will try to list some tricks and tips with code examples, benefits, and use cases ... And this is a list of...
Read more >
meiosis-setup examples - CodeSandbox
Learn how to use meiosis-setup by viewing and forking meiosis-setup example apps on CodeSandbox. ... meiosis-setup-typescript-example.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found