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.

Simplified typing

See original GitHub issue

Dear Overminders!

I have one thing I really want to do and that is to clean up and simplify the typing of Overmind. It was a long process figuring out how to do it and with acquired knowledge through all this work and later projects I would like to do this:

import { IContext } from 'overmind'

const config = { ... }

export interface Context extends IContext<{
  state: typeof config.state,
  actions: typeof config.actions,
  effects: typeof config.effects
}> {}

There will be no more implicit typing, the above is what everybody will need to do. This is how you type the different things:

const myAction = (context: Context) => {}

const myActionWithPayload = (context: Context, payload: string) => {}

// Now we support generics
const myActionWithPayload = <T extends TEvent>(context: Context, payload: T) => {}

const myOperator = map((context: Context, value: string) => {})

const state: State = {
  someDerived: derived((state: State, rootState: Context["state"]) => {})
}

And I believe that is it. This will need to be a breaking change to actually clean up the internal typing of Overmind. I was just wondering how you feel about this change, do you consider refactoring your apps to this typing too much work? 😄

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:7
  • Comments:20 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
Michielnuytscommented, Feb 10, 2021

@christianalfoni This is all coming in V28 right? Do you have a rough release date in mind?

2reactions
christianalfonicommented, Jan 23, 2021

So a summary of what is being moved into next now is:

New typing, no more implicit typing:

import { IContext } from 'overmind'

const config = { ... }

export type Context = IContext<{
  state: typeof config.state,
  actions: typeof config.actions,
  effects: typeof config.effects
}>

Type actions:

const myAction = (context: Context) => {}

const myActionWithPayload = (context: Context, payload: string) => {}

Operator changes:

  • Now an operator is interoperable with actions, meaning you can just do:
const whatever = pipe(
  (context: Context, input: string) => input.toUpperCase()
)
  • Due to interoperable actions, the map, mutate and run operators has been removed. Just use plain action signature

  • forEach operators has also been removed as the typing never worked there (This might come back, have to research some more)

  • fork has new signature:

pipe(
  // "type" is a property on the object on the pipe
  fork('type', {
    FOO: (context: Context, event) => {
      event // Is now typed as FooEvent
    },
    BAR: (context: context, event) => {
      event // Is now typed as BarEvent
    } 
  })
)
  • parallel now actually returns an array to the pipe with the results of each operator

React hooks

  • useOvermind is removed in favour of explicit hooks (more efficient and cleaner)
  • useState hook now has an added signature
const ItemComponent = ({ id }) => {
  // The state you access within the callback is not tracked,
  // only the result and further access is tracked. Meaning this
  // component will only track the item, not changes to "items"
  const item = useAppState(state => state.items[id])
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Easy Home Row Words - Typing Lessons
Easy Home Row Words | Practice words, punctuation, and sentences.
Read more >
Typing simplified: Leslie, Louis A - Amazon.com
Typing simplified. Typing simplified. Back. Double-tap to zoom. Hardcover $9.99. Select delivery location. See All Buying Options ...
Read more >
Type Chinese using Pinyin - Simplified on Mac - Apple Support
On your Mac, enter Simplified Chinese characters using the Pinyin phonetic input codes.
Read more >
Online Simplified/Traditional Chinese Input System
With this powerful tool, you can type Simplified / Traditional Chinese characters anywhere in the world with no need to install Chinese input...
Read more >
Type Chinese Online - 在线中文输入
You can type Chinese on a tablet, smartphone, or PC without installing a Chinese Input Method Editor(IME)! It is fast and runs on...
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