@uistate/examples 1.0.0

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.
Files changed (137) hide show
  1. package/README.md +40 -0
  2. package/cssState/.gitkeep +0 -0
  3. package/eventState/001-counter/README.md +44 -0
  4. package/eventState/001-counter/index.html +33 -0
  5. package/eventState/002-counter-improved/README.md +44 -0
  6. package/eventState/002-counter-improved/index.html +47 -0
  7. package/eventState/003-input-reactive/README.md +44 -0
  8. package/eventState/003-input-reactive/index.html +33 -0
  9. package/eventState/004-computed-state/README.md +45 -0
  10. package/eventState/004-computed-state/index.html +65 -0
  11. package/eventState/005-conditional-rendering/README.md +42 -0
  12. package/eventState/005-conditional-rendering/index.html +39 -0
  13. package/eventState/006-list-rendering/README.md +49 -0
  14. package/eventState/006-list-rendering/index.html +63 -0
  15. package/eventState/007-form-validation/README.md +52 -0
  16. package/eventState/007-form-validation/index.html +102 -0
  17. package/eventState/008-undo-redo/README.md +70 -0
  18. package/eventState/008-undo-redo/index.html +108 -0
  19. package/eventState/009-localStorage-side-effects/README.md +72 -0
  20. package/eventState/009-localStorage-side-effects/index.html +57 -0
  21. package/eventState/010-decoupled-components/README.md +74 -0
  22. package/eventState/010-decoupled-components/index.html +93 -0
  23. package/eventState/011-async-patterns/README.md +98 -0
  24. package/eventState/011-async-patterns/index.html +132 -0
  25. package/eventState/028-counter-improved-eventTest/LICENSE +55 -0
  26. package/eventState/028-counter-improved-eventTest/README.md +131 -0
  27. package/eventState/028-counter-improved-eventTest/app/store.js +9 -0
  28. package/eventState/028-counter-improved-eventTest/index.html +49 -0
  29. package/eventState/028-counter-improved-eventTest/runtime/core/behaviors.runtime.js +282 -0
  30. package/eventState/028-counter-improved-eventTest/runtime/core/eventState.js +100 -0
  31. package/eventState/028-counter-improved-eventTest/runtime/core/eventStateNew.js +149 -0
  32. package/eventState/028-counter-improved-eventTest/runtime/core/helpers.js +212 -0
  33. package/eventState/028-counter-improved-eventTest/runtime/core/router.js +271 -0
  34. package/eventState/028-counter-improved-eventTest/store.d.ts +8 -0
  35. package/eventState/028-counter-improved-eventTest/style.css +170 -0
  36. package/eventState/028-counter-improved-eventTest/tests/README.md +208 -0
  37. package/eventState/028-counter-improved-eventTest/tests/counter.test.js +116 -0
  38. package/eventState/028-counter-improved-eventTest/tests/eventTest.js +176 -0
  39. package/eventState/028-counter-improved-eventTest/tests/generateTypes.js +168 -0
  40. package/eventState/028-counter-improved-eventTest/tests/run.js +20 -0
  41. package/eventState/030-todo-app-with-eventTest/LICENSE +55 -0
  42. package/eventState/030-todo-app-with-eventTest/README.md +121 -0
  43. package/eventState/030-todo-app-with-eventTest/app/router.js +25 -0
  44. package/eventState/030-todo-app-with-eventTest/app/store.js +16 -0
  45. package/eventState/030-todo-app-with-eventTest/app/views/home.js +11 -0
  46. package/eventState/030-todo-app-with-eventTest/app/views/todoDemo.js +88 -0
  47. package/eventState/030-todo-app-with-eventTest/index.html +65 -0
  48. package/eventState/030-todo-app-with-eventTest/runtime/core/behaviors.runtime.js +282 -0
  49. package/eventState/030-todo-app-with-eventTest/runtime/core/eventState.js +100 -0
  50. package/eventState/030-todo-app-with-eventTest/runtime/core/eventStateNew.js +149 -0
  51. package/eventState/030-todo-app-with-eventTest/runtime/core/helpers.js +212 -0
  52. package/eventState/030-todo-app-with-eventTest/runtime/core/router.js +271 -0
  53. package/eventState/030-todo-app-with-eventTest/store.d.ts +18 -0
  54. package/eventState/030-todo-app-with-eventTest/style.css +170 -0
  55. package/eventState/030-todo-app-with-eventTest/tests/README.md +208 -0
  56. package/eventState/030-todo-app-with-eventTest/tests/eventTest.js +176 -0
  57. package/eventState/030-todo-app-with-eventTest/tests/generateTypes.js +189 -0
  58. package/eventState/030-todo-app-with-eventTest/tests/run.js +20 -0
  59. package/eventState/030-todo-app-with-eventTest/tests/todos.test.js +167 -0
  60. package/eventState/031-todo-app-with-eventTest/LICENSE +55 -0
  61. package/eventState/031-todo-app-with-eventTest/README.md +54 -0
  62. package/eventState/031-todo-app-with-eventTest/TUTORIAL.md +390 -0
  63. package/eventState/031-todo-app-with-eventTest/WHY_EVENTSTATE.md +777 -0
  64. package/eventState/031-todo-app-with-eventTest/app/bridges.js +113 -0
  65. package/eventState/031-todo-app-with-eventTest/app/router.js +26 -0
  66. package/eventState/031-todo-app-with-eventTest/app/store.js +15 -0
  67. package/eventState/031-todo-app-with-eventTest/app/views/home.js +46 -0
  68. package/eventState/031-todo-app-with-eventTest/app/views/todoDemo.js +69 -0
  69. package/eventState/031-todo-app-with-eventTest/devtools/dock.js +41 -0
  70. package/eventState/031-todo-app-with-eventTest/devtools/stateTracker.dock.js +10 -0
  71. package/eventState/031-todo-app-with-eventTest/devtools/stateTracker.js +246 -0
  72. package/eventState/031-todo-app-with-eventTest/devtools/telemetry.js +104 -0
  73. package/eventState/031-todo-app-with-eventTest/devtools/typeGenerator.js +339 -0
  74. package/eventState/031-todo-app-with-eventTest/index.html +103 -0
  75. package/eventState/031-todo-app-with-eventTest/package-lock.json +2184 -0
  76. package/eventState/031-todo-app-with-eventTest/package.json +24 -0
  77. package/eventState/031-todo-app-with-eventTest/runtime/core/behaviors.runtime.js +282 -0
  78. package/eventState/031-todo-app-with-eventTest/runtime/core/eventState.js +100 -0
  79. package/eventState/031-todo-app-with-eventTest/runtime/core/eventStateNew.js +149 -0
  80. package/eventState/031-todo-app-with-eventTest/runtime/core/helpers.js +212 -0
  81. package/eventState/031-todo-app-with-eventTest/runtime/core/router.js +271 -0
  82. package/eventState/031-todo-app-with-eventTest/runtime/extensions/boundary.js +36 -0
  83. package/eventState/031-todo-app-with-eventTest/runtime/extensions/converge.js +63 -0
  84. package/eventState/031-todo-app-with-eventTest/runtime/extensions/eventState.plus.js +210 -0
  85. package/eventState/031-todo-app-with-eventTest/runtime/extensions/hydrate.js +157 -0
  86. package/eventState/031-todo-app-with-eventTest/runtime/extensions/queryBinding.js +69 -0
  87. package/eventState/031-todo-app-with-eventTest/runtime/forms/computed.js +78 -0
  88. package/eventState/031-todo-app-with-eventTest/runtime/forms/meta.js +51 -0
  89. package/eventState/031-todo-app-with-eventTest/runtime/forms/submitWithBoundary.js +28 -0
  90. package/eventState/031-todo-app-with-eventTest/runtime/forms/validators.js +55 -0
  91. package/eventState/031-todo-app-with-eventTest/store.d.ts +23 -0
  92. package/eventState/031-todo-app-with-eventTest/style.css +170 -0
  93. package/eventState/031-todo-app-with-eventTest/tests/README.md +208 -0
  94. package/eventState/031-todo-app-with-eventTest/tests/eventTest.js +176 -0
  95. package/eventState/031-todo-app-with-eventTest/tests/generateTypes.js +191 -0
  96. package/eventState/031-todo-app-with-eventTest/tests/run.js +20 -0
  97. package/eventState/031-todo-app-with-eventTest/tests/todos.test.js +192 -0
  98. package/eventState/032-todo-app-with-eventTest/LICENSE +55 -0
  99. package/eventState/032-todo-app-with-eventTest/README.md +54 -0
  100. package/eventState/032-todo-app-with-eventTest/TUTORIAL.md +390 -0
  101. package/eventState/032-todo-app-with-eventTest/WHY_EVENTSTATE.md +777 -0
  102. package/eventState/032-todo-app-with-eventTest/app/actions/index.js +153 -0
  103. package/eventState/032-todo-app-with-eventTest/app/bridges.js +113 -0
  104. package/eventState/032-todo-app-with-eventTest/app/router.js +26 -0
  105. package/eventState/032-todo-app-with-eventTest/app/store.js +15 -0
  106. package/eventState/032-todo-app-with-eventTest/app/views/home.js +46 -0
  107. package/eventState/032-todo-app-with-eventTest/app/views/todoDemo.js +69 -0
  108. package/eventState/032-todo-app-with-eventTest/devtools/dock.js +41 -0
  109. package/eventState/032-todo-app-with-eventTest/devtools/stateTracker.dock.js +10 -0
  110. package/eventState/032-todo-app-with-eventTest/devtools/stateTracker.js +246 -0
  111. package/eventState/032-todo-app-with-eventTest/devtools/telemetry.js +104 -0
  112. package/eventState/032-todo-app-with-eventTest/devtools/typeGenerator.js +339 -0
  113. package/eventState/032-todo-app-with-eventTest/index.html +87 -0
  114. package/eventState/032-todo-app-with-eventTest/package-lock.json +2184 -0
  115. package/eventState/032-todo-app-with-eventTest/package.json +24 -0
  116. package/eventState/032-todo-app-with-eventTest/runtime/core/behaviors.runtime.js +282 -0
  117. package/eventState/032-todo-app-with-eventTest/runtime/core/eventState.js +100 -0
  118. package/eventState/032-todo-app-with-eventTest/runtime/core/eventStateNew.js +149 -0
  119. package/eventState/032-todo-app-with-eventTest/runtime/core/helpers.js +212 -0
  120. package/eventState/032-todo-app-with-eventTest/runtime/core/router.js +271 -0
  121. package/eventState/032-todo-app-with-eventTest/runtime/extensions/boundary.js +36 -0
  122. package/eventState/032-todo-app-with-eventTest/runtime/extensions/converge.js +63 -0
  123. package/eventState/032-todo-app-with-eventTest/runtime/extensions/eventState.plus.js +210 -0
  124. package/eventState/032-todo-app-with-eventTest/runtime/extensions/hydrate.js +157 -0
  125. package/eventState/032-todo-app-with-eventTest/runtime/extensions/queryBinding.js +69 -0
  126. package/eventState/032-todo-app-with-eventTest/runtime/forms/computed.js +78 -0
  127. package/eventState/032-todo-app-with-eventTest/runtime/forms/meta.js +51 -0
  128. package/eventState/032-todo-app-with-eventTest/runtime/forms/submitWithBoundary.js +28 -0
  129. package/eventState/032-todo-app-with-eventTest/runtime/forms/validators.js +55 -0
  130. package/eventState/032-todo-app-with-eventTest/store.d.ts +23 -0
  131. package/eventState/032-todo-app-with-eventTest/style.css +170 -0
  132. package/eventState/032-todo-app-with-eventTest/tests/README.md +208 -0
  133. package/eventState/032-todo-app-with-eventTest/tests/eventTest.js +176 -0
  134. package/eventState/032-todo-app-with-eventTest/tests/generateTypes.js +191 -0
  135. package/eventState/032-todo-app-with-eventTest/tests/run.js +20 -0
  136. package/eventState/032-todo-app-with-eventTest/tests/todos.test.js +192 -0
  137. package/package.json +27 -0
@@ -0,0 +1,116 @@
1
+ /**
2
+ * counter.test.js - Event-sequence tests for counter functionality
3
+ *
4
+ * These tests verify direct state manipulation for counter operations
5
+ */
6
+
7
+ import { createEventTest, test, runTests } from './eventTest.js';
8
+
9
+ // Helper functions that match the view logic
10
+ function increment(store) {
11
+ const current = store.get('count');
12
+ store.set('count', current + 1);
13
+ }
14
+
15
+ function decrement(store) {
16
+ const current = store.get('count');
17
+ store.set('count', current - 1);
18
+ }
19
+
20
+ function double(store) {
21
+ const current = store.get('count');
22
+ store.set('count', current * 2);
23
+ }
24
+
25
+ // Test suite
26
+ const tests = {
27
+ 'increment increases count by 1': () => {
28
+ const t = createEventTest({ count: 0 });
29
+
30
+ increment(t.store);
31
+
32
+ // Assert type
33
+ t.assertType('count', 'number');
34
+
35
+ // Assert value
36
+ const count = t.store.get('count');
37
+ if (count !== 1) {
38
+ throw new Error(`Expected count to be 1, got ${count}`);
39
+ }
40
+ },
41
+
42
+ 'decrement decreases count by 1': () => {
43
+ const t = createEventTest({ count: 5 });
44
+
45
+ decrement(t.store);
46
+
47
+ // Assert type
48
+ t.assertType('count', 'number');
49
+
50
+ // Assert value
51
+ const count = t.store.get('count');
52
+ if (count !== 4) {
53
+ throw new Error(`Expected count to be 4, got ${count}`);
54
+ }
55
+ },
56
+
57
+ 'double multiplies count by 2': () => {
58
+ const t = createEventTest({ count: 3 });
59
+
60
+ double(t.store);
61
+
62
+ // Assert type
63
+ t.assertType('count', 'number');
64
+
65
+ // Assert value
66
+ const count = t.store.get('count');
67
+ if (count !== 6) {
68
+ throw new Error(`Expected count to be 6, got ${count}`);
69
+ }
70
+ },
71
+
72
+ 'multiple increments work correctly': () => {
73
+ const t = createEventTest({ count: 0 });
74
+
75
+ increment(t.store);
76
+ increment(t.store);
77
+ increment(t.store);
78
+
79
+ const count = t.store.get('count');
80
+ if (count !== 3) {
81
+ throw new Error(`Expected count to be 3, got ${count}`);
82
+ }
83
+ },
84
+
85
+ 'mixed operations work correctly': () => {
86
+ const t = createEventTest({ count: 10 });
87
+
88
+ increment(t.store); // 11
89
+ double(t.store); // 22
90
+ decrement(t.store); // 21
91
+
92
+ const count = t.store.get('count');
93
+ if (count !== 21) {
94
+ throw new Error(`Expected count to be 21, got ${count}`);
95
+ }
96
+ },
97
+
98
+ 'count can go negative': () => {
99
+ const t = createEventTest({ count: 0 });
100
+
101
+ decrement(t.store);
102
+ decrement(t.store);
103
+
104
+ const count = t.store.get('count');
105
+ if (count !== -2) {
106
+ throw new Error(`Expected count to be -2, got ${count}`);
107
+ }
108
+ }
109
+ };
110
+
111
+ // Run tests if executed directly
112
+ if (import.meta.url === `file://${process.argv[1]}`) {
113
+ runTests(tests);
114
+ }
115
+
116
+ export default tests;
@@ -0,0 +1,176 @@
1
+ /**
2
+ * eventTest.js - Event-Sequence Testing for EventState
3
+ *
4
+ * Provides TDD-style testing with type extraction capabilities
5
+ */
6
+
7
+ import { createEventState } from '../runtime/core/eventStateNew.js';
8
+
9
+ export function createEventTest(initialState = {}) {
10
+ const store = createEventState(initialState);
11
+ const eventLog = [];
12
+ const typeAssertions = [];
13
+
14
+ // Spy on all events
15
+ store.subscribe('*', (detail) => {
16
+ const { path, value } = detail;
17
+ eventLog.push({ timestamp: Date.now(), path, value });
18
+ });
19
+
20
+ const api = {
21
+ store,
22
+
23
+ // Trigger a state change
24
+ trigger(path, value) {
25
+ store.set(path, value);
26
+ return this;
27
+ },
28
+
29
+ // Assert exact value
30
+ assertPath(path, expected) {
31
+ const actual = store.get(path);
32
+ if (JSON.stringify(actual) !== JSON.stringify(expected)) {
33
+ throw new Error(`Expected ${path} to be ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}`);
34
+ }
35
+ return this;
36
+ },
37
+
38
+ // Assert type (for type generation)
39
+ assertType(path, expectedType) {
40
+ const actual = store.get(path);
41
+ const actualType = typeof actual;
42
+
43
+ if (actualType !== expectedType) {
44
+ throw new Error(`Expected ${path} to be type ${expectedType}, got ${actualType}`);
45
+ }
46
+
47
+ // Store for type generation
48
+ typeAssertions.push({ path, type: expectedType });
49
+ return this;
50
+ },
51
+
52
+ // Assert array with element shape (for type generation)
53
+ assertArrayOf(path, elementShape) {
54
+ const actual = store.get(path);
55
+
56
+ if (!Array.isArray(actual)) {
57
+ throw new Error(`Expected ${path} to be an array, got ${typeof actual}`);
58
+ }
59
+
60
+ // Validate first element matches shape (if array not empty)
61
+ if (actual.length > 0) {
62
+ validateShape(actual[0], elementShape, path);
63
+ }
64
+
65
+ // Store for type generation
66
+ typeAssertions.push({ path, type: 'array', elementShape });
67
+ return this;
68
+ },
69
+
70
+ // Assert object shape (for type generation)
71
+ assertShape(path, objectShape) {
72
+ const actual = store.get(path);
73
+
74
+ if (typeof actual !== 'object' || actual === null || Array.isArray(actual)) {
75
+ throw new Error(`Expected ${path} to be an object, got ${typeof actual}`);
76
+ }
77
+
78
+ validateShape(actual, objectShape, path);
79
+
80
+ // Store for type generation
81
+ typeAssertions.push({ path, type: 'object', shape: objectShape });
82
+ return this;
83
+ },
84
+
85
+ // Assert array length
86
+ assertArrayLength(path, expectedLength) {
87
+ const actual = store.get(path);
88
+
89
+ if (!Array.isArray(actual)) {
90
+ throw new Error(`Expected ${path} to be an array`);
91
+ }
92
+
93
+ if (actual.length !== expectedLength) {
94
+ throw new Error(`Expected ${path} to have length ${expectedLength}, got ${actual.length}`);
95
+ }
96
+
97
+ return this;
98
+ },
99
+
100
+ // Assert event fired N times
101
+ assertEventFired(path, times) {
102
+ const count = eventLog.filter(e => e.path === path).length;
103
+ if (times !== undefined && count !== times) {
104
+ throw new Error(`Expected ${path} to fire ${times} times, fired ${count}`);
105
+ }
106
+ return this;
107
+ },
108
+
109
+ // Get event log
110
+ getEventLog() {
111
+ return [...eventLog];
112
+ },
113
+
114
+ // Get type assertions (for type generation)
115
+ getTypeAssertions() {
116
+ return [...typeAssertions];
117
+ }
118
+ };
119
+
120
+ return api;
121
+ }
122
+
123
+ // Helper to validate object shape
124
+ function validateShape(actual, shape, path) {
125
+ for (const [key, expectedType] of Object.entries(shape)) {
126
+ if (!(key in actual)) {
127
+ throw new Error(`Expected ${path} to have property ${key}`);
128
+ }
129
+
130
+ const actualValue = actual[key];
131
+
132
+ // Handle nested objects
133
+ if (typeof expectedType === 'object' && !Array.isArray(expectedType)) {
134
+ validateShape(actualValue, expectedType, `${path}.${key}`);
135
+ } else {
136
+ // Primitive type check
137
+ const actualType = typeof actualValue;
138
+ if (actualType !== expectedType) {
139
+ throw new Error(`Expected ${path}.${key} to be type ${expectedType}, got ${actualType}`);
140
+ }
141
+ }
142
+ }
143
+ }
144
+
145
+ // Simple test runner
146
+ export function test(name, fn) {
147
+ try {
148
+ fn();
149
+ console.log(`✓ ${name}`);
150
+ return true;
151
+ } catch (error) {
152
+ console.error(`✗ ${name}`);
153
+ console.error(` ${error.message}`);
154
+ return false;
155
+ }
156
+ }
157
+
158
+ // Run multiple tests
159
+ export function runTests(tests) {
160
+ console.log('\n🧪 Running tests...\n');
161
+
162
+ let passed = 0;
163
+ let failed = 0;
164
+
165
+ for (const [name, fn] of Object.entries(tests)) {
166
+ if (test(name, fn)) {
167
+ passed++;
168
+ } else {
169
+ failed++;
170
+ }
171
+ }
172
+
173
+ console.log(`\n📊 Results: ${passed} passed, ${failed} failed\n`);
174
+
175
+ return { passed, failed };
176
+ }
@@ -0,0 +1,168 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * generateTypes.js - Generate TypeScript definitions from test assertions
4
+ *
5
+ * Usage: node tests/generateTypes.js
6
+ */
7
+
8
+ import { createEventTest } from './eventTest.js';
9
+ import todosTests from './todos.test.js';
10
+ import { writeFileSync } from 'fs';
11
+ import { fileURLToPath } from 'url';
12
+ import { dirname, join } from 'path';
13
+
14
+ const __filename = fileURLToPath(import.meta.url);
15
+ const __dirname = dirname(__filename);
16
+
17
+ // Collect all type assertions from tests
18
+ const allAssertions = [];
19
+
20
+ console.log('🔍 Extracting types from tests...\n');
21
+
22
+ for (const [name, testFn] of Object.entries(todosTests)) {
23
+ try {
24
+ // Run test to collect assertions
25
+ testFn();
26
+ console.log(`✓ ${name}`);
27
+ } catch (error) {
28
+ // Test might fail, but we still want type assertions
29
+ console.log(`⚠ ${name} (failed but types extracted)`);
30
+ }
31
+ }
32
+
33
+ // Simple type generator (minimal version for Node.js)
34
+ class SimpleTypeGenerator {
35
+ constructor() {
36
+ this.pathTypes = new Map();
37
+ }
38
+
39
+ parseAssertions(assertions) {
40
+ for (const assertion of assertions) {
41
+ const { path, type, elementShape, shape } = assertion;
42
+
43
+ if (type === 'array' && elementShape) {
44
+ this.pathTypes.set(path, {
45
+ type: 'array',
46
+ element: elementShape
47
+ });
48
+ } else if (type === 'object' && shape) {
49
+ this.pathTypes.set(path, {
50
+ type: 'object',
51
+ shape: shape
52
+ });
53
+ } else if (type) {
54
+ this.pathTypes.set(path, { type });
55
+ }
56
+ }
57
+ }
58
+
59
+ buildTree() {
60
+ const tree = {};
61
+
62
+ for (const [path, typeInfo] of this.pathTypes) {
63
+ const parts = path.split('.');
64
+ let current = tree;
65
+
66
+ for (let i = 0; i < parts.length; i++) {
67
+ const part = parts[i];
68
+
69
+ if (i === parts.length - 1) {
70
+ current[part] = { __typeInfo: typeInfo };
71
+ } else {
72
+ if (!current[part]) {
73
+ current[part] = {};
74
+ }
75
+ current = current[part];
76
+ }
77
+ }
78
+ }
79
+
80
+ return tree;
81
+ }
82
+
83
+ formatType(typeInfo) {
84
+ if (typeof typeInfo === 'string') return typeInfo;
85
+
86
+ if (typeInfo.type === 'array' && typeInfo.element) {
87
+ const elementType = this.formatShape(typeInfo.element);
88
+ return `Array<${elementType}>`;
89
+ }
90
+
91
+ if (typeInfo.type === 'object' && typeInfo.shape) {
92
+ return this.formatShape(typeInfo.shape);
93
+ }
94
+
95
+ return typeInfo.type || 'unknown';
96
+ }
97
+
98
+ formatShape(shape) {
99
+ if (typeof shape === 'string') return shape;
100
+
101
+ const props = Object.entries(shape)
102
+ .map(([k, v]) => {
103
+ const type = typeof v === 'string' ? v : this.formatShape(v);
104
+ return `${k}: ${type}`;
105
+ })
106
+ .join('; ');
107
+
108
+ return `{ ${props} }`;
109
+ }
110
+
111
+ generateInterface(obj, indent = 0) {
112
+ const lines = [];
113
+ const spaces = ' '.repeat(indent);
114
+
115
+ for (const [key, value] of Object.entries(obj)) {
116
+ if (value.__typeInfo) {
117
+ const type = this.formatType(value.__typeInfo);
118
+ lines.push(`${spaces}${key}: ${type};`);
119
+ } else {
120
+ lines.push(`${spaces}${key}: {`);
121
+ lines.push(this.generateInterface(value, indent + 1));
122
+ lines.push(`${spaces}};`);
123
+ }
124
+ }
125
+
126
+ return lines.join('\n');
127
+ }
128
+
129
+ generateDTS() {
130
+ const lines = [
131
+ '// Auto-generated from test assertions',
132
+ '// DO NOT EDIT - regenerate by running: node tests/generateTypes.js',
133
+ '',
134
+ 'export interface StoreState {',
135
+ ];
136
+
137
+ const tree = this.buildTree();
138
+ lines.push(this.generateInterface(tree, 1));
139
+ lines.push('}');
140
+ lines.push('');
141
+ lines.push('export default StoreState;');
142
+ lines.push('');
143
+
144
+ return lines.join('\n');
145
+ }
146
+ }
147
+
148
+ // Note: We need to actually collect assertions from test execution
149
+ // For now, manually define expected types based on test assertions
150
+ const manualAssertions = [
151
+ {
152
+ path: 'count',
153
+ type: 'number'
154
+ }
155
+ ];
156
+
157
+ const generator = new SimpleTypeGenerator();
158
+ generator.parseAssertions(manualAssertions);
159
+
160
+ const dts = generator.generateDTS();
161
+
162
+ // Write to file
163
+ const outputPath = join(__dirname, '..', 'store.d.ts');
164
+ writeFileSync(outputPath, dts, 'utf-8');
165
+
166
+ console.log(`\n✅ Generated ${outputPath}`);
167
+ console.log('\n📝 Type definitions:\n');
168
+ console.log(dts);
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * run.js - Test runner for Node.js
4
+ *
5
+ * Usage: node tests/run.js
6
+ */
7
+
8
+ import { runTests } from './eventTest.js';
9
+ import counterTests from './counter.test.js';
10
+
11
+ // Combine all test suites
12
+ const allTests = {
13
+ ...counterTests
14
+ };
15
+
16
+ // Run tests
17
+ const results = runTests(allTests);
18
+
19
+ // Exit with appropriate code
20
+ process.exit(results.failed > 0 ? 1 : 0);
@@ -0,0 +1,55 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
10
+
11
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
12
+
13
+ "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
14
+
15
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
16
+
17
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
18
+
19
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
20
+
21
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work.
22
+
23
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
24
+
25
+ "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
26
+
27
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
28
+
29
+ 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
30
+
31
+ 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
32
+
33
+ 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
34
+
35
+ (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
36
+
37
+ (b) You must cause any modified files to carry prominent notices stating that You changed the files; and
38
+
39
+ (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
40
+
41
+ (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
42
+
43
+ You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
44
+
45
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
46
+
47
+ 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
48
+
49
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
50
+
51
+ 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
52
+
53
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
54
+
55
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,121 @@
1
+ # 030 Todo App with eventTest
2
+
3
+ A complete todo app demonstrating the UIstate framework features, bridging from the simple examples (001-011) to a real application.
4
+
5
+ ## What This Example Shows
6
+
7
+ This is the **bridge** between learning the primitive (`eventState.js`) and using the full framework:
8
+
9
+ ✅ **Same primitive from 001-011** - `runtime/core/eventState.js` (~80 lines)
10
+ ✅ **Declarative templates** - `data-bind` and `data-on` attributes
11
+ ✅ **Client-side routing** - Multi-page SPA with loading states
12
+ ✅ **Event-sequence testing** - `eventTest.js` for testing state changes
13
+ ✅ **Direct state manipulation** - No action registry, just `store.set()`
14
+
15
+ ## Structure
16
+
17
+ ```
18
+ app/
19
+ ├── store.js → Store initialization
20
+ ├── router.js → Route configuration
21
+ └── views/
22
+ ├── home.js → Simple counter view
23
+ └── todoDemo.js → Todo app with add/toggle/filter
24
+
25
+ runtime/core/
26
+ ├── eventState.js → The 80-line reactive primitive
27
+ ├── behaviors.runtime.js → Declarative bindings (data-bind, data-on)
28
+ └── router.js → Simple client-side router
29
+
30
+ tests/
31
+ ├── eventTest.js → Event-sequence testing framework
32
+ ├── todos.test.js → Tests for todo app
33
+ └── run.js → Test runner
34
+ ```
35
+
36
+ ## Key Features
37
+
38
+ ### 1. Direct State Manipulation
39
+
40
+ Views use `store.set()` directly - no action registry:
41
+
42
+ ```javascript
43
+ // Add todo
44
+ const items = store.get('todos.items') || [];
45
+ const newTodo = { id: Date.now(), text, done: false };
46
+ store.set('todos.items', [...items, newTodo]);
47
+
48
+ // Toggle todo
49
+ const updated = items.map(item =>
50
+ item.id === t.id ? { ...item, done: !item.done } : item
51
+ );
52
+ store.set('todos.items', updated);
53
+ ```
54
+
55
+ ### 2. Declarative Bindings
56
+
57
+ HTML attributes for reactive UI:
58
+
59
+ ```html
60
+ <!-- Bind theme to body attribute -->
61
+ <body data-bind="data-theme: ui.theme">
62
+
63
+ <!-- Button with action pipeline -->
64
+ <button data-on="click: toggleTheme() | log('theme changed')">
65
+ Toggle Theme
66
+ </button>
67
+ ```
68
+
69
+ ### 3. Event-Sequence Testing
70
+
71
+ Test state changes as event sequences:
72
+
73
+ ```javascript
74
+ import { eventTest } from './eventTest.js';
75
+
76
+ eventTest('add todo', ({ store, trigger, assertPath }) => {
77
+ trigger(() => {
78
+ const items = store.get('todos.items') || [];
79
+ store.set('todos.items', [...items, { id: 1, text: 'Test', done: false }]);
80
+ });
81
+
82
+ assertPath('todos.items', (items) => items.length === 1);
83
+ });
84
+ ```
85
+
86
+ ## Run It
87
+
88
+ ```bash
89
+ # Install dependencies
90
+ npm install
91
+
92
+ # Open in browser
93
+ open index.html
94
+
95
+ # Run tests
96
+ npm test
97
+ ```
98
+
99
+ ## Progression from 001-011
100
+
101
+ **Examples 001-011:** Learn `eventState.js` primitive
102
+ **Example 030:** See the framework features (routing, templates, testing)
103
+ **Next steps:** Advanced features (devtools, forms, extensions)
104
+
105
+ ## What Makes This Different
106
+
107
+ **Other frameworks:**
108
+ - Testing is separate (React Testing Library, Vue Test Utils)
109
+ - State management is opaque (virtual DOM, reactivity magic)
110
+ - Need build tools (JSX, SFC compilers)
111
+
112
+ **UIstate (030):**
113
+ - Testing is **architectural** (event-sequence assertions)
114
+ - State management is **transparent** (events all the way down)
115
+ - No build step (runs directly in browser)
116
+
117
+ ## Learn More
118
+
119
+ - See `tests/todos.test.js` for testing examples
120
+ - See `runtime/core/behaviors.runtime.js` for how `data-bind` works
121
+ - See `runtime/core/eventState.js` for the core primitive
@@ -0,0 +1,25 @@
1
+ // Simple router setup for the todo app example
2
+ import store from './store.js';
3
+ import { createRouter } from '../runtime/core/router.js';
4
+ import * as home from './views/home.js';
5
+ import * as todoDemo from './views/todoDemo.js';
6
+
7
+ const routes = [
8
+ { path: '/', view: 'home', component: home },
9
+ { path: '/todo-demo', view: 'todoDemo', component: todoDemo },
10
+ ];
11
+
12
+ // Initialize router with correct config object
13
+ const router = createRouter({
14
+ routes,
15
+ store,
16
+ rootSelector: '[data-route-root]',
17
+ debug: true
18
+ });
19
+
20
+ // Start the router after DOM is ready
21
+ if (document.readyState === 'loading') {
22
+ document.addEventListener('DOMContentLoaded', () => router.start());
23
+ } else {
24
+ router.start();
25
+ }