Skip to content

Commit 0030a36

Browse files
gaspardchristianalfoni
authored andcommitted
fix(overmind): use a temporary action context to make IContext compatible with useOvermind
1 parent 2c3a949 commit 0030a36

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

packages/node_modules/overmind/src/index.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
import { EventEmitter } from 'betsy'
22
import isPlainObject from 'is-plain-obj'
33
import {
4+
IFlushCallback,
5+
IMutation,
6+
IMutationCallback,
47
IS_PROXY,
58
ProxyStateTree,
69
TTree,
7-
IMutation,
810
VALUE,
9-
IMutationCallback,
10-
IFlushCallback,
1111
} from 'proxy-state-tree'
1212
import { Derived } from './derived'
1313
import { Devtools, Message, safeValue, safeValues } from './Devtools'
1414
import {
1515
Events,
1616
EventType,
17+
Execution,
18+
NestedPartial,
1719
Options,
1820
ResolveActions,
19-
ResolveState,
20-
Execution,
2121
ResolveMockActions,
22-
NestedPartial,
22+
ResolveState,
2323
} from './internalTypes'
2424
import { proxifyEffects } from './proxyfyEffects'
2525
import {
26-
IConfiguration,
26+
AContext,
2727
IAction,
28+
IConfiguration,
2829
IDerive,
2930
IOperator,
30-
IContext,
31-
TOnInitialize,
3231
IState,
32+
TOnInitialize,
3333
} from './types'
3434

3535
export * from './types'
@@ -843,7 +843,7 @@ function createNextPath(next) {
843843
}
844844

845845
export function map<Input, Output, ThisConfig extends IConfiguration = Config>(
846-
operation: (context: IContext<ThisConfig, Input>, value: Input) => Output
846+
operation: (context: AContext<ThisConfig, Input>, value: Input) => Output
847847
): IOperator<ThisConfig, Input, Output extends Promise<infer U> ? U : Output> {
848848
const instance = (err, context, next) => {
849849
if (err) next(err)
@@ -961,7 +961,7 @@ export function parallel<Input, ThisConfig extends IConfiguration = Config>(
961961
}
962962

963963
export function filter<Input, ThisConfig extends IConfiguration = Config>(
964-
operation: (context: IContext<ThisConfig, Input>, value: Input) => boolean
964+
operation: (context: AContext<ThisConfig, Input>, value: Input) => boolean
965965
): IOperator<ThisConfig, Input, Input> {
966966
const instance = (err, context, next, final) => {
967967
if (err) next(err)
@@ -995,7 +995,7 @@ export function filter<Input, ThisConfig extends IConfiguration = Config>(
995995
}
996996

997997
export function action<Input, ThisConfig extends IConfiguration = Config>(
998-
operation: (context: IContext<ThisConfig, Input>, value: Input) => void
998+
operation: (context: AContext<ThisConfig, Input>, value: Input) => void
999999
): IOperator<ThisConfig, Input, Input> {
10001000
const instance = (err, context, next) => {
10011001
if (err) next(err)
@@ -1066,7 +1066,7 @@ export function fork<
10661066
ThisConfig extends IConfiguration = Config
10671067
>(
10681068
operation: (
1069-
context: IContext<ThisConfig, Input>,
1069+
context: AContext<ThisConfig, Input>,
10701070
value: Input
10711071
) => keyof Paths,
10721072
paths: Paths
@@ -1103,7 +1103,7 @@ export function when<
11031103
OutputB,
11041104
ThisConfig extends IConfiguration = Config
11051105
>(
1106-
operation: (context: IContext<ThisConfig, Input>, value: Input) => boolean,
1106+
operation: (context: AContext<ThisConfig, Input>, value: Input) => boolean,
11071107
paths: {
11081108
true: IOperator<ThisConfig, Input, OutputA>
11091109
false: IOperator<ThisConfig, Input, OutputB>

packages/node_modules/overmind/src/types.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,19 @@ export interface IConfig<ThisConfig extends IConfiguration> {
3232
effects: ThisConfig['effects'] & {}
3333
}
3434

35-
// DEPRECATED: Value is to be removed
36-
export type IContext<ThisConfig extends IConfiguration, Value> = {
35+
export type IContext<ThisConfig extends IConfiguration> = {
3736
state: ResolveState<ThisConfig['state']>
3837
actions: ResolveActions<ThisConfig['actions']>
3938
effects: ThisConfig['effects']
40-
value: Value
4139
}
4240

41+
// DEPRECATED: Value is to be removed
42+
export type AContext<ThisConfig extends IConfiguration, Value> = IContext<
43+
ThisConfig
44+
> & { value: Value }
45+
4346
export interface IAction<ThisConfig extends IConfiguration, Value> {
44-
(context: IContext<ThisConfig, Value>, value: Value): any
47+
(context: AContext<ThisConfig, Value>, value: Value): any
4548
}
4649

4750
// We do not type operators as their low level implementation, but rather
@@ -50,7 +53,7 @@ export type IOperator<
5053
ThisConfig extends IConfiguration,
5154
Input,
5255
Output = Input
53-
> = (context: IContext<ThisConfig, Input>, value: Input) => Output
56+
> = (context: AContext<ThisConfig, Input>, value: Input) => Output
5457

5558
export type IDerive<
5659
ThisConfig extends IConfiguration,
@@ -63,7 +66,7 @@ export type IDerive<
6366

6467
export interface TOnInitialize<ThisConfig extends IConfiguration> {
6568
(
66-
context: IContext<ThisConfig, Overmind<ThisConfig>>,
69+
context: AContext<ThisConfig, Overmind<ThisConfig>>,
6770
value: Overmind<ThisConfig>
6871
): void
6972
}

0 commit comments

Comments
 (0)