@tanstack/react-store 0.5.0 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tanstack/react-store",
3
3
  "author": "Tanner Linsley",
4
- "version": "0.5.0",
4
+ "version": "0.5.3",
5
5
  "license": "MIT",
6
6
  "repository": "tanstack/store",
7
7
  "homepage": "https://tanstack.com/",
@@ -46,7 +46,7 @@
46
46
  },
47
47
  "dependencies": {
48
48
  "use-sync-external-store": "^1.2.0",
49
- "@tanstack/store": "0.5.0"
49
+ "@tanstack/store": "0.5.3"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@types/use-sync-external-store": "^0.0.3",
@@ -1,132 +0,0 @@
1
- import { describe, expect, it, test, vi } from 'vitest'
2
- import { render, waitFor } from '@testing-library/react'
3
- import * as React from 'react'
4
- import { Store } from '@tanstack/store'
5
- import { useState } from 'react'
6
- import { userEvent } from '@testing-library/user-event'
7
- import { shallow, useStore } from '../index'
8
-
9
- const user = userEvent.setup()
10
-
11
- describe('useStore', () => {
12
- it('allows us to select state using a selector', async () => {
13
- const store = new Store({
14
- select: 0,
15
- ignored: 1,
16
- })
17
-
18
- function Comp() {
19
- const storeVal = useStore(store, (state) => state.select)
20
-
21
- return <p>Store: {storeVal}</p>
22
- }
23
-
24
- const { getByText } = render(<Comp />)
25
- expect(getByText('Store: 0')).toBeInTheDocument()
26
- })
27
-
28
- it('only triggers a re-render when selector state is updated', async () => {
29
- const store = new Store({
30
- select: 0,
31
- ignored: 1,
32
- })
33
-
34
- function Comp() {
35
- const storeVal = useStore(store, (state) => state.select)
36
- const [fn] = useState(vi.fn)
37
- fn()
38
-
39
- return (
40
- <div>
41
- <p>Number rendered: {fn.mock.calls.length}</p>
42
- <p>Store: {storeVal}</p>
43
- <button
44
- onClick={() =>
45
- store.setState((v) => ({
46
- ...v,
47
- select: 10,
48
- }))
49
- }
50
- >
51
- Update select
52
- </button>
53
- <button
54
- onClick={() =>
55
- store.setState((v) => ({
56
- ...v,
57
- ignored: 10,
58
- }))
59
- }
60
- >
61
- Update ignored
62
- </button>
63
- </div>
64
- )
65
- }
66
-
67
- const { getByText } = render(<Comp />)
68
- expect(getByText('Store: 0')).toBeInTheDocument()
69
- expect(getByText('Number rendered: 1')).toBeInTheDocument()
70
-
71
- await user.click(getByText('Update select'))
72
-
73
- await waitFor(() => expect(getByText('Store: 10')).toBeInTheDocument())
74
- expect(getByText('Number rendered: 2')).toBeInTheDocument()
75
-
76
- await user.click(getByText('Update ignored'))
77
- expect(getByText('Number rendered: 2')).toBeInTheDocument()
78
- })
79
- })
80
-
81
- describe('shallow', () => {
82
- test('should return true for shallowly equal objects', () => {
83
- const objA = { a: 1, b: 'hello' }
84
- const objB = { a: 1, b: 'hello' }
85
- expect(shallow(objA, objB)).toBe(true)
86
- })
87
-
88
- test('should return false for objects with different values', () => {
89
- const objA = { a: 1, b: 'hello' }
90
- const objB = { a: 2, b: 'world' }
91
- expect(shallow(objA, objB)).toBe(false)
92
- })
93
-
94
- test('should return false for objects with different keys', () => {
95
- const objA = { a: 1, b: 'hello' }
96
- const objB = { a: 1, c: 'world' }
97
- // @ts-ignore
98
- expect(shallow(objA, objB)).toBe(false)
99
- })
100
-
101
- test('should return false for objects with different structures', () => {
102
- const objA = { a: 1, b: 'hello' }
103
- const objB = [1, 'hello']
104
- // @ts-ignore
105
- expect(shallow(objA, objB)).toBe(false)
106
- })
107
-
108
- test('should return false for one object being null', () => {
109
- const objA = { a: 1, b: 'hello' }
110
- const objB = null
111
- expect(shallow(objA, objB)).toBe(false)
112
- })
113
-
114
- test('should return false for one object being undefined', () => {
115
- const objA = { a: 1, b: 'hello' }
116
- const objB = undefined
117
- expect(shallow(objA, objB)).toBe(false)
118
- })
119
-
120
- test('should return true for two null objects', () => {
121
- const objA = null
122
- const objB = null
123
- expect(shallow(objA, objB)).toBe(true)
124
- })
125
-
126
- test('should return false for objects with different types', () => {
127
- const objA = { a: 1, b: 'hello' }
128
- const objB = { a: '1', b: 'hello' }
129
- // @ts-ignore
130
- expect(shallow(objA, objB)).toBe(false)
131
- })
132
- })