@codeleap/store 5.8.2 → 5.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/package.json.bak +1 -1
- package/src/tests/globalState.spec.ts +51 -47
- package/src/tests/slice.spec.ts +38 -36
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codeleap/store",
|
|
3
|
-
"version": "5.8.
|
|
3
|
+
"version": "5.8.3",
|
|
4
4
|
"main": "src/index.ts",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"directory": "packages/store"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
|
-
"@codeleap/config": "5.8.
|
|
12
|
+
"@codeleap/config": "5.8.3",
|
|
13
13
|
"ts-node-dev": "1.1.8"
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
package/package.json.bak
CHANGED
|
@@ -1,69 +1,73 @@
|
|
|
1
|
-
import { expect, test } from
|
|
2
|
-
import {globalState} from '../globalState'
|
|
1
|
+
import { expect, test, describe } from 'bun:test'
|
|
2
|
+
import { globalState } from '../globalState'
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
describe('globalState', () => {
|
|
5
|
+
describe('set method', () => {
|
|
6
|
+
test('store.set()', () => {
|
|
7
|
+
const store = globalState(1)
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
store.set(4)
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
})
|
|
11
|
+
expect(store.get()).toBe(4)
|
|
12
|
+
})
|
|
11
13
|
|
|
12
|
-
test(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
test('store.set() with object', () => {
|
|
15
|
+
const store = globalState({
|
|
16
|
+
a: 1,
|
|
17
|
+
b: 'Test'
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
store.set({
|
|
21
|
+
a: 4
|
|
22
|
+
})
|
|
17
23
|
|
|
18
|
-
|
|
19
|
-
|
|
24
|
+
expect(store.get().a).toBe(4)
|
|
25
|
+
})
|
|
20
26
|
})
|
|
21
27
|
|
|
22
|
-
|
|
23
|
-
|
|
28
|
+
test('store.reset() with object', () => {
|
|
29
|
+
const store = globalState({
|
|
30
|
+
a: 1,
|
|
31
|
+
b: 'Test'
|
|
32
|
+
})
|
|
24
33
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
})
|
|
34
|
+
store.reset({
|
|
35
|
+
a: 4,
|
|
36
|
+
b: 'Changed'
|
|
37
|
+
})
|
|
30
38
|
|
|
31
|
-
|
|
32
|
-
a
|
|
33
|
-
b
|
|
39
|
+
const newVal = store.get()
|
|
40
|
+
expect(newVal.a).toBe(4)
|
|
41
|
+
expect(newVal.b).toBe('Changed')
|
|
34
42
|
})
|
|
35
43
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
expect(newVal.b).toBe('Changed')
|
|
39
|
-
})
|
|
44
|
+
test('store array methods', () => {
|
|
45
|
+
const store = globalState([] as number[])
|
|
40
46
|
|
|
41
|
-
|
|
42
|
-
|
|
47
|
+
store.push(10)
|
|
48
|
+
store.unshift(100)
|
|
43
49
|
|
|
44
|
-
|
|
45
|
-
store.unshift(100)
|
|
50
|
+
const doubled = store.map(v => v * 2)
|
|
46
51
|
|
|
47
|
-
|
|
52
|
+
const val = store.get()
|
|
48
53
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
expect(val[0]).toBe(100)
|
|
52
|
-
expect(val[1]).toBe(10)
|
|
54
|
+
expect(val[0]).toBe(100)
|
|
55
|
+
expect(val[1]).toBe(10)
|
|
53
56
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
})
|
|
57
|
+
expect(doubled[0]).toBe(200)
|
|
58
|
+
expect(doubled[1]).toBe(20)
|
|
59
|
+
})
|
|
57
60
|
|
|
58
|
-
test(
|
|
59
|
-
|
|
61
|
+
test('store.listen()', () => {
|
|
62
|
+
const store = globalState(1)
|
|
60
63
|
|
|
61
|
-
|
|
64
|
+
store.listen((current, prev) => {
|
|
62
65
|
expect(current).toBe(4)
|
|
63
66
|
expect(prev).toBe(1)
|
|
64
|
-
|
|
67
|
+
})
|
|
65
68
|
|
|
66
|
-
|
|
69
|
+
store.set(4)
|
|
67
70
|
|
|
68
|
-
|
|
69
|
-
})
|
|
71
|
+
expect(store.get()).toBe(4)
|
|
72
|
+
})
|
|
73
|
+
})
|
package/src/tests/slice.spec.ts
CHANGED
|
@@ -1,48 +1,50 @@
|
|
|
1
|
-
import { expect, test } from
|
|
2
|
-
import {globalState} from '../globalState'
|
|
3
|
-
import { createStateSlice } from
|
|
4
|
-
|
|
5
|
-
test("slice selects consistently", () => {
|
|
6
|
-
const store = globalState({
|
|
7
|
-
a: 1,
|
|
8
|
-
b: "Test"
|
|
9
|
-
})
|
|
1
|
+
import { expect, test, describe } from 'bun:test'
|
|
2
|
+
import { globalState } from '../globalState'
|
|
3
|
+
import { createStateSlice } from '../utils'
|
|
10
4
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
describe('slice', () => {
|
|
6
|
+
test('slice selects consistently', () => {
|
|
7
|
+
const store = globalState({
|
|
8
|
+
a: 1,
|
|
9
|
+
b: 'Test'
|
|
10
|
+
})
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
const slice = createStateSlice(store,
|
|
13
|
+
(v: any) => v.a
|
|
14
|
+
)
|
|
18
15
|
|
|
19
|
-
|
|
16
|
+
store.set({
|
|
17
|
+
a: 4
|
|
18
|
+
})
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
a: 10
|
|
23
|
-
})
|
|
20
|
+
expect(slice.get()).toBe(4)
|
|
24
21
|
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
store.set({
|
|
23
|
+
a: 10
|
|
24
|
+
})
|
|
27
25
|
|
|
28
|
-
|
|
29
|
-
const store = globalState({
|
|
30
|
-
a: 1,
|
|
31
|
-
b: "Test"
|
|
26
|
+
expect(slice.get()).toBe(10)
|
|
32
27
|
})
|
|
33
28
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
29
|
+
test('slice sets consistently', () => {
|
|
30
|
+
const store = globalState({
|
|
31
|
+
a: 1,
|
|
32
|
+
b: 'Test'
|
|
33
|
+
})
|
|
38
34
|
|
|
39
|
-
|
|
35
|
+
const slice = createStateSlice(store,
|
|
36
|
+
(v: any) => v.a,
|
|
37
|
+
v => ({ a: v })
|
|
38
|
+
)
|
|
40
39
|
|
|
41
|
-
|
|
42
|
-
expect(store.get().a).toBe(4)
|
|
40
|
+
slice.set(4)
|
|
43
41
|
|
|
44
|
-
|
|
42
|
+
expect(slice.get()).toBe(4)
|
|
43
|
+
expect(store.get().a).toBe(4)
|
|
45
44
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
slice.set(10)
|
|
46
|
+
|
|
47
|
+
expect(slice.get()).toBe(10)
|
|
48
|
+
expect(store.get().a).toBe(10)
|
|
49
|
+
})
|
|
50
|
+
})
|