assign-gingerly 0.0.34 → 0.0.35
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 +22 -0
- package/package.json +1 -1
- package/resolveValues.js +4 -2
- package/resolveValues.ts +4 -2
package/README.md
CHANGED
|
@@ -3303,6 +3303,28 @@ console.log(result);
|
|
|
3303
3303
|
|
|
3304
3304
|
-->
|
|
3305
3305
|
|
|
3306
|
+
## Resolving and Assigning with `assignFrom`
|
|
3307
|
+
|
|
3308
|
+
The `assignFrom` function combines RHS path resolution with `assignGingerly` in a single call. It resolves `?.`-prefixed RHS values against a source object, then assigns the results into a target. Use `?.` alone as a RHS value to reference the entire source object itself.
|
|
3309
|
+
|
|
3310
|
+
```TypeScript
|
|
3311
|
+
import { assignFrom } from 'assign-gingerly/assignFrom.js';
|
|
3312
|
+
|
|
3313
|
+
const viewModel = { username: 'Alice', clone: someDocumentFragment };
|
|
3314
|
+
|
|
3315
|
+
assignFrom(target, {
|
|
3316
|
+
'?.appendChild': '?..clone', // source.clone
|
|
3317
|
+
'?.clone?.q?..username?.textContent': '?.username', // source.username
|
|
3318
|
+
ref: '?.' // the source object itself
|
|
3319
|
+
}, {
|
|
3320
|
+
from: viewModel,
|
|
3321
|
+
withMethods: ['appendChild'],
|
|
3322
|
+
aka: { 'q': 'querySelector' }
|
|
3323
|
+
});
|
|
3324
|
+
```
|
|
3325
|
+
|
|
3326
|
+
For full documentation, see [docs/assignFrom.md](docs/assignFrom.md).
|
|
3327
|
+
|
|
3306
3328
|
## Itemscope Managers (Chrome 146+)
|
|
3307
3329
|
|
|
3308
3330
|
Itemscope Managers provide a way to manage DOM fragments and their associated data/view models for elements with the `itemscope` attribute. This feature enables frameworks and libraries to manage light children of web components, DOM fragments from looping constructs, and scenarios where custom element wrapping is not feasible.
|
package/package.json
CHANGED
package/resolveValues.js
CHANGED
|
@@ -26,8 +26,10 @@ export function resolveValues(pattern, source) {
|
|
|
26
26
|
const result = {};
|
|
27
27
|
for (const [key, value] of Object.entries(pattern)) {
|
|
28
28
|
if (typeof value === 'string' && value.startsWith('?.')) {
|
|
29
|
-
// Parse path: split
|
|
30
|
-
|
|
29
|
+
// Parse path: split on '?.' delimiter, filter empties
|
|
30
|
+
// Use '?.' as the sole delimiter to preserve dots in values (e.g., CSS selectors)
|
|
31
|
+
// Special case: '?.' alone (empty path) resolves to the source object itself
|
|
32
|
+
const parts = value.split('?.').filter(p => p.length > 0);
|
|
31
33
|
let current = source;
|
|
32
34
|
for (const part of parts) {
|
|
33
35
|
if (current == null)
|
package/resolveValues.ts
CHANGED
|
@@ -29,8 +29,10 @@ export function resolveValues(
|
|
|
29
29
|
const result: Record<string, any> = {};
|
|
30
30
|
for (const [key, value] of Object.entries(pattern)) {
|
|
31
31
|
if (typeof value === 'string' && value.startsWith('?.')) {
|
|
32
|
-
// Parse path: split
|
|
33
|
-
|
|
32
|
+
// Parse path: split on '?.' delimiter, filter empties
|
|
33
|
+
// Use '?.' as the sole delimiter to preserve dots in values (e.g., CSS selectors)
|
|
34
|
+
// Special case: '?.' alone (empty path) resolves to the source object itself
|
|
35
|
+
const parts = value.split('?.').filter(p => p.length > 0);
|
|
34
36
|
let current = source;
|
|
35
37
|
for (const part of parts) {
|
|
36
38
|
if (current == null) break;
|