1- import { Overmind , TAction , TApp , EventType } from './'
1+ import { EventType , Overmind , TAction , TApp } from './'
22import { modules } from './modules'
33
44function toJSON ( obj ) {
@@ -30,12 +30,21 @@ function createDefaultApp() {
3030 const changeValue : Action < { isAwesome : boolean } > = ( context ) => {
3131 context . value . isAwesome = ! context . value . isAwesome
3232 }
33+ const changeFormValue : Action < {
34+ key : string
35+ form : { [ key : string ] : any }
36+ value : any
37+ } > = ( context ) => {
38+ const { form, key, value } = context . value
39+ form [ key ] = value
40+ }
3341 const actions = {
42+ asyncChangeFoo,
43+ changeFormValue,
3444 changeFoo,
3545 changeFooWithEffect,
36- waitAndChangeFoo,
37- asyncChangeFoo,
3846 changeValue,
47+ waitAndChangeFoo,
3948 }
4049 const effects = {
4150 hello ( ) {
@@ -184,7 +193,7 @@ describe('Overmind', () => {
184193 const app = createDefaultApp ( )
185194 app . eventHub . once ( EventType . MUTATIONS , ( data ) => {
186195 expect ( toJSON ( data ) ) . toEqual ( {
187- actionId : 0 ,
196+ actionId : 2 ,
188197 actionName : 'changeFoo' ,
189198 mutations : [
190199 {
@@ -205,7 +214,7 @@ describe('Overmind', () => {
205214 const app = createDefaultApp ( )
206215 app . eventHub . on ( EventType . MUTATIONS , ( data ) => {
207216 expect ( toJSON ( data ) ) . toEqual ( {
208- actionId : 2 ,
217+ actionId : 5 ,
209218 actionName : 'waitAndChangeFoo' ,
210219 mutations : [
211220 {
@@ -226,7 +235,7 @@ describe('Overmind', () => {
226235 const app = createDefaultApp ( )
227236 app . eventHub . on ( EventType . MUTATIONS , ( data ) => {
228237 expect ( toJSON ( data ) ) . toEqual ( {
229- actionId : 3 ,
238+ actionId : 0 ,
230239 actionName : 'asyncChangeFoo' ,
231240 mutations : [
232241 {
@@ -305,4 +314,16 @@ describe('Overmind', () => {
305314 expect ( ( ) => app . actions . changeValue ( app . state . item ) ) . not . toThrow ( )
306315 expect ( app . state . item . isAwesome ) . toBe ( false )
307316 } )
317+ test ( 'should allow mutations on passed values in object' , ( ) => {
318+ expect . assertions ( 2 )
319+ const app = createDefaultApp ( )
320+ expect ( ( ) =>
321+ app . actions . changeFormValue ( {
322+ form : app . state . item ,
323+ key : 'isAwesome' ,
324+ value : false ,
325+ } )
326+ ) . not . toThrow ( )
327+ expect ( app . state . item . isAwesome ) . toBe ( false )
328+ } )
308329} )
0 commit comments