@@ -20,6 +20,7 @@ import {
2020 TDerive ,
2121 TOperator ,
2222 TReaction ,
23+ TValueContext ,
2324} from './types'
2425
2526export * from './types'
@@ -34,13 +35,15 @@ type App = BaseApp & IApp
3435
3536export type Action < Value = void > = TAction < App , Value >
3637
37- export type Context < Value > = TContext < App , Value >
38+ export type Context = TContext < App >
3839
3940export type Derive < Value , Parent = any > = TDerive < App , Value , Parent >
4041
4142export type Reaction = TReaction < App >
4243
43- export type OnInitialize = ( context : Context < App [ 'actions' ] > ) => void
44+ export type OnInitialize = (
45+ context : TValueContext < TContext < App > , App [ 'actions' ] >
46+ ) => void
4447
4548const isPlainObject = require ( 'is-plain-object' )
4649const IS_PRODUCTION = process . env . NODE_ENV === 'production'
@@ -467,44 +470,46 @@ export class Overmind<Config extends Configuration> implements BaseApp {
467470 OPERATORS
468471 needs to be in this file for typing override to work
469472*/
470- export type Operator < C , RC > = TOperator < Context < C > , Context < RC > >
471-
472- export function pipe < A , B , C > ( aOperator : Operator < A , B > ) : Operator < A , C >
473-
474- export function pipe < A , B , C , D > (
475- aOperator : Operator < A , B > ,
476- bOperator : Operator < B , C >
477- ) : Operator < A , D >
478-
479- export function pipe < A , B , C , D , E > (
480- aOperator : Operator < A , B > ,
481- bOperator : Operator < B , C > ,
482- cOperator : Operator < C , D >
483- ) : Operator < A , E >
484-
485- export function pipe < A , B , C , D , E , F > (
486- aOperator : Operator < A , B > ,
487- bOperator : Operator < B , C > ,
488- cOperator : Operator < C , D > ,
489- dOperator : Operator < D , E >
490- ) : Operator < A , F >
491-
492- export function pipe < A , B , C , D , E , F , G > (
493- aOperator : Operator < A , B > ,
494- bOperator : Operator < B , C > ,
495- cOperator : Operator < C , D > ,
496- dOperator : Operator < D , E > ,
497- eOperator : Operator < E , F >
498- ) : Operator < A , G >
499-
500- export function pipe < A , B , C , D , E , F , G , H > (
501- aOperator : Operator < A , B > ,
502- bOperator : Operator < B , C > ,
503- cOperator : Operator < C , D > ,
504- dOperator : Operator < D , E > ,
505- eOperator : Operator < E , F > ,
506- fOperator : Operator < F , G >
507- ) : Operator < A , H >
473+ export type Operator < Input , Output > = TOperator < Input , Output , Context >
474+
475+ export function pipe < BaseContext , A , B , C > (
476+ aOperator : TOperator < A , B , BaseContext >
477+ ) : TOperator < A , C , BaseContext >
478+
479+ export function pipe < BaseContext , A , B , C , D > (
480+ aOperator : TOperator < A , B , BaseContext > ,
481+ bOperator : TOperator < B , C , BaseContext >
482+ ) : TOperator < A , D , BaseContext >
483+
484+ export function pipe < BaseContext , A , B , C , D , E > (
485+ aOperator : TOperator < A , B , BaseContext > ,
486+ bOperator : TOperator < B , C , BaseContext > ,
487+ cOperator : TOperator < C , D , BaseContext >
488+ ) : TOperator < A , E , BaseContext >
489+
490+ export function pipe < BaseContext , A , B , C , D , E , F > (
491+ aOperator : TOperator < A , B , BaseContext > ,
492+ bOperator : TOperator < B , C , BaseContext > ,
493+ cOperator : TOperator < C , D , BaseContext > ,
494+ dOperator : TOperator < D , E , BaseContext >
495+ ) : TOperator < A , F , BaseContext >
496+
497+ export function pipe < BaseContext , A , B , C , D , E , F , G > (
498+ aOperator : TOperator < A , B , BaseContext > ,
499+ bOperator : TOperator < B , C , BaseContext > ,
500+ cOperator : TOperator < C , D , BaseContext > ,
501+ dOperator : TOperator < D , E , BaseContext > ,
502+ eOperator : TOperator < E , F , BaseContext >
503+ ) : TOperator < A , G , BaseContext >
504+
505+ export function pipe < BaseContext , A , B , C , D , E , F , G , H > (
506+ aOperator : TOperator < A , B , BaseContext > ,
507+ bOperator : TOperator < B , C , BaseContext > ,
508+ cOperator : TOperator < C , D , BaseContext > ,
509+ dOperator : TOperator < D , E , BaseContext > ,
510+ eOperator : TOperator < E , F , BaseContext > ,
511+ fOperator : TOperator < F , G , BaseContext >
512+ ) : TOperator < A , H , BaseContext >
508513
509514export function pipe ( ...operators ) {
510515 const instance = ( err , context , next , final = next ) => {
@@ -612,9 +617,9 @@ function createNextPath(next) {
612617 }
613618}
614619
615- export function map < Input , Output > (
616- operation : ( input : Context < Input > ) => Output
617- ) : Operator < Input , Output extends Promise < infer U > ? U : Output > {
620+ export function map < Input , Output , BaseContext = Context > (
621+ operation : ( input : TValueContext < BaseContext , Input > ) => Output
622+ ) : TOperator < Input , Output extends Promise < infer U > ? U : Output , BaseContext > {
618623 const instance = ( err , context , next ) => {
619624 if ( err ) next ( err )
620625 else {
@@ -630,9 +635,9 @@ export function map<Input, Output>(
630635 return instance
631636}
632637
633- export function run < Input > (
634- operation : ( input : Context < Input > ) => void
635- ) : Operator < Input , Input > {
638+ export function run < Input , BaseContext = Context > (
639+ operation : ( input : TValueContext < BaseContext , Input > ) => void
640+ ) : TOperator < Input , Input , BaseContext > {
636641 const instance = ( err , context , next ) => {
637642 if ( err ) next ( err )
638643 else {
@@ -648,9 +653,9 @@ export function run<Input>(
648653 return instance
649654}
650655
651- export function forEach < Input extends any [ ] > (
652- forEachItemOperator : Operator < Input [ 0 ] , any >
653- ) : Operator < Input , Input > {
656+ export function forEach < Input extends any [ ] , BaseContext = Context > (
657+ forEachItemOperator : TOperator < Input [ 0 ] , any , BaseContext >
658+ ) : TOperator < Input , Input , BaseContext > {
654659 const instance = ( err , context , next ) => {
655660 if ( err ) next ( err )
656661 else {
@@ -691,9 +696,9 @@ export function forEach<Input extends any[]>(
691696 return instance
692697}
693698
694- export function parallel < Input > (
695- operators : Operator < Input , any > [ ]
696- ) : Operator < Input , Input > {
699+ export function parallel < Input , BaseContext = Context > (
700+ operators : TOperator < Input , any , BaseContext > [ ]
701+ ) : TOperator < Input , Input , BaseContext > {
697702 const instance = ( err , context , next ) => {
698703 if ( err ) next ( err )
699704 else {
@@ -733,9 +738,9 @@ export function parallel<Input>(
733738 return instance
734739}
735740
736- export function filter < Input > (
737- operation : ( input : Context < Input > ) => boolean
738- ) : Operator < Input , Input > {
741+ export function filter < Input , BaseContext = Context > (
742+ operation : ( input : TValueContext < BaseContext , Input > ) => boolean
743+ ) : TOperator < Input , Input , BaseContext > {
739744 const instance = ( err , context , next , final ) => {
740745 if ( err ) next ( err )
741746 else {
@@ -756,8 +761,8 @@ export function filter<Input>(
756761 return instance
757762}
758763
759- export function mutate < Input > (
760- operation : ( input : Context < Input > ) => void
764+ export function mutate < Input , BaseContext = Context > (
765+ operation : ( input : TValueContext < BaseContext , Input > ) => void
761766) : Operator < Input , Input > {
762767 const instance = ( err , context , next ) => {
763768 if ( err ) next ( err )
@@ -782,11 +787,12 @@ export function mutate<Input>(
782787
783788export function fork <
784789 Input ,
785- Paths extends { [ key : string ] : Operator < Input , any > }
790+ Paths extends { [ key : string ] : Operator < Input , any > } ,
791+ BaseContext = Context
786792> (
787- operation : ( input : Context < Input > ) => keyof Paths ,
793+ operation : ( input : TValueContext < BaseContext , Input > ) => keyof Paths ,
788794 paths : Paths
789- ) : Operator < Input , Input > {
795+ ) : TOperator < Input , Input , BaseContext > {
790796 const instance = ( err , context , next ) => {
791797 if ( err ) next ( err )
792798 else {
@@ -812,13 +818,13 @@ export function fork<
812818 return instance
813819}
814820
815- export function when < Input , OutputA , OutputB > (
816- operation : ( input : Context < Input > ) => boolean ,
821+ export function when < Input , OutputA , OutputB , BaseContext = Context > (
822+ operation : ( input : TValueContext < BaseContext , Input > ) => boolean ,
817823 paths : {
818- true : Operator < Input , OutputA >
819- false : Operator < Input , OutputB >
824+ true : TOperator < Input , OutputA , BaseContext >
825+ false : TOperator < Input , OutputB , BaseContext >
820826 }
821- ) : Operator < Input , OutputA | OutputB > {
827+ ) : TOperator < Input , OutputA | OutputB , BaseContext > {
822828 const instance = ( err , context , next ) => {
823829 if ( err ) next ( err )
824830 else {
@@ -849,7 +855,9 @@ export function when<Input, OutputA, OutputB>(
849855 return instance
850856}
851857
852- export function wait < Input > ( ms : number ) : Operator < Input , Input > {
858+ export function wait < Input , BaseContext = Context > (
859+ ms : number
860+ ) : TOperator < Input , Input , BaseContext > {
853861 const instance = ( err , context , next ) => {
854862 if ( err ) next ( err )
855863 else {
@@ -863,7 +871,9 @@ export function wait<Input>(ms: number): Operator<Input, Input> {
863871 return instance
864872}
865873
866- export function debounce < Input > ( ms : number ) : Operator < Input , Input > {
874+ export function debounce < Input , BaseContext = Context > (
875+ ms : number
876+ ) : TOperator < Input , Input , BaseContext > {
867877 let timeout
868878 let previousFinal
869879 const instance = ( err , context , next , final ) => {
0 commit comments