@@ -2,8 +2,8 @@ import ProxyStateTree from 'proxy-state-tree'
22import { ActionBase , StopExecution } from 'action-chain'
33
44type OperatorCallback < Context , Value , NewValue = Value > = (
5- value : Value ,
6- context : Context
5+ context : Context ,
6+ value : Value
77) => NewValue | Promise < NewValue >
88
99export interface IValueAction <
@@ -36,13 +36,13 @@ export default class Action<
3636 this . proxyStateTree = proxyStateTree
3737 }
3838 fork : < Paths > (
39- cb : ( value : Value , context : Context ) => keyof Paths ,
39+ cb : ( context : Context , value : Value ) => keyof Paths ,
4040 paths : Paths
4141 ) => [ InitialValue ] extends [ void ]
4242 ? INoValueAction < State , Context , InitialValue , Value >
4343 : IValueAction < State , Context , InitialValue , Value > = ( cb , paths ) => {
44- const operator = ( value , context ) => {
45- const path = cb ( value , context )
44+ const operator = ( context , value ) => {
45+ const path = cb ( context , value )
4646
4747 return ( paths [ path ] as any ) . map ( ( ) => value ) ( value , context , path )
4848 }
@@ -60,13 +60,13 @@ export default class Action<
6060 ) as any
6161 }
6262 mutation : (
63- cb : ( value : Value , state : State ) => any
63+ cb : ( state : State , value : Value ) => any
6464 ) => [ InitialValue ] extends [ void ]
6565 ? INoValueAction < State , Context , InitialValue , Value >
6666 : IValueAction < State , Context , InitialValue , Value > = ( cb ) => {
67- const operator = ( value , context ) => {
67+ const operator = ( context , value ) => {
6868 this . proxyStateTree . startMutationTracking ( )
69- cb ( value , context . state )
69+ cb ( context . state , value )
7070 const mutations = this . proxyStateTree . clearMutationTracking ( )
7171 this . getActionChain ( ) . emit ( 'mutations' , {
7272 mutations,
@@ -90,12 +90,12 @@ export default class Action<
9090 ) as any
9191 }
9292 do : (
93- cb : ( value : Value , context : Context ) => void
93+ cb : ( context : Context , value : Value ) => void
9494 ) => [ InitialValue ] extends [ void ]
9595 ? INoValueAction < State , Context , InitialValue , Value >
9696 : IValueAction < State , Context , InitialValue , Value > = ( cb ) => {
97- const operator = ( value , context ) => {
98- cb ( value , context )
97+ const operator = ( context , value ) => {
98+ cb ( context , value )
9999 return value
100100 }
101101
@@ -113,7 +113,7 @@ export default class Action<
113113 ) as any
114114 }
115115 map : < NewValue > (
116- cb : ( value : Value , context : Context ) => NewValue | Promise < NewValue >
116+ cb : ( context : Context , value : Value ) => NewValue | Promise < NewValue >
117117 ) => [ InitialValue ] extends [ void ]
118118 ? INoValueAction < State , Context , InitialValue , NewValue >
119119 : IValueAction < State , Context , InitialValue , NewValue > = ( cb ) => {
@@ -156,8 +156,8 @@ export default class Action<
156156 cb ,
157157 paths
158158 ) => {
159- const operator = ( value , context ) => {
160- return ( cb ( value , context ) as any )
159+ const operator = ( context , value ) => {
160+ return ( cb ( context , value ) as any )
161161 . then ( ( promiseValue ) => {
162162 return ( paths . success as any ) ( promiseValue , context , 'success' )
163163 } )
@@ -179,7 +179,7 @@ export default class Action<
179179 ) as any
180180 }
181181 when : < TrueValue , FalseValue > (
182- cb : ( value : Value , context : Context ) => boolean ,
182+ cb : ( context : Context , value : Value ) => boolean ,
183183 paths : {
184184 true : Action < State , Context , Value , TrueValue >
185185 false : Action < State , Context , Value , FalseValue >
@@ -190,8 +190,8 @@ export default class Action<
190190 cb ,
191191 paths
192192 ) => {
193- const operator = ( value , context ) => {
194- const isTrue = cb ( value , context )
193+ const operator = ( context , value ) => {
194+ const isTrue = cb ( context , value )
195195 const path = isTrue ? paths . true : ( paths . false as any )
196196
197197 return path ( value , context , isTrue ? 'true' : 'false' )
@@ -210,12 +210,12 @@ export default class Action<
210210 ) as any
211211 }
212212 filter : (
213- cb : ( value : Value , context : Context ) => boolean
213+ cb : ( context : Context , value : Value ) => boolean
214214 ) => [ InitialValue ] extends [ void ]
215215 ? INoValueAction < State , Context , InitialValue , Value >
216216 : IValueAction < State , Context , InitialValue , Value > = ( cb ) => {
217- const operator = ( value , context ) => {
218- const result = cb ( value , context )
217+ const operator = ( context , value ) => {
218+ const result = cb ( context , value )
219219
220220 if ( result === true ) {
221221 return value
@@ -243,7 +243,7 @@ export default class Action<
243243 : IValueAction < State , Context , InitialValue , Value > = ( timer ) => {
244244 let currentTimeout = null
245245
246- const operator = ( value ) => {
246+ const operator = ( _ , value ) => {
247247 return new Promise ( ( resolve ) => {
248248 if ( currentTimeout ) {
249249 currentTimeout ( )
0 commit comments