Skip to content

Commit 0ea86fd

Browse files
committed
fix(subscribe): add the missing name for anonymous function
1 parent 35d698e commit 0ea86fd

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

__test__/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type NextCounterActionParams = {
2222

2323
type ExtraActionParams = {
2424
add: number
25+
addCaller: undefined
2526
}
2627

2728
type ThemeActionParams = {

__test__/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ export const Counter: ModelType<
4343
return {
4444
count: state.count + params
4545
}
46+
},
47+
addCaller: (_, actions) => {
48+
actions.add(5)
4649
}
4750
}
4851
}
@@ -63,6 +66,9 @@ export const NextCounter: NextModelType<
6366
return {
6467
count: state.count + params
6568
}
69+
},
70+
addCaller: (_, { actions }) => {
71+
actions.add(5)
6672
}
6773
}
6874
}

__test__/middlewares/subscribe.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
/// <reference path="../index.d.ts" />
22
import 'react-testing-library/cleanup-after-each'
33
import { Model } from '../../src'
4-
import { Counter } from '..'
4+
import { NextCounter } from '..'
55
import { testHook } from 'react-hooks-testing-library'
66

77
describe('Subscribe middleware', () => {
88
test('run callback when specific action run', async () => {
99
let actions: any
1010
let count = 0
11+
const Counter = Model(NextCounter)
1112
const { useStore, subscribe } = Model({ Counter })
1213
subscribe('Counter', ['increment'], () => (count += 1))
1314
subscribe('Counter', 'add', () => (count += 10))
@@ -20,5 +21,7 @@ describe('Subscribe middleware', () => {
2021
await actions.increment()
2122
await actions.increment()
2223
expect(count).toBe(33)
24+
await actions.addCaller()
25+
expect(count).toBe(48)
2326
})
2427
})

src/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ function Model<M extends Models, MT extends NextModelType>(
3939
o[name] = async (state, actions, params) => {
4040
return await action(params, { state, actions })
4141
}
42+
Object.defineProperty(o[name], 'name', { value: name })
4243
return o
4344
},
4445
{}

0 commit comments

Comments
 (0)