react-state-custom 1.0.23 โ 1.0.25
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/LICENSE +21 -0
- package/README.md +85 -1
- package/dist/dev-tool/DataViewComponent.d.ts +6 -0
- package/dist/dev-tool/DevTool.d.ts +5 -0
- package/dist/dev-tool/DevToolState.d.ts +9 -0
- package/dist/dev-tool/StateLabelRender.d.ts +2 -0
- package/dist/dev-tool/useHighlight.d.ts +11 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.es.js +332 -488
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/react-state-custom.css +1 -1
- package/dist/state-utils/createAutoCtx.d.ts +1 -1
- package/dist/state-utils/createRootCtx.d.ts +1 -0
- package/dist/state-utils/ctx.d.ts +2 -1
- package/package.json +22 -3
- package/.github/copilot-instructions.md +0 -42
- package/.vscode/extensions.json +0 -5
- package/.vscode/settings.json +0 -8
- package/API_DOCUMENTATION.md +0 -883
- package/dist/DevTool.d.ts +0 -4
- package/dist/DevToolState.d.ts +0 -15
- package/dist/Test.d.ts +0 -1
- package/dist/dev.d.ts +0 -1
- package/fix-vscode-yarn-pnp.sh +0 -26
- package/index.html +0 -14
- package/src/DevTool.css +0 -218
- package/src/DevTool.tsx +0 -19
- package/src/DevToolState.tsx +0 -358
- package/src/Test.tsx +0 -97
- package/src/dev.tsx +0 -14
- package/src/index.ts +0 -21
- package/src/state-utils/createAutoCtx.tsx +0 -191
- package/src/state-utils/createRootCtx.tsx +0 -117
- package/src/state-utils/ctx.ts +0 -346
- package/src/state-utils/useArrayHash.ts +0 -53
- package/src/state-utils/useObjectHash.ts +0 -53
- package/src/state-utils/useQuickSubscribe.ts +0 -110
- package/src/state-utils/useRefValue.ts +0 -8
- package/src/state-utils/utils.ts +0 -43
- package/tsconfig.json +0 -18
- package/vite.config.dev.ts +0 -11
- package/vite.config.ts +0 -39
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Vo Thanh Dat
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -4,10 +4,16 @@
|
|
|
4
4
|
|
|
5
5
|
A lightweight React state management library that combines the simplicity of React hooks with the power of event-driven subscriptions. No boilerplate, no complexityโjust pure, performant state management.
|
|
6
6
|
|
|
7
|
+
[](https://vothanhdat.github.io/react-state-custom/)
|
|
8
|
+
[](https://www.npmjs.com/package/react-state-custom)
|
|
9
|
+
[](https://opensource.org/licenses/MIT)
|
|
10
|
+
|
|
7
11
|
```bash
|
|
8
12
|
npm install react-state-custom
|
|
9
13
|
```
|
|
10
14
|
|
|
15
|
+
๐ฎ **[Try the Live Demo โ](https://vothanhdat.github.io/react-state-custom/)**
|
|
16
|
+
|
|
11
17
|
## Why React State Custom?
|
|
12
18
|
|
|
13
19
|
**Zero Boilerplate** โข **Type-Safe** โข **Selective Re-renders** โข **Hook-Based** โข **~10KB Bundle**
|
|
@@ -105,7 +111,7 @@ Full type inference and type safety throughout. Your IDE knows exactly what's in
|
|
|
105
111
|
| **Boilerplate** | โ
None | โ Heavy | โ
Minimal |
|
|
106
112
|
| **Type Safety** | โ
Full inference | โ ๏ธ Requires setup | โ
Good |
|
|
107
113
|
| **Selective Re-renders** | โ
Built-in | โ ๏ธ Requires selectors | โ
Built-in |
|
|
108
|
-
| **DevTools** |
|
|
114
|
+
| **DevTools** | โ
Built-in UI | โ
Redux DevTools | โ
DevTools support |
|
|
109
115
|
| **Async Support** | โ
Native (hooks) | โ ๏ธ Requires middleware | โ
Native |
|
|
110
116
|
| **Context Composition** | โ
Automatic | โ Manual | โ ๏ธ Manual store combination |
|
|
111
117
|
|
|
@@ -243,6 +249,37 @@ const { useCtxState } = createAutoCtx(rootContext);
|
|
|
243
249
|
|
|
244
250
|
## ๐ Advanced Features
|
|
245
251
|
|
|
252
|
+
### Developer Tools
|
|
253
|
+
Visual debugging component to inspect all your context data in real-time:
|
|
254
|
+
|
|
255
|
+
```typescript
|
|
256
|
+
import { DevToolContainer } from 'react-state-custom';
|
|
257
|
+
import 'react-state-custom/dist/react-state-custom.css';
|
|
258
|
+
|
|
259
|
+
function App() {
|
|
260
|
+
return (
|
|
261
|
+
<>
|
|
262
|
+
<AutoRootCtx />
|
|
263
|
+
<YourAppContent />
|
|
264
|
+
<DevToolContainer />
|
|
265
|
+
</>
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
**Custom data viewer with rich object visualization:**
|
|
271
|
+
```typescript
|
|
272
|
+
import { DataViewComponent } from 'react-state-custom';
|
|
273
|
+
import { ObjectView } from 'react-obj-view';
|
|
274
|
+
import 'react-obj-view/dist/react-obj-view.css'; // Required for ObjectView styling
|
|
275
|
+
|
|
276
|
+
const CustomDataView: DataViewComponent = ({ name, value }) => {
|
|
277
|
+
return <ObjectView name={name} value={value} expandLevel={2} />;
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
<DevToolContainer Component={CustomDataView} />
|
|
281
|
+
```
|
|
282
|
+
|
|
246
283
|
### Parameterized Contexts
|
|
247
284
|
Create multiple instances of the same state with different parameters:
|
|
248
285
|
|
|
@@ -285,10 +322,57 @@ const userStats = useDataSubscribeWithTransform(
|
|
|
285
322
|
);
|
|
286
323
|
```
|
|
287
324
|
|
|
325
|
+
## ๐ฎ Live Examples
|
|
326
|
+
|
|
327
|
+
Explore interactive examples in the **[Live Demo](https://vothanhdat.github.io/react-state-custom/)**:
|
|
328
|
+
|
|
329
|
+
- **Counter** - Basic state management with increment, decrement, and reset
|
|
330
|
+
- **Todo List** - Multiple independent lists with scoped contexts
|
|
331
|
+
- **Form Validation** - Real-time validation with error handling
|
|
332
|
+
- **Timer** - Side effects and cleanup with millisecond precision
|
|
333
|
+
- **Shopping Cart** - Complex state with derived values (total, itemCount)
|
|
334
|
+
|
|
335
|
+
Each example includes live code editing with syntax highlighting, powered by Sandpack!
|
|
336
|
+
|
|
288
337
|
## ๐ Documentation
|
|
289
338
|
|
|
290
339
|
For complete API documentation, examples, and advanced patterns, see:
|
|
291
340
|
- **[API_DOCUMENTATION.md](./API_DOCUMENTATION.md)** - Complete API reference
|
|
341
|
+
- **[Live Demo](https://vothanhdat.github.io/react-state-custom/)** - Interactive examples
|
|
342
|
+
|
|
343
|
+
## ๐ ๏ธ Development
|
|
344
|
+
|
|
345
|
+
```bash
|
|
346
|
+
# Install dependencies
|
|
347
|
+
yarn install
|
|
348
|
+
|
|
349
|
+
# Run development UI with example selector
|
|
350
|
+
yarn dev
|
|
351
|
+
|
|
352
|
+
# Run interactive playground with live code editing
|
|
353
|
+
yarn dev:playground
|
|
354
|
+
|
|
355
|
+
# Build library
|
|
356
|
+
yarn build
|
|
357
|
+
|
|
358
|
+
# Build demo site
|
|
359
|
+
yarn build:demo
|
|
360
|
+
|
|
361
|
+
# Preview demo locally
|
|
362
|
+
yarn preview
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
### Development Modes
|
|
366
|
+
|
|
367
|
+
**`yarn dev`** - Starts a clean development UI with an interactive example selector. Great for:
|
|
368
|
+
- Testing all examples in one place
|
|
369
|
+
- Quick switching between different examples
|
|
370
|
+
- Visual debugging with DevTool component
|
|
371
|
+
|
|
372
|
+
**`yarn dev:playground`** - Starts the Sandpack-powered playground with live code editing. Perfect for:
|
|
373
|
+
- Creating interactive demos
|
|
374
|
+
- Live code editing and experimentation
|
|
375
|
+
- Sharing editable examples
|
|
292
376
|
|
|
293
377
|
## ๐ Learning Path
|
|
294
378
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { DataViewComponent } from './DataViewComponent';
|
|
3
|
+
export declare const DevToolState: React.FC<{
|
|
4
|
+
Component: DataViewComponent;
|
|
5
|
+
}>;
|
|
6
|
+
export declare const StateView: React.FC<{
|
|
7
|
+
dataKey: string;
|
|
8
|
+
Component: DataViewComponent;
|
|
9
|
+
}>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
export declare function useHighlight(filterString: string): {
|
|
3
|
+
highlight: RegExp;
|
|
4
|
+
};
|
|
5
|
+
export declare const HightlightWrapper: React.FC<{
|
|
6
|
+
highlight: string;
|
|
7
|
+
children: any;
|
|
8
|
+
}>;
|
|
9
|
+
export declare const HighlightString: React.FC<{
|
|
10
|
+
text: string;
|
|
11
|
+
}>;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ export { createRootCtx } from './state-utils/createRootCtx';
|
|
|
3
3
|
export { AutoRootCtx, createAutoCtx } from './state-utils/createAutoCtx';
|
|
4
4
|
export { useArrayHash } from './state-utils/useArrayHash';
|
|
5
5
|
export { useQuickSubscribe } from './state-utils/useQuickSubscribe';
|
|
6
|
-
export { DevToolContainer } from './DevTool';
|
|
6
|
+
export { DevToolContainer } from './dev-tool/DevTool';
|
|
7
|
+
export type { DataViewComponent } from './dev-tool/DataViewComponent';
|