objs-core 2.3.0 → 2.4.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.
- package/README.md +561 -618
- package/objs-extension/README.md +32 -0
- package/objs-extension/background.js +110 -0
- package/objs-extension/bridge.js +193 -0
- package/objs-extension/icons/icon128.png +0 -0
- package/objs-extension/lib/objs-inject.js +5308 -0
- package/objs-extension/manifest.json +18 -0
- package/objs-extension/sidepanel.css +455 -0
- package/objs-extension/sidepanel.html +56 -0
- package/objs-extension/sidepanel.js +908 -0
- package/objs.built.js +475 -120
- package/objs.built.min.js +57 -48
- package/objs.d.ts +584 -525
- package/objs.js +593 -134
- package/package.json +71 -70
package/README.md
CHANGED
|
@@ -1,618 +1,561 @@
|
|
|
1
|
-
# Objs
|
|
2
|
-
> Fast and simple library to speed up developing by AI context friendly architecture, auto-tests recording, cache control and other. Develop new features without rewriting anything. Works standalone or alongside React. Examples and full documentation: [Full Documentation](https://en.fous.name/objs/documentation)
|
|
3
|
-
|
|
4
|
-
**AI-friendly** — one file, `SKILL.md` primer (~6,000 tokens). An LLM generates correct Objs code from a description without JSX, virtual DOM, or React lifecycle knowledge.
|
|
5
|
-
|
|
6
|
-
**React-developer-friendly** — familiar `className`, `ref`/`refs`, `o.createStore`. Add one script tag to an existing React app and get Playwright test generation without touching any components.
|
|
7
|
-
|
|
8
|
-
**Live examples** — real patterns in [`examples/`](https://foggysq.github.io/objs/examples/), narrative walkthroughs in EXAMPLES.md. For AI assistants: use SKILL.md as `@SKILL.md` or system prompt.
|
|
9
|
-
|
|
10
|
-
---
|
|
11
|
-
|
|
12
|
-
## Why Objs
|
|
13
|
-
|
|
14
|
-
**
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
- **
|
|
19
|
-
- **
|
|
20
|
-
- **
|
|
21
|
-
- **
|
|
22
|
-
- **
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
- **
|
|
33
|
-
- **
|
|
34
|
-
- **
|
|
35
|
-
- **
|
|
36
|
-
- **
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
####
|
|
68
|
-
-
|
|
69
|
-
-
|
|
70
|
-
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
-
|
|
79
|
-
-
|
|
80
|
-
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
-
|
|
102
|
-
|
|
103
|
-
-
|
|
104
|
-
- `
|
|
105
|
-
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
`o`
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
`o.
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
`o().
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
`o
|
|
280
|
-
|
|
281
|
-
`o
|
|
282
|
-
|
|
283
|
-
`o
|
|
284
|
-
|
|
285
|
-
`o
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
`o
|
|
296
|
-
|
|
297
|
-
`o
|
|
298
|
-
|
|
299
|
-
`o
|
|
300
|
-
|
|
301
|
-
`o
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
`o
|
|
311
|
-
|
|
312
|
-
`o
|
|
313
|
-
|
|
314
|
-
`o
|
|
315
|
-
|
|
316
|
-
`o
|
|
317
|
-
|
|
318
|
-
`o
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
`o.
|
|
347
|
-
|
|
348
|
-
`o.
|
|
349
|
-
|
|
350
|
-
`o.
|
|
351
|
-
|
|
352
|
-
`o.
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
`o.
|
|
363
|
-
|
|
364
|
-
`o.
|
|
365
|
-
|
|
366
|
-
`o.
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
`o.
|
|
372
|
-
|
|
373
|
-
`o.
|
|
374
|
-
|
|
375
|
-
`o.
|
|
376
|
-
|
|
377
|
-
`o.
|
|
378
|
-
|
|
379
|
-
`o.
|
|
380
|
-
|
|
381
|
-
`o.
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
`o.
|
|
392
|
-
|
|
393
|
-
`o.
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
`o.
|
|
401
|
-
|
|
402
|
-
`o.
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
`
|
|
418
|
-
|
|
419
|
-
`
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
`o.
|
|
424
|
-
|
|
425
|
-
`o.
|
|
426
|
-
|
|
427
|
-
`o.
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
o.
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
`
|
|
474
|
-
|
|
475
|
-
`
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
},
|
|
563
|
-
};
|
|
564
|
-
},
|
|
565
|
-
updateCount: ({ self }, num) => {
|
|
566
|
-
self.store.n = num;
|
|
567
|
-
self.refs.n.html(num);
|
|
568
|
-
},
|
|
569
|
-
};
|
|
570
|
-
o.init(counterStates).render().appendInside('#app');
|
|
571
|
-
```
|
|
572
|
-
|
|
573
|
-
No compiler. No build step to try the above. No framework knowledge needed to generate it.
|
|
574
|
-
|
|
575
|
-
### Granular reactive updates — no virtual DOM diff
|
|
576
|
-
|
|
577
|
-
Each store subscription calls exactly one targeted DOM write:
|
|
578
|
-
|
|
579
|
-
```js
|
|
580
|
-
// React with Redux: entire subtree re-renders, React diffs it
|
|
581
|
-
// Objs: one function call, one innerHTML assignment
|
|
582
|
-
o.connectRedux(store, s => s.userName, profileCard, 'updateName');
|
|
583
|
-
o.connectRedux(store, s => s.score, profileCard, 'updateScore');
|
|
584
|
-
```
|
|
585
|
-
|
|
586
|
-
Similar philosophy to Solid.js signals — but the update logic is a plain function, not a reactive primitive. An AI generates it without any framework knowledge.
|
|
587
|
-
|
|
588
|
-
### Comparison
|
|
589
|
-
|
|
590
|
-
| | Objs v2.0 | React ecosystem |
|
|
591
|
-
|---|---|---|
|
|
592
|
-
| **Setup** | `<script src="objs.js">` or `npm i objs-core` | React + Babel/Vite + config |
|
|
593
|
-
| **State management** | Built-in states + loaders | Redux / Zustand / MobX (separate) |
|
|
594
|
-
| **Routing** | `o.route()` built-in | React Router (separate) |
|
|
595
|
-
| **Testing** | Built-in `o.test()` + recording | Jest + Testing Library + Playwright |
|
|
596
|
-
| **Dev tools** | Built-in overlay, recording | React DevTools extension |
|
|
597
|
-
| **TypeScript** | `objs.d.ts` included | @types/react + separate config |
|
|
598
|
-
| **SSR** | Built-in DocumentMVP | Next.js / separate hydration setup |
|
|
599
|
-
| **AI context size** | ~2500 lines, one file | Dozens of packages, thousands of files |
|
|
600
|
-
| **Prod bundle overhead** | Dev code fully stripped | Depends on tree-shaking config |
|
|
601
|
-
|
|
602
|
-
### Real-world patterns
|
|
603
|
-
|
|
604
|
-
See [EXAMPLES.md](EXAMPLES.md) for the architecture guide and runnable examples (aligned with [SKILL.md](SKILL.md)):
|
|
605
|
-
1. **How render works** — plain object, function, HTML string, multi-instance, `append`, `children`, `ref`/`refs`
|
|
606
|
-
2. **Single components (atoms)** — Button, Badge, Field with `val()`, `css(null)`, `addClass` spread
|
|
607
|
-
3. **Nesting & composition** — slot pattern, `append` in render, factory with dynamic children
|
|
608
|
-
4. **Design system** — Atoms → Molecules → Organisms, `self.store`, update efficiency
|
|
609
|
-
5. **Real-world** — menu, cart+cards, dialog, drawer+URL, complex form
|
|
610
|
-
6. **React integration** — four modes including bolt-on Playwright recording with `o.reactQA`
|
|
611
|
-
|
|
612
|
-
**Rule (from SKILL):** Define one state method per data slice; never call `.render()` to update — use targeted state methods. In event handlers use **self.select(e)** and **refs** (e.g. `row.refs.input.val()`), not `e.target`/class selectors or raw DOM.
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
## License
|
|
618
|
-
Apache 2.0
|
|
1
|
+
# Objs
|
|
2
|
+
> Fast and simple library to speed up developing by AI context friendly architecture, auto-tests recording, cache control and other. Develop new features without rewriting anything. Works standalone or alongside React. Examples and full documentation: [Full Documentation](https://en.fous.name/objs/documentation)
|
|
3
|
+
|
|
4
|
+
**AI-friendly** — one file, `SKILL.md` primer (~6,000 tokens). An LLM generates correct Objs code from a description without JSX, virtual DOM, or React lifecycle knowledge.
|
|
5
|
+
|
|
6
|
+
**React-developer-friendly** — familiar `className`, `ref`/`refs`, `o.createStore`. Add one script tag to an existing React app and get Playwright test generation without touching any components.
|
|
7
|
+
|
|
8
|
+
**Live examples** — real patterns in [`examples/`](https://foggysq.github.io/objs/examples/), narrative walkthroughs in EXAMPLES.md. For AI assistants: use SKILL.md as `@SKILL.md` or system prompt.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Why Objs
|
|
13
|
+
|
|
14
|
+
**Objs is built so one dependency spans the whole loop—UI, reactive state, in-browser recording, replay with mocks, and export to standard Playwright**—instead of stitching together a framework, a separate recorder product, and a second test stack just to lock regressions in CI.
|
|
15
|
+
|
|
16
|
+
**Core functionality** — Record user actions in the browser, export ready-to-commit tests, and run them in CI or **run in the browser extension**. One script; no separate recorder or test-ID maintenance.
|
|
17
|
+
|
|
18
|
+
- **Record → Playwright in one pipeline** — `o.startRecording()` captures click, input, change, scroll; `o.stopRecording()` returns actions and auto-generated assertions; `o.exportPlaywrightTest(recording)` outputs a `.spec.ts` with locators and network mocks. Paste into your repo and run `npx playwright test`.
|
|
19
|
+
- **CI support** — Export runs in all builds (including prod). QA or assessors record on staging; paste the generated Playwright test into your test suite; CI runs it with no extra config. Optional `o.exportTest(recording)` for Objs-style tests.
|
|
20
|
+
- **Store and update model** — `o.createStore()` + `subscribe`/`notify`: no virtual DOM, no re-render cascade; only subscribed components update their own DOM (O(1) per subscriber).
|
|
21
|
+
- **One library, many roles** — DOM + state + routing + AJAX + cache (`o.inc`) + tests + recording + SSR. No extra test runner or recorder product. Built-in `o.route()` / `o.router()` — no separate router dependency.
|
|
22
|
+
- **Stable selectors and UI checks** — `{...o.reactQA('ComponentName')}` or `o.autotag`; recorder uses `data-qa` and list indices. `o.assertSize(el, { w, h, padding, margin })` for design system verification; `o.testConfirm()` for manual/hover checks after replay.
|
|
23
|
+
- **Works standalone or with React** — Add one script tag to an existing React app; no architecture change. Familiar `className`, `ref`/`refs`, `o.createStore`. Built-in SSR (Node) with `DocumentMVP` and in-browser hydration.
|
|
24
|
+
- **AI-friendly** — One file, ~6,000-token `SKILL.md` primer. No JSX, virtual DOM, or React lifecycle; fewer tokens than typical React context for runnable output. No stale closures, dependency arrays, or re-render cascades. Same code runs in Node (SSR) so tools can verify output without a browser — **verify generated code without user review**: run `o.init(states).render()` in Node, serialize or assert structure before returning to the user.
|
|
25
|
+
|
|
26
|
+
→ [Full comparison and live demo](https://foggysq.github.io/objs/examples/ai-workflow/index.html)
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
### Update v2.4: Chrome extension + native WebSocket replay
|
|
31
|
+
|
|
32
|
+
- **Strict record / replay** — `o.startRecording({ … strictCaptureAssertions?, strictCaptureNetwork?, strictCaptureWebSocket? })` stores **`strictCapture`** on the recording; **`o.playRecording`** accepts **`strictPlay`** and per-feature **`strictAssertions`**, **`strictNetwork`**, **`strictWebSocket`**, **`strictRemoved`** (see README “Recording and export”). The extension **Recording settings** accordion includes matching toggles for JSON replay.
|
|
33
|
+
- **Chrome extension (`objs-extension/`)** — Manifest V3 toolbar popup with an **accordion** per test: edit **`o.exportTest()` JS** (same as the recording example’s “Export Objs test”), **Play** runs `addTest`/`run`, **Stop** after recording fills the script + snapshot for Playwright. Legacy **JSON** recordings still **Play** via `o.playRecording` (replay with network mocks). Import/export `.js` / `.json`, download Playwright. Load unpacked from `chrome://extensions` (Developer mode) or **package and sign it yourself** for internal distribution.
|
|
34
|
+
- **Distribution** — The Objs project does **not** publish this extension to the **public Chrome Web Store**. Enterprises and teams zip or policy-deploy the folder to match their **host permissions, signing, and compliance** requirements.
|
|
35
|
+
- **Native WebSocket mocking** — During `o.playRecording`, when `recording.websocketEvents` is present, Objs installs a mock `WebSocket` that replays captured in/out messages (same teardown as fetch/XHR mocks). Use `skipWebSocketMock: true` in play options to force a live connection.
|
|
36
|
+
- **Extension setup** — See [`objs-extension/README.md`](objs-extension/README.md) for load-unpacked steps and packaging notes.
|
|
37
|
+
- **`o().cssMerge(object|null)`** — Merges into the existing inline `style` attribute instead of replacing it (unlike `css()`, which overwrites the whole attribute). Properties in the object **add** or **replace**; pass **`null`** or **`undefined`** for a property to **remove** that property only. Pass **`null`** for the whole argument to clear the style attribute (same as `css(null)`). Keys may be **camelCase** or **kebab-case**; they are normalized to kebab-case when serializing.
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## Get started
|
|
42
|
+
|
|
43
|
+
**Browser** — source with test tools:
|
|
44
|
+
```html
|
|
45
|
+
<script src="objs.js" type="text/javascript"></script>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**Browser (smaller)** — minified `objs.built.min.js` for production. Use `type="module"`:
|
|
49
|
+
```html
|
|
50
|
+
<script src="objs.min.js" type="module"></script>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
**npm / bundler** — correct file chosen automatically via `package.json` exports:
|
|
54
|
+
```js
|
|
55
|
+
import o from 'objs-core'; // resolves to objs.built.js
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
npm i objs-core
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
## Features
|
|
66
|
+
|
|
67
|
+
#### Develop
|
|
68
|
+
- Samples and state control
|
|
69
|
+
- Data store, Cookies and LS/SS control
|
|
70
|
+
- Events delegation
|
|
71
|
+
|
|
72
|
+
#### Test
|
|
73
|
+
- Sync/async, tests with reload
|
|
74
|
+
- Console & HTML output
|
|
75
|
+
- Autotests
|
|
76
|
+
|
|
77
|
+
#### Optimize
|
|
78
|
+
- Separate logic and samples
|
|
79
|
+
- Native micro-service architecture
|
|
80
|
+
- Async loading and preloading, cache
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
## Main principles
|
|
86
|
+
|
|
87
|
+
### Dynamic content
|
|
88
|
+
|
|
89
|
+
#### Create sample
|
|
90
|
+
|
|
91
|
+
To control elements Objs uses states. State - it's an information how to create or change DOM element. To create an element use `render` state with html (inner HTML) and tag attributes:
|
|
92
|
+
```
|
|
93
|
+
// state called render for timer example
|
|
94
|
+
const timerStates = {
|
|
95
|
+
render: {
|
|
96
|
+
class: 'timer',
|
|
97
|
+
html: 'Seconds: <span ref="n">0</span>',
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
- `render` could be a string if you use HTML samples (see [documentation](https://fous.name/objs/documentation/?parameter=value#states)):
|
|
102
|
+
`'<div class="timer">Seconds:<span>0</span></div>'`
|
|
103
|
+
- default tag is `div` (if tag is undefined)
|
|
104
|
+
- attributes `dataset` and `style` can be object type
|
|
105
|
+
- to append elements inside - use `append` with DOM element/Objs or an array of them as a value
|
|
106
|
+
|
|
107
|
+
#### States
|
|
108
|
+
|
|
109
|
+
Then add a new state that will start and finish counting. Number will be stored in the object itself - `self` object. So the state will be a function that gets `self`, creates a variable, increments it by interval and shows as innerHTML of `span`:
|
|
110
|
+
```
|
|
111
|
+
// new timer states object
|
|
112
|
+
const timerStates = {
|
|
113
|
+
render: {
|
|
114
|
+
class: 'timer',
|
|
115
|
+
html: 'Seconds: <span ref="n">0</span>',
|
|
116
|
+
},
|
|
117
|
+
start: ({self}) => {
|
|
118
|
+
self.n = self.n || 0;
|
|
119
|
+
self.interval = setInterval(() => {
|
|
120
|
+
self.n++;
|
|
121
|
+
self.refs.n.html(self.n);
|
|
122
|
+
}, 1000);
|
|
123
|
+
},
|
|
124
|
+
stop: ({self}) => {
|
|
125
|
+
clearInterval(self.interval);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
- every state gets object with
|
|
130
|
+
`self` - Objs object
|
|
131
|
+
`o` - o-function to use inside
|
|
132
|
+
`i` - index of the current element in Objs object
|
|
133
|
+
|
|
134
|
+
#### Append in DOM
|
|
135
|
+
|
|
136
|
+
The last thing is to create and append element on the page. To do this - init states, render object and start timer... And also - append it.
|
|
137
|
+
```
|
|
138
|
+
// create and start timer
|
|
139
|
+
const timer = o.init(timerStates)
|
|
140
|
+
.render()
|
|
141
|
+
.start()
|
|
142
|
+
.appendInside('#simpleTimer');
|
|
143
|
+
|
|
144
|
+
// stop timer
|
|
145
|
+
timer.stop();
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
#### Main settings
|
|
149
|
+
|
|
150
|
+
`o.showErrors` – turn on/off showing errors (false)
|
|
151
|
+
`o.errors` – an array of all hidden errors, can be logged by `o.logErrors()` for debug
|
|
152
|
+
`o.onError` – a function than will be called with an error as an argument
|
|
153
|
+
|
|
154
|
+
> This and some more complex live examples are in the [full documentation](https://fous.name/objs/documentation). There are lots of useful methods and settings.
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
### Tests - unit tests, e2e, recording etc.
|
|
158
|
+
|
|
159
|
+
Testing is a first-class part of Objs: use `o.test()` and `o.addTest()` for sync and async unit tests, including tests with page reload and autorun. Record user sessions with `o.startRecording()` / `o.stopRecording()`, then export to Objs-style tests (`o.exportTest()`) or Playwright (`.spec.ts`) with `o.exportPlaywrightTest()` for e2e in CI. Replay with `o.playRecording()` (all builds); call `o.testOverlay()` to show a results panel so assessors can see if all auto tests passed and which manual checks failed. Use `o.testConfirm()` for manual checks (e.g. hover effects). Dev-only: `o.assertSize()` / `o.assertVisible()` for layout assertions. See the [recording example](https://foggysq.github.io/objs/examples/recording/index.html) and the full documentation for details.
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
## Functions
|
|
165
|
+
Almost all functions return control object with methods, let's call it **Objs**. Full API and TypeScript types: [objs.d.ts](objs.d.ts).
|
|
166
|
+
|
|
167
|
+
### Element selection
|
|
168
|
+
`o(q)` – gets elements to control object. If [string] - by **querySelectorAll(q)** into control object, if DOM element or an array of them - gets them, if [number] - gets control object from **o.inits[q]**.
|
|
169
|
+
|
|
170
|
+
`o.first(q)` – gets element to control by **querySelector(q)**.
|
|
171
|
+
|
|
172
|
+
`o.take(q)` – gets elements like **o(q)** from DOM but if there is just one element or equal number of elements to inited in **o.inits[]** before, gets all inited elements and their methods.
|
|
173
|
+
|
|
174
|
+
### Component control
|
|
175
|
+
`o.init(states)` – returns **Objs**, creates method(s) for each state to create, change elements. State called **render** is reserved for creation elements. **states** can be [string], [object], [function] that returns [string] or [object]. After **init()** **Objs** gets a **initID** parameter for a saved object in **o.inits**. More info about structure and features [here](https://fous.name/objs).
|
|
176
|
+
|
|
177
|
+
`o.initState(state, [props])` – inite method and call it with props, e.g. to render/create element. **Objs** gets a **.initID** parameter for a saved object in **o.inits[]**.
|
|
178
|
+
|
|
179
|
+
`o.inits[initID]` – an array of all inited objects. Available by index **initID** or **o.take()**.
|
|
180
|
+
|
|
181
|
+
Instance: `o().init()` – equal to **o.init()** but with elements to control. `o().initState()` – equal to **o.initState()** but with elements to control. `o().sample()` – returns states object with render state for creation such elements. `o().getSSR(initId, [fromEls])` – bind this instance to DOM nodes by initId; optional **fromEls** (e.g. from a container) skips document query; used by auto-hydration when parent sets innerHTML. `o().saveState([id])`, `o().revertState([id])`, `o().loseState(id)` – save/restore DOM state. `o().unmount()` – remove from DOM and **o.inits**. `o().connect(loader, state, fail)` – connect a loader to this instance (state/fail method names). `o().initID` – undefined or number in **o.inits[]**. **`toString()` / `Symbol.toPrimitive`** — an Objs instance stringifies to its HTML (same as **`.html()`**), so you can use **`${child}`** in template literals and when the parent sets **innerHTML** from composed instance markup, children auto-hydrate. `o().html([html])` – returns html string of all elements or sets innerHTML as **html**; when **html** is set, any `[data-o-init]` nodes inside are auto-hydrated (inited instances bound to those nodes).
|
|
182
|
+
|
|
183
|
+
### DOM manipulation
|
|
184
|
+
`o().reset(q)` – clears **Objs** and get new elements by **q**, works as **o()**.
|
|
185
|
+
|
|
186
|
+
`o().select([i])` – selects number **i** element from 0 to change only it, if **i** is undefined selects the last index element. Pass an **Event** to select the element in the set that contains **event.target** (use in handlers to get **`self.select(e).refs…`**).
|
|
187
|
+
|
|
188
|
+
`o().all()` – selects all elements to operate again.
|
|
189
|
+
|
|
190
|
+
`o().remove([i])` – removes all or **i** element from DOM.
|
|
191
|
+
|
|
192
|
+
`o().skip(i)` – removes **i** element from control set of this **Objs**.
|
|
193
|
+
|
|
194
|
+
`o().add()` – adds element to control set.
|
|
195
|
+
|
|
196
|
+
`o().find(q)` – finds all children elements by q-query in each element.
|
|
197
|
+
|
|
198
|
+
`o().first(q)` – finds only the first child element by q-query in each element.
|
|
199
|
+
|
|
200
|
+
`o().length` – number of elements of control set.
|
|
201
|
+
|
|
202
|
+
`o().el` – the first DOM element in the set.
|
|
203
|
+
|
|
204
|
+
`o().els` – all DOM elements of the set.
|
|
205
|
+
|
|
206
|
+
`o().last` – the last DOM element in the set.
|
|
207
|
+
|
|
208
|
+
`o().attr(attribute, [value])` – `UPDATED` sets **attribute** to **value**. Pass `null` to remove the attribute. Pass `""` to set an empty string. Returns **attribute** value if **value** is undefined. If **.select()** was not used before — returns an array of values.
|
|
209
|
+
|
|
210
|
+
`o().attrs()` – returns an array of all elements attributes, if **.select()** was used before - returns an object with values of one element.
|
|
211
|
+
|
|
212
|
+
`o().dataset([object])` – Sets dataset values due to the **object** data. It will not delete other dataset values. If **.select()** was used before - returns an object with dataset of one element or changes just one element.
|
|
213
|
+
|
|
214
|
+
`o().style(value)` – `UPDATED` sets style attribute to [string] **value**. Pass `null` to remove the `style` attribute entirely.
|
|
215
|
+
|
|
216
|
+
`o().css(object|null)` – `UPDATED` sets style from **object** like `{width: '100px', 'font-family': 'Arial'}`. Pass `null` to remove the `style` attribute entirely.
|
|
217
|
+
|
|
218
|
+
`o().cssMerge(object|null)` – `NEW` merges into the existing inline `style`: properties add or replace; `null` or `undefined` for a property removes that property only. Pass `null` for the whole argument to remove the `style` attribute (same as `css(null)`). Keys may be camelCase or kebab-case.
|
|
219
|
+
|
|
220
|
+
`o().val([value])` – `NEW` gets or sets the `.value` property of `input`/`textarea`/`select`. Returns current value when called without argument; sets and returns `Objs` for chaining when called with argument.
|
|
221
|
+
|
|
222
|
+
`o().setClass(value)` – sets class attribute to **value**.
|
|
223
|
+
|
|
224
|
+
`o().addClass(...cls)` – `UPDATED` adds one or more classes: `addClass('foo', 'bar', 'baz')`.
|
|
225
|
+
|
|
226
|
+
`o().removeClass(...cls)` – `UPDATED` removes one or more classes: `removeClass('foo', 'bar')`.
|
|
227
|
+
|
|
228
|
+
`o().toggleClass(class, rule)` – switch having and not having **class** by **rule**. If **rule** set **class**.
|
|
229
|
+
|
|
230
|
+
`o().haveClass(class)` – returns true if all elements have **class**.
|
|
231
|
+
|
|
232
|
+
`o().innerHTML([html])` – if **html** is set, sets innerHTML of all elements. If not set, returns array with innerHTML of each element.
|
|
233
|
+
|
|
234
|
+
`o().innerText(text)` – sets innerText for all elements.
|
|
235
|
+
|
|
236
|
+
`o().textContent(content)` – sets textContent for all elements.
|
|
237
|
+
|
|
238
|
+
`o().refs` – `NEW` object populated on `init` — every child element with a `ref="name"` attribute is available as `component.refs.name` (an ObjsInstance wrapper). Use for direct access without selectors.
|
|
239
|
+
|
|
240
|
+
`o().forEach(function)` – runs **function** with an object as the first parameter: {o, self, i, el} where is o-function, self Objs object, i-index of current element and el - DOM element.
|
|
241
|
+
|
|
242
|
+
### Events
|
|
243
|
+
`o().on(events, function, [options])` – adds **events** listeners separated by ', ' to elements.
|
|
244
|
+
|
|
245
|
+
`o().off(events, function, [options])` – removes **events** listeners separated by ', ' to elements.
|
|
246
|
+
|
|
247
|
+
`o().offAll([event])` – removes all listeners or for special **event** from elements.
|
|
248
|
+
|
|
249
|
+
`o().onAll([event])` – adds all inited listeners from cache for all or for special **event**.
|
|
250
|
+
|
|
251
|
+
`o().ie` – object with all ever added listeners like {click: [[function, options], ...], ...}.
|
|
252
|
+
|
|
253
|
+
### DOM insert
|
|
254
|
+
`o().appendInside(q)` – append elements inside element **q** or got by **q** query.
|
|
255
|
+
|
|
256
|
+
`o().appendBefore(q)` – append elements before element **q** or got by **q** query.
|
|
257
|
+
|
|
258
|
+
`o().appendAfter(q)` – append elements after element **q** or got by **q** query.
|
|
259
|
+
|
|
260
|
+
`o().prepareFor(React.createElement, [React.Component])` – clones and returns React element or JSX Component if React.Component is given. Allows to use Objs in React Apps. Objs states should be inited on rendered elements.
|
|
261
|
+
|
|
262
|
+
### State and store
|
|
263
|
+
`o.createStore(defaults)` – `NEW` creates a reactive plain-object store. Returns the defaults object extended with `subscribe(component, stateName)`, `notify()`, and `reset()`. Subscribed components receive `{ ...storeProps, self, o, i }` merged into their state context on every `notify()`.
|
|
264
|
+
|
|
265
|
+
```
|
|
266
|
+
Objs update cycle (vs React):
|
|
267
|
+
|
|
268
|
+
React: setState(newVal)
|
|
269
|
+
→ component function re-runs entirely
|
|
270
|
+
→ virtual DOM diff
|
|
271
|
+
→ patch (1–N nodes, including unchanged ones)
|
|
272
|
+
|
|
273
|
+
Objs: store.notify()
|
|
274
|
+
→ each subscribed component's sync() fires
|
|
275
|
+
→ each sync() writes only its own DOM nodes
|
|
276
|
+
→ O(1) per subscriber — no diff, no cascade
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
`o.connectRedux(store, selector, component, [state])` – connects a Redux store slice to a component state method. Fires immediately and on every store change. Returns unsubscribe function.
|
|
280
|
+
|
|
281
|
+
`o.connectMobX(mobx, observable, accessor, component, [state])` – wraps `mobx.autorun()` to connect a MobX observable to a component state method. Returns disposer.
|
|
282
|
+
|
|
283
|
+
`o.withReactContext(React, Context, selector, component, [state])` – returns a React bridge component that calls `component[state](selector(contextValue))` on every context change. Mount it inside the Provider to connect.
|
|
284
|
+
|
|
285
|
+
`o.ObjsContext` – default context value placeholder for `React.createContext()`.
|
|
286
|
+
|
|
287
|
+
### Routing
|
|
288
|
+
`o.route(path, task)` – register a route: **path** is string, boolean, or function(path); **task** is function or object. Returns match result. Built-in; no separate router dependency.
|
|
289
|
+
|
|
290
|
+
`o.router(routes)` – run routing: **routes** is object of path → task. Returns true if a route matched.
|
|
291
|
+
|
|
292
|
+
Use **o.getParams([key])** to read GET (query) parameters in route callbacks or when initialising components—e.g. pass `o.getParams()` to `render(data)` or read `o.getParams('id')` for component state or data loading.
|
|
293
|
+
|
|
294
|
+
### HTTP and parameters
|
|
295
|
+
`o.get(url, [props])` – returns promise for GET AJAX, **data** in **props** as an [object] will be converted to string parameters.
|
|
296
|
+
|
|
297
|
+
`o.post(url, props)` – returns promise for POST AJAX, **data** in **props** as an [object] will be converted to body.
|
|
298
|
+
|
|
299
|
+
`o.ajax(url, props)` – returns propmise for AJAX, needs **method** in **props** equal to GET or POST, **data** will be converted for GET/POST format.
|
|
300
|
+
|
|
301
|
+
`o.getParams([key])` – returns GET **key** value or an object with all GET parameters.
|
|
302
|
+
|
|
303
|
+
### Include and cache
|
|
304
|
+
`o.inc(sources, [callBack, callBad])` – returns [number] **setID**, gets **souces** is an object like {nameID: url, ...} where **nameID** is unique ID, **url** link to JS, CSS or image, **callBack** – function to run after everything is loaded successfully, **callBad** - function to run on failure. Functions gets **setN** as the first argument.
|
|
305
|
+
|
|
306
|
+
`o.incCheck(setID)` – true if include files set number **setID** is loaded.
|
|
307
|
+
|
|
308
|
+
`o.incCacheClear([all])` – true. Clears localStorage JS, CSS cache. If **all** is true, removes DOM elements of include and clears all include data.
|
|
309
|
+
|
|
310
|
+
`o.newLoader(promise)` – create a loader for async data; use with `o().connect(loader, state, fail)`.
|
|
311
|
+
|
|
312
|
+
`o.incCache` – true, cache in localStorage enabled.
|
|
313
|
+
|
|
314
|
+
`o.incCacheExp` – 1000 * 60 * 60 * 24, cache for 24 hours.
|
|
315
|
+
|
|
316
|
+
`o.incTimeout` – 6000, ms timeout to load function.
|
|
317
|
+
|
|
318
|
+
`o.incSource` – '', prefix for urls.
|
|
319
|
+
|
|
320
|
+
`o.incForce` – false, do not load already loaded files.
|
|
321
|
+
|
|
322
|
+
`o.incAsync` – true, async loading, set to false for in order loading.
|
|
323
|
+
|
|
324
|
+
`o.incCors` – false, do not allow loading from other domains
|
|
325
|
+
|
|
326
|
+
`o.incFns` – object, array of name:status for all loaded functions.
|
|
327
|
+
|
|
328
|
+
### Cookies and storage
|
|
329
|
+
`o.setCookie(name, value, [options])` – set a cookie.
|
|
330
|
+
|
|
331
|
+
`o.getCookie(name)` – get cookie value.
|
|
332
|
+
|
|
333
|
+
`o.deleteCookie(name)` – delete a cookie.
|
|
334
|
+
|
|
335
|
+
`o.clearCookies()` – clear all cookies.
|
|
336
|
+
|
|
337
|
+
`o.clearLocalStorage()`, `o.clearSessionStorage()`, `o.clearTestsStorage()` – clear respective storage.
|
|
338
|
+
|
|
339
|
+
`o.clearAfterTests()` – clear cookies and test-related storage after test run (e.g. in tAfterEach).
|
|
340
|
+
|
|
341
|
+
### Testing
|
|
342
|
+
`o.test(title, test1, test2, ..., callBack)` – returns [number] **testID**, gets [string] **title** and tests like ["Test title", testFunction], where **testFunction** should return true for success and false or string for failure. If test is async, **testFunction** should get the first parameter and use it in **o.testUpdate()**. Optional **options object** (same argument list as a test case): **`{ sync: true }`** runs steps one after another synchronously (typical with **o.playRecording**); **`{ confirmOnFailure: true, confirmOnFailureTimeout?: number }`** shows a Continue/Stop overlay when a step fails instead of stopping immediately.
|
|
343
|
+
|
|
344
|
+
`o.sleep(ms)` – returns a **Promise** that resolves after **ms** milliseconds (used by **o.exportTest** and **o.playRecording** action delays).
|
|
345
|
+
|
|
346
|
+
`o.addTest(title, ...cases)` – add a test suite; returns handle for **o.runTest()**.
|
|
347
|
+
|
|
348
|
+
`o.runTest(testId?, autoRun?, savePrev?)` – run test(s). **savePrev** true keeps existing sessionStorage for that testId so the run can resume.
|
|
349
|
+
|
|
350
|
+
`o.testUpdate(info, result, [description])` – returns undefined, gets **info** object (the first parameter of any **testFunction**) to update test status and set it to **result** (true or false/string), **description** - additional text if needed. Used for test status update for async tests. More info [here](https://fous.name/objs).
|
|
351
|
+
|
|
352
|
+
`o.updateLogs()` – return test log lines (e.g. for assertions).
|
|
353
|
+
|
|
354
|
+
`o.tLog[testID]` – test sessions and text results.
|
|
355
|
+
|
|
356
|
+
`o.tRes[testID]` – test sets results as true/false.
|
|
357
|
+
|
|
358
|
+
`o.tStatus[testID: [functionID: true/false],...]` – an array of set test functions statuses.
|
|
359
|
+
|
|
360
|
+
`o.tShowOk` – false, success tests are hidden, only errors. Set to **true** to see success results before **o.test()**.
|
|
361
|
+
|
|
362
|
+
`o.tStyled` – false, logs are in console view. Set to **true** to make logs HTML styled before **o.test()**.
|
|
363
|
+
|
|
364
|
+
`o.tTime` – 2000, milliseconds timeout for async tests.
|
|
365
|
+
|
|
366
|
+
`o.tBeforeEach` / `o.tAfterEach` – global hooks called before/after each test case. Set to a function.
|
|
367
|
+
|
|
368
|
+
### Recording and export
|
|
369
|
+
Available in all builds so QA testers/assessors can record on staging or production environments.
|
|
370
|
+
|
|
371
|
+
> **Security note:** `o.startRecording()` intercepts `window.fetch` and captures request/response bodies including auth tokens. Appropriate for staging environments; review before enabling on production.
|
|
372
|
+
|
|
373
|
+
`o.startRecording(observe?, events?, timeouts?)` – `UPDATED` starts capturing user interactions and network requests as mocks (**fetch** and **XMLHttpRequest**). Optional `observe` is a CSS selector to scope the MutationObserver (e.g. `'#task-app'`). Default events: **`click`**, **`mouseover`**, **`scroll`**, **`input`**, **`change`**, **`submit`**, **`keydown`**, **`focus`**, **`blur`** (override with the **`events`** array). Default per-event debounce/step delays include **`{ click: 100, mouseover: 50, scroll: 30, input: 50, change: 50, submit: 100, keydown: 50, focus: 50, blur: 50 }`** (merge with **`timeouts`**). **Blur**/**focus** on a target removed by the **immediately preceding** recorded action are not captured. Check **o.recorder.active** to see if recording is on.
|
|
374
|
+
|
|
375
|
+
`o.startRecording({ observe?, events?, timeouts?, strictCaptureAssertions?, strictCaptureNetwork?, strictCaptureWebSocket? })` – Same as above using an options object. The optional **strictCapture\*** booleans are stored on the returned recording as **`strictCapture`** and used as defaults for **`o.playRecording`** strict modes when you do not override them in play options.
|
|
376
|
+
|
|
377
|
+
`o.stopRecording()` – `UPDATED` stops recording, returns `{actions, mocks, initialData, assertions, observeRoot, stepDelays, removedElements?, websocketEvents?, strictCapture?}`. Assertions are driven by the MutationObserver: types include **`visible`**, **`class`**, **`style`**, **`hidden`**, **`disabled`**, **`aria-expanded`**, **`aria-checked`**, with fields matching the type (e.g. **`text`**, **`className`**, **`style`**, **`listSelector`**, **`index`**). **`removedElements`** records removed nodes for lenient replay (skip or **strictRemoved**). **`websocketEvents`** holds captured WebSocket URLs and in/out messages when used. **`observeRoot`** is the selector string or null. **`stepDelays`** is the per-event delay map used when replaying.
|
|
378
|
+
|
|
379
|
+
`o.exportTest(recording, options?)` – `UPDATED` returns generated **`o.addTest()`** (or extension-oriented **`o.test`** when **`extensionExport: true`**) source string ready to review and commit. **`options.delay`** is the pause in ms after each action (default **16**; use **`{ delay: 0 }`** to omit **`o.sleep`** in emitted steps).
|
|
380
|
+
|
|
381
|
+
`o.exportPlaywrightTest(recording, [options])` – `NEW` returns a complete Playwright `.spec.ts` file string with network **route** mocks (method/body checks for POST/PUT where applicable), **`page.goto()`**, typed locator steps, real **`expect()`** for DOM (**toHaveClass**, **toHaveCSS**, **toBeHidden**, **toBeDisabled**, **toHaveAttribute**, etc.), and **WebSocket** **`framereceived`/`framesent`** expectations when messages were recorded. **`options.testName`** and **`options.baseUrl`** are optional.
|
|
382
|
+
|
|
383
|
+
```js
|
|
384
|
+
o.startRecording();
|
|
385
|
+
// QA tester uses the app normally
|
|
386
|
+
const rec = o.stopRecording();
|
|
387
|
+
console.log(o.exportPlaywrightTest(rec, { testName: 'Checkout flow' }));
|
|
388
|
+
// paste → tests/checkout.spec.ts → npx playwright test
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
`o.clearRecording([id])` – removes recording from sessionStorage.
|
|
392
|
+
|
|
393
|
+
`o.playRecording(recording, [mockOverrides])` – Replays recording as a test with intercepted fetch. Available in all builds (for assessors on staging).
|
|
394
|
+
|
|
395
|
+
`o.playRecording(recording, { … })` – Options include **`runAssertions`**, **`root`**, **`actionDelay`**, **`manualChecks`**, **`mockOverrides`**, **`skipWebSocketMock`**, **`skipNetworkMocks`**, **`recordingAssertionDebug`**, **`onComplete`**, and strict replay: **`strictPlay`** (shorthand for all strict toggles below), **`strictAssertions`** (exact list index and text, normalized style/class match, no fuzzy list rescan), **`strictNetwork`** (mocked fetch/XHR body must match **`mock.request`**), **`strictWebSocket`** (outbound frames must match recording order and payload), **`strictRemoved`** (assertions tied to **`removedElements`** verify absence instead of auto-pass; defaults to **`strictAssertions`** when omitted). With **`runAssertions: true`**, the return value is **`{ testId }`** (object), not a bare numeric id.
|
|
396
|
+
|
|
397
|
+
`o.runRecordingAssertions(recording, root?, actionIdx?, opts?)` – **`opts`** may include **`assertions`**, **`removedElements`**, **`strictAssertions`**, **`strictRemoved`** (same semantics as play). **`removedElements`** / skip logic applies only when **`actionIdx`** is set (as **o.playRecording** does per step); omitting **`actionIdx`** runs all matching assertions without removed-element bypass.
|
|
398
|
+
|
|
399
|
+
### QA and selectors
|
|
400
|
+
`o.autotag` – set to a string (e.g. `"qa"`) to auto-add `data-{autotag}="component-name"` to all rendered elements. Component name comes from `states.name` (camelCase → kebab-case). Ships in all builds — QA teams can target stable selectors with Playwright/Cypress.
|
|
401
|
+
|
|
402
|
+
`o.reactQA(componentName)` – `NEW` returns a `{ 'data-qa': 'kebab-name' }` object for spreading onto React JSX elements. Converts CamelCase to kebab-case. Respects `o.autotag` value. Ships in all builds.
|
|
403
|
+
|
|
404
|
+
```jsx
|
|
405
|
+
<button {...o.reactQA('CheckoutButton')} onClick={fn}>Checkout</button>
|
|
406
|
+
// → <button data-qa="checkout-button">
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
### Measurement and UI assertions (dev)
|
|
410
|
+
All builds include the full API (test framework, playRecording, testOverlay, testConfirm, measure/assertVisible/assertSize). Only the debug flag and debug logging are behind `__DEV__`.
|
|
411
|
+
|
|
412
|
+
`o.measure(el)` – returns `{width, height, top, left, visible, opacity, zIndex}`. Use in test assertions.
|
|
413
|
+
|
|
414
|
+
`o.assertVisible(el)` – returns `true/false` for use inside `o.test()`.
|
|
415
|
+
|
|
416
|
+
`o.assertSize(el, expected)` – returns `true` or a descriptive error string. `expected` can include:
|
|
417
|
+
- `w`, `h` – width and height (px)
|
|
418
|
+
- `padding` – same value for all four sides (px), or `paddingTop`, `paddingRight`, `paddingBottom`, `paddingLeft` individually
|
|
419
|
+
- `margin` – same value for all four sides (px), or `marginTop`, `marginRight`, `marginBottom`, `marginLeft` individually
|
|
420
|
+
|
|
421
|
+
Use for design system or UI verification tests (e.g. button height 24px, container padding 20px).
|
|
422
|
+
|
|
423
|
+
`o.testOverlay()` – Renders a fixed overlay button (🧪 Tests). Click to see pass/fail results for all test runs (auto steps and manual checks). Drag handle uses **`grab`**; panel height is capped (**e.g. 90vh**). For assessors: after replay, open the overlay to see if all auto tests passed and which manual checks failed. **`onComplete`** from **o.playRecording** runs after async manual checks (**testConfirm** promises) settle so counts stay accurate. Available in all builds.
|
|
424
|
+
|
|
425
|
+
`o.testConfirm(label, items?, opts?)` – Shows a draggable overlay titled "Label: Paused" with an optional checklist; returns `Promise<{ ok: boolean, errors?: string[] }>`. **`opts.timeout`** (ms) enables a countdown before auto-close. Use after replay for manual checks (e.g. hover effects). Available in all builds. See the [recording example](https://foggysq.github.io/objs/examples/recording/index.html) for a live demo.
|
|
426
|
+
|
|
427
|
+
`o.overlay(opts)` – Low-level draggable overlay: **`innerHTML`**, **`onClose`**, **`timeout`**, **`excludeDragSelector`**, **`removeExisting`**, **`className`**, **`id`**. Shared by **testConfirm**, **testOverlay**, and **confirmOnFailure** test options.
|
|
428
|
+
|
|
429
|
+
### SSR and Node
|
|
430
|
+
In Node, **o.D** is **o.DocumentMVP** (no real DOM); **o.init().render()** builds a virtual tree and you can serialize with the same code path that produces HTML for SSR. See full docs for getSSR and hydration.
|
|
431
|
+
|
|
432
|
+
### Utilities and debug
|
|
433
|
+
**o.verify / o.safeVerify / o.specialTypes** — Runtime type checking for arguments, config, or API responses. Useful in projects to fail fast at API boundaries, validate options before use, or keep generated code safe.
|
|
434
|
+
|
|
435
|
+
- **o.verify(pairs, safe?)** — **pairs** is an array of `[value, expectedTypes]`, where **expectedTypes** is a string or array of strings (e.g. `'string'`, `['number','undefined']`). Uses built-in `typeof` checks plus **o.specialTypes**. On failure: throws (default) or returns an Error if **safe** is true. On success: returns `true`.
|
|
436
|
+
- **o.safeVerify(pairs)** — Same as **o.verify(pairs, true)**; returns `true` or `false` (no throw).
|
|
437
|
+
- **o.specialTypes** — Object of custom validators used by **o.verify()**. Built-in: `notEmptyString`, `array`, `promise`. **Developers can add global validators here**: assign a function `(value, typeofValue) => boolean` to **o.specialTypes.myType**. That validator is then available everywhere—in your app and inside Objs—so you can use `o.verify([x, ['myType']])` consistently.
|
|
438
|
+
|
|
439
|
+
`o.showErrors` – false as default, but all errors are saved in **o.errors[]**.
|
|
440
|
+
|
|
441
|
+
`o.errors` – an array of all errors.
|
|
442
|
+
|
|
443
|
+
`o.logErrors()` – log all hidden errors in console.
|
|
444
|
+
|
|
445
|
+
`o.onError` – set a function that is called when an error happens.
|
|
446
|
+
|
|
447
|
+
`o.getStates()` – returns array of state info per init.
|
|
448
|
+
|
|
449
|
+
`o.getStores()` – returns array of store refs.
|
|
450
|
+
|
|
451
|
+
`o.getListeners()` – returns array of listener refs.
|
|
452
|
+
|
|
453
|
+
`o.camelToKebab(str)`, `o.kebabToCamel(str)` – convert between naming conventions.
|
|
454
|
+
|
|
455
|
+
`o.C(obj, key)` – safe `Object.hasOwn`-style check; returns whether `obj` has own property `key`. Used internally; available for app code. `o.F` and `o.U` are internal constants (false, undefined). `o.W` and `o.H` exist but are reserved; do not rely on them.
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
## Why Objs for AI-assisted development
|
|
461
|
+
|
|
462
|
+
### The complete loop in one script
|
|
463
|
+
|
|
464
|
+
```
|
|
465
|
+
develop → o.autotag / o.reactQA → o.startRecording() → o.stopRecording()
|
|
466
|
+
→ o.exportPlaywrightTest() → paste → npx playwright test
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
No Playwright config to set up manually. No test IDs to maintain. The entire pipeline — component, QA tag, behavior capture, and Playwright test generation — runs inside the same library. Works in React projects too: add one script tag, sprinkle `{...o.reactQA('MyComponent')}`, record.
|
|
470
|
+
|
|
471
|
+
### Dev/prod build split
|
|
472
|
+
|
|
473
|
+
`objs.js` is the source for development or script tag. `objs.built.js` and `objs.built.min.js` are produced by `node build.js` (ESM + window.o). Only the debug flag is behind `__DEV__`.
|
|
474
|
+
|
|
475
|
+
The **recording pipeline** (`startRecording`, `stopRecording`, `exportTest`, `exportPlaywrightTest`, `reactQA`) ships in all builds so QA assessors can use it on staging.
|
|
476
|
+
|
|
477
|
+
Bundlers pick the right file automatically via `package.json` exports conditions:
|
|
478
|
+
|
|
479
|
+
```js
|
|
480
|
+
// Vite, webpack, esbuild — no config needed
|
|
481
|
+
import o from 'objs-core'; // dev server → objs.js, build → objs.built.js
|
|
482
|
+
|
|
483
|
+
// Script tag
|
|
484
|
+
<script src="objs.js"></script>
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
### States as AI-natural data structures
|
|
488
|
+
|
|
489
|
+
Every Objs component is a plain JS object. An LLM can generate correct components from a description without knowing JSX, virtual DOM, or React lifecycle rules:
|
|
490
|
+
|
|
491
|
+
```js
|
|
492
|
+
// AI prompt: "create a counter with increment and reset"
|
|
493
|
+
// Hack: render as function sets the entity store and returns the init object (no globals, no post-init wiring)
|
|
494
|
+
const counterStates = {
|
|
495
|
+
name: 'Counter',
|
|
496
|
+
render: ({ self }) => {
|
|
497
|
+
self.store.n = self.store.n ?? 0;
|
|
498
|
+
return {
|
|
499
|
+
html: '<span ref="n">0</span> <button ref="inc">+</button> <button ref="rst">Reset</button>',
|
|
500
|
+
events: {
|
|
501
|
+
click: (e) => {
|
|
502
|
+
if (e.target === self.refs?.inc?.el) self.updateCount(++self.store.n);
|
|
503
|
+
else if (e.target === self.refs?.rst?.el) self.updateCount(self.store.n = 0);
|
|
504
|
+
},
|
|
505
|
+
},
|
|
506
|
+
};
|
|
507
|
+
},
|
|
508
|
+
updateCount: ({ self }, num) => {
|
|
509
|
+
self.store.n = num;
|
|
510
|
+
self.refs.n.html(num);
|
|
511
|
+
},
|
|
512
|
+
};
|
|
513
|
+
o.init(counterStates).render().appendInside('#app');
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
No compiler. No build step to try the above. No framework knowledge needed to generate it.
|
|
517
|
+
|
|
518
|
+
### Granular reactive updates — no virtual DOM diff
|
|
519
|
+
|
|
520
|
+
Each store subscription calls exactly one targeted DOM write:
|
|
521
|
+
|
|
522
|
+
```js
|
|
523
|
+
// React with Redux: entire subtree re-renders, React diffs it
|
|
524
|
+
// Objs: one function call, one innerHTML assignment
|
|
525
|
+
o.connectRedux(store, s => s.userName, profileCard, 'updateName');
|
|
526
|
+
o.connectRedux(store, s => s.score, profileCard, 'updateScore');
|
|
527
|
+
```
|
|
528
|
+
|
|
529
|
+
Similar philosophy to Solid.js signals — but the update logic is a plain function, not a reactive primitive. An AI generates it without any framework knowledge.
|
|
530
|
+
|
|
531
|
+
### Comparison
|
|
532
|
+
|
|
533
|
+
| | Objs v2.0 | React ecosystem |
|
|
534
|
+
|---|---|---|
|
|
535
|
+
| **Setup** | `<script src="objs.js">` or `npm i objs-core` | React + Babel/Vite + config |
|
|
536
|
+
| **State management** | Built-in states + loaders | Redux / Zustand / MobX (separate) |
|
|
537
|
+
| **Routing** | `o.route()` built-in | React Router (separate) |
|
|
538
|
+
| **Testing** | Built-in `o.test()` + recording | Jest + Testing Library + Playwright |
|
|
539
|
+
| **Dev tools** | Built-in overlay, recording | React DevTools extension |
|
|
540
|
+
| **TypeScript** | `objs.d.ts` included | @types/react + separate config |
|
|
541
|
+
| **SSR** | Built-in DocumentMVP | Next.js / separate hydration setup |
|
|
542
|
+
| **AI context size** | ~2500 lines, one file | Dozens of packages, thousands of files |
|
|
543
|
+
| **Prod bundle overhead** | Dev code fully stripped | Depends on tree-shaking config |
|
|
544
|
+
|
|
545
|
+
### Real-world patterns
|
|
546
|
+
|
|
547
|
+
See [EXAMPLES.md](EXAMPLES.md) for the architecture guide and runnable examples (aligned with [SKILL.md](SKILL.md)):
|
|
548
|
+
1. **How render works** — plain object, function, HTML string, multi-instance, `append`, `children`, `ref`/`refs`
|
|
549
|
+
2. **Single components (atoms)** — Button, Badge, Field with `val()`, `css(null)`, `addClass` spread
|
|
550
|
+
3. **Nesting & composition** — slot pattern, `append` in render, factory with dynamic children
|
|
551
|
+
4. **Design system** — Atoms → Molecules → Organisms, `self.store`, update efficiency
|
|
552
|
+
5. **Real-world** — menu, cart+cards, dialog, drawer+URL, complex form
|
|
553
|
+
6. **React integration** — four modes including bolt-on Playwright recording with `o.reactQA`
|
|
554
|
+
|
|
555
|
+
**Rule (from SKILL):** Define one state method per data slice; never call `.render()` to update — use targeted state methods. In event handlers use **self.select(e)** and **refs** (e.g. `row.refs.input.val()`), not `e.target`/class selectors or raw DOM.
|
|
556
|
+
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
|
|
560
|
+
## License
|
|
561
|
+
Apache 2.0
|