Skip to content

Commit b22c2d4

Browse files
committed
fix(lane): fix splice bug
1 parent c6739a9 commit b22c2d4

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

__test__/lane/lane.spec.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,16 @@ describe('lane model', () => {
6969
return { count, setCount }
7070
})
7171

72-
const callback = () => {
72+
const callback_1 = () => {
7373
subscribeTimes += 1
7474
}
7575

76-
subscribe(callback)
76+
const callback_2 = () => {
77+
subscribeTimes += 1
78+
}
79+
80+
subscribe(callback_1)
81+
subscribe(callback_2)
7782

7883
act(() => {
7984
expect(subscribeTimes).toEqual(0)
@@ -84,18 +89,18 @@ describe('lane model', () => {
8489
})
8590

8691
act(() => {
87-
expect(subscribeTimes).toEqual(1)
92+
expect(subscribeTimes).toEqual(2)
8893
expect(getState().count).toBe(5)
8994
})
9095

91-
unsubscribe(callback)
96+
unsubscribe(callback_1)
9297

9398
act(() => {
9499
getState().setCount(15)
95100
})
96101

97102
act(() => {
98-
expect(subscribeTimes).toEqual(1)
103+
expect(subscribeTimes).toEqual(3)
99104
expect(getState().count).toBe(15)
100105
})
101106
})

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-model",
3-
"version": "4.1.2",
3+
"version": "4.1.4",
44
"description": "The State management library for React",
55
"main": "./dist/react-model.js",
66
"module": "./dist/react-model.esm.js",

src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ function createStore<S>(n: any, u?: any): LaneAPI<S> {
124124
if (Global.subscriptions[storeId]) {
125125
if (callback) {
126126
const idx = Global.subscriptions[storeId].indexOf(callback)
127-
if (idx >= 0) Global.subscriptions[storeId].splice(idx)
127+
if (idx >= 0) Global.subscriptions[storeId].splice(idx, 1)
128128
}
129129
}
130130
}

0 commit comments

Comments
 (0)