13 |
Todo App with anyState React Hooks
14 |
This version uses the new useAnyState hook for cleaner integration
15 | {
16 | (todos || []).map((todo, index) => (
17 |
18 | ))
19 | }
20 |
21 |
22 | );
23 | }
24 |
25 | export default AppWithHooks;
--------------------------------------------------------------------------------
/test/performance.js:
--------------------------------------------------------------------------------
1 | const assert = require('assert');
2 | const { createStore } = require('../dist/index');
3 |
4 | describe('Performance', () => {
5 | let logs = [];
6 | const originalLog = console.log;
7 | beforeEach(() => {
8 | console.log = (...args) => {
9 | logs.push(args.join(' '));
10 | };
11 | });
12 | afterEach(() => {
13 | console.log = originalLog;
14 | logs = [];
15 | });
16 |
17 | it('should track performance', () => {
18 | const store = createStore({ a: 1 });
19 | store.setState({ a: 2 });
20 | assert.strictEqual(store.getState().a, 2);
21 | assert.ok(logs.some(log => log.includes('setState took')));
22 | assert.ok(logs.some(log => log.includes('getState took')));
23 | });
24 |
25 | it('should track memory', () => {
26 | const store = createStore({ a: 1 });
27 | store.logMemoryUsage();
28 | assert.ok(logs.some(log => log.includes('State memory usage')));
29 | });
30 | });
31 |
--------------------------------------------------------------------------------
/examples/todo-react/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "todo-react",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@testing-library/jest-dom": "^5.16.5",
7 | "@testing-library/react": "^13.3.0",
8 | "@testing-library/user-event": "^13.5.0",
9 | "anystate": "0.0.2-a",
10 | "react": "^18.2.0",
11 | "react-dom": "^18.2.0",
12 | "react-scripts": "5.0.1",
13 | "web-vitals": "^2.1.4"
14 | },
15 | "scripts": {
16 | "start": "react-scripts start",
17 | "build": "react-scripts build",
18 | "test": "react-scripts test",
19 | "eject": "react-scripts eject"
20 | },
21 | "eslintConfig": {
22 | "extends": [
23 | "react-app",
24 | "react-app/jest"
25 | ]
26 | },
27 | "browserslist": {
28 | "production": [
29 | ">0.2%",
30 | "not dead",
31 | "not op_mini all"
32 | ],
33 | "development": [
34 | "last 1 chrome version",
35 | "last 1 firefox version",
36 | "last 1 safari version"
37 | ]
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/License.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 Vy Quốc Vũ
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.
22 |
--------------------------------------------------------------------------------
/examples/todo-svelte/public/global.css:
--------------------------------------------------------------------------------
1 | html, body {
2 | position: relative;
3 | width: 100%;
4 | height: 100%;
5 | }
6 |
7 | body {
8 | color: #333;
9 | margin: 0;
10 | padding: 8px;
11 | box-sizing: border-box;
12 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
13 | }
14 |
15 | a {
16 | color: rgb(0,100,200);
17 | text-decoration: none;
18 | }
19 |
20 | a:hover {
21 | text-decoration: underline;
22 | }
23 |
24 | a:visited {
25 | color: rgb(0,80,160);
26 | }
27 |
28 | label {
29 | display: block;
30 | }
31 |
32 | input, button, select, textarea {
33 | font-family: inherit;
34 | font-size: inherit;
35 | -webkit-padding: 0.4em 0;
36 | padding: 0.4em;
37 | margin: 0 0 0.5em 0;
38 | box-sizing: border-box;
39 | border: 1px solid #ccc;
40 | border-radius: 2px;
41 | }
42 |
43 | input:disabled {
44 | color: #ccc;
45 | }
46 |
47 | button {
48 | color: #333;
49 | background-color: #f4f4f4;
50 | outline: none;
51 | }
52 |
53 | button:disabled {
54 | color: #999;
55 | }
56 |
57 | button:not(:disabled):active {
58 | background-color: #ddd;
59 | }
60 |
61 | button:focus {
62 | border-color: #666;
63 | }
64 |
--------------------------------------------------------------------------------
/src/devtools.ts:
--------------------------------------------------------------------------------
1 | import type { Key } from './type';
2 |
3 | declare global {
4 | interface Window {
5 | __REDUX_DEVTOOLS_EXTENSION__: any;
6 | }
7 | }
8 |
9 | type Action = {
10 | type: string;
11 | payload?: any;
12 | };
13 |
14 | type DevTools = {
15 | send: (action: Action, state: any) => void;
16 | subscribe: (listener: (message: any) => void) => () => void;
17 | init: (state: any) => void;
18 | };
19 |
20 | let devTools: DevTools | null = null;
21 |
22 | export const connectDevTools =