assign-gingerly 0.0.10 → 0.0.11
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 +3 -3
- package/assignGingerly.js +4 -4
- package/assignGingerly.ts +5 -5
- package/object-extension.js +5 -5
- package/object-extension.ts +5 -5
- package/package.json +1 -1
- package/types.d.ts +1 -1
package/README.md
CHANGED
|
@@ -607,7 +607,7 @@ When you access `element.enh.set.enhKey.property`, the proxy:
|
|
|
607
607
|
|
|
608
608
|
1. **Checks the registry**: Looks for a registry item with `enhKey` matching the property name
|
|
609
609
|
2. **Spawns if needed**: If found and the enhancement doesn't exist or is the wrong type:
|
|
610
|
-
- Creates a `SpawnContext` with `{
|
|
610
|
+
- Creates a `SpawnContext` with `{ config: registryItem }`
|
|
611
611
|
- Calls the constructor with `(element, ctx, initVals)`
|
|
612
612
|
- If a non-matching object already exists at `element.enh[enhKey]`, it's passed as `initVals`
|
|
613
613
|
- Stores the spawned instance at `element.enh[enhKey]`
|
|
@@ -629,7 +629,7 @@ Enhancement classes should follow this constructor signature:
|
|
|
629
629
|
|
|
630
630
|
```TypeScript
|
|
631
631
|
interface SpawnContext<T> {
|
|
632
|
-
|
|
632
|
+
config: IBaseRegistryItem<T>;
|
|
633
633
|
}
|
|
634
634
|
|
|
635
635
|
class Enhancement {
|
|
@@ -1185,7 +1185,7 @@ static canSpawn(obj: any, ctx?: SpawnContext<T>): boolean
|
|
|
1185
1185
|
```
|
|
1186
1186
|
|
|
1187
1187
|
- `obj`: The target object being enhanced (element, plain object, etc.)
|
|
1188
|
-
- `ctx`: Optional spawn context containing `{
|
|
1188
|
+
- `ctx`: Optional spawn context containing `{ config: IBaseRegistryItem<T> }`
|
|
1189
1189
|
- Returns: `true` to allow spawning, `false` to block
|
|
1190
1190
|
|
|
1191
1191
|
### Use Cases
|
package/assignGingerly.js
CHANGED
|
@@ -315,7 +315,7 @@ export function assignGingerly(target, source, options) {
|
|
|
315
315
|
const SpawnClass = registryItem.spawn;
|
|
316
316
|
// Check canSpawn if it exists
|
|
317
317
|
if (typeof SpawnClass.canSpawn === 'function') {
|
|
318
|
-
const ctx = {
|
|
318
|
+
const ctx = { config: registryItem };
|
|
319
319
|
if (!SpawnClass.canSpawn(target, ctx)) {
|
|
320
320
|
// canSpawn returned false, skip spawning
|
|
321
321
|
continue;
|
|
@@ -323,7 +323,7 @@ export function assignGingerly(target, source, options) {
|
|
|
323
323
|
}
|
|
324
324
|
// If target is an Element and registryItem has enhKey, pass element to constructor
|
|
325
325
|
if (registryItem.enhKey && typeof Element !== 'undefined' && target instanceof Element) {
|
|
326
|
-
const ctx = {
|
|
326
|
+
const ctx = { config: registryItem };
|
|
327
327
|
const initVals = target.enh?.[registryItem.enhKey] &&
|
|
328
328
|
!(target.enh[registryItem.enhKey] instanceof SpawnClass)
|
|
329
329
|
? target.enh[registryItem.enhKey]
|
|
@@ -370,7 +370,7 @@ export function assignGingerly(target, source, options) {
|
|
|
370
370
|
const SpawnClass = registryItem.spawn;
|
|
371
371
|
// Check canSpawn if it exists
|
|
372
372
|
if (typeof SpawnClass.canSpawn === 'function') {
|
|
373
|
-
const ctx = {
|
|
373
|
+
const ctx = { config: registryItem };
|
|
374
374
|
if (!SpawnClass.canSpawn(target, ctx)) {
|
|
375
375
|
// canSpawn returned false, skip spawning
|
|
376
376
|
return true;
|
|
@@ -378,7 +378,7 @@ export function assignGingerly(target, source, options) {
|
|
|
378
378
|
}
|
|
379
379
|
// If target is an Element and registryItem has enhKey, pass element to constructor
|
|
380
380
|
if (registryItem.enhKey && typeof Element !== 'undefined' && target instanceof Element) {
|
|
381
|
-
const ctx = {
|
|
381
|
+
const ctx = { config: registryItem };
|
|
382
382
|
const initVals = target.enh?.[registryItem.enhKey] &&
|
|
383
383
|
!(target.enh[registryItem.enhKey] instanceof SpawnClass)
|
|
384
384
|
? target.enh[registryItem.enhKey]
|
package/assignGingerly.ts
CHANGED
|
@@ -15,7 +15,7 @@ export interface EnhancementConfig<T = any> {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export interface SpawnContext<T = any> {
|
|
18
|
-
|
|
18
|
+
config: EnhancementConfig<T>;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/**
|
|
@@ -379,7 +379,7 @@ export function assignGingerly(
|
|
|
379
379
|
|
|
380
380
|
// Check canSpawn if it exists
|
|
381
381
|
if (typeof SpawnClass.canSpawn === 'function') {
|
|
382
|
-
const ctx = {
|
|
382
|
+
const ctx = { config: registryItem };
|
|
383
383
|
if (!SpawnClass.canSpawn(target, ctx)) {
|
|
384
384
|
// canSpawn returned false, skip spawning
|
|
385
385
|
continue;
|
|
@@ -388,7 +388,7 @@ export function assignGingerly(
|
|
|
388
388
|
|
|
389
389
|
// If target is an Element and registryItem has enhKey, pass element to constructor
|
|
390
390
|
if (registryItem.enhKey && typeof Element !== 'undefined' && target instanceof Element) {
|
|
391
|
-
const ctx = {
|
|
391
|
+
const ctx = { config: registryItem };
|
|
392
392
|
const initVals = (target as any).enh?.[registryItem.enhKey] &&
|
|
393
393
|
!((target as any).enh[registryItem.enhKey] instanceof SpawnClass)
|
|
394
394
|
? (target as any).enh[registryItem.enhKey]
|
|
@@ -442,7 +442,7 @@ export function assignGingerly(
|
|
|
442
442
|
|
|
443
443
|
// Check canSpawn if it exists
|
|
444
444
|
if (typeof SpawnClass.canSpawn === 'function') {
|
|
445
|
-
const ctx = {
|
|
445
|
+
const ctx = { config: registryItem };
|
|
446
446
|
if (!SpawnClass.canSpawn(target, ctx)) {
|
|
447
447
|
// canSpawn returned false, skip spawning
|
|
448
448
|
return true;
|
|
@@ -451,7 +451,7 @@ export function assignGingerly(
|
|
|
451
451
|
|
|
452
452
|
// If target is an Element and registryItem has enhKey, pass element to constructor
|
|
453
453
|
if (registryItem.enhKey && typeof Element !== 'undefined' && target instanceof Element) {
|
|
454
|
-
const ctx = {
|
|
454
|
+
const ctx = { config: registryItem };
|
|
455
455
|
const initVals = (target as any).enh?.[registryItem.enhKey] &&
|
|
456
456
|
!((target as any).enh[registryItem.enhKey] instanceof SpawnClass)
|
|
457
457
|
? (target as any).enh[registryItem.enhKey]
|
package/object-extension.js
CHANGED
|
@@ -75,7 +75,7 @@ class ElementEnhancementContainer {
|
|
|
75
75
|
const SpawnClass = registryItem.spawn;
|
|
76
76
|
// Check canSpawn if it exists
|
|
77
77
|
if (typeof SpawnClass.canSpawn === 'function') {
|
|
78
|
-
const ctx = {
|
|
78
|
+
const ctx = { config: registryItem };
|
|
79
79
|
if (!SpawnClass.canSpawn(element, ctx)) {
|
|
80
80
|
// canSpawn returned false, return undefined
|
|
81
81
|
return undefined;
|
|
@@ -83,7 +83,7 @@ class ElementEnhancementContainer {
|
|
|
83
83
|
}
|
|
84
84
|
// Check if there's an enhKey
|
|
85
85
|
if (registryItem.enhKey) {
|
|
86
|
-
const ctx = {
|
|
86
|
+
const ctx = { config: registryItem };
|
|
87
87
|
const self = this;
|
|
88
88
|
// Parse attributes if withAttrs is defined
|
|
89
89
|
let attrInitVals = undefined;
|
|
@@ -111,7 +111,7 @@ class ElementEnhancementContainer {
|
|
|
111
111
|
}
|
|
112
112
|
else {
|
|
113
113
|
// No enhKey, just spawn with element
|
|
114
|
-
const ctx = {
|
|
114
|
+
const ctx = { config: registryItem };
|
|
115
115
|
instance = new SpawnClass(element, ctx);
|
|
116
116
|
}
|
|
117
117
|
// Store in global instance map
|
|
@@ -209,7 +209,7 @@ class ElementEnhancementContainer {
|
|
|
209
209
|
const SpawnClass = registryItem.spawn;
|
|
210
210
|
// Check canSpawn if it exists
|
|
211
211
|
if (typeof SpawnClass.canSpawn === 'function') {
|
|
212
|
-
const ctx = {
|
|
212
|
+
const ctx = { config: registryItem };
|
|
213
213
|
if (!SpawnClass.canSpawn(element, ctx)) {
|
|
214
214
|
// canSpawn returned false, return undefined
|
|
215
215
|
return undefined;
|
|
@@ -221,7 +221,7 @@ class ElementEnhancementContainer {
|
|
|
221
221
|
initVals = self[prop];
|
|
222
222
|
}
|
|
223
223
|
// Create spawn context
|
|
224
|
-
const ctx = {
|
|
224
|
+
const ctx = { config: registryItem };
|
|
225
225
|
// Spawn the instance
|
|
226
226
|
instance = new SpawnClass(element, ctx, initVals);
|
|
227
227
|
// Store in global instance map
|
package/object-extension.ts
CHANGED
|
@@ -148,7 +148,7 @@ class ElementEnhancementContainer {
|
|
|
148
148
|
|
|
149
149
|
// Check canSpawn if it exists
|
|
150
150
|
if (typeof SpawnClass.canSpawn === 'function') {
|
|
151
|
-
const ctx = {
|
|
151
|
+
const ctx = { config: registryItem };
|
|
152
152
|
if (!SpawnClass.canSpawn(element, ctx)) {
|
|
153
153
|
// canSpawn returned false, return undefined
|
|
154
154
|
return undefined;
|
|
@@ -157,7 +157,7 @@ class ElementEnhancementContainer {
|
|
|
157
157
|
|
|
158
158
|
// Check if there's an enhKey
|
|
159
159
|
if (registryItem.enhKey) {
|
|
160
|
-
const ctx = {
|
|
160
|
+
const ctx = { config: registryItem };
|
|
161
161
|
const self = this as any;
|
|
162
162
|
|
|
163
163
|
// Parse attributes if withAttrs is defined
|
|
@@ -192,7 +192,7 @@ class ElementEnhancementContainer {
|
|
|
192
192
|
self[registryItem.enhKey] = instance;
|
|
193
193
|
} else {
|
|
194
194
|
// No enhKey, just spawn with element
|
|
195
|
-
const ctx = {
|
|
195
|
+
const ctx = { config: registryItem };
|
|
196
196
|
instance = new SpawnClass(element, ctx);
|
|
197
197
|
}
|
|
198
198
|
|
|
@@ -315,7 +315,7 @@ class ElementEnhancementContainer {
|
|
|
315
315
|
|
|
316
316
|
// Check canSpawn if it exists
|
|
317
317
|
if (typeof SpawnClass.canSpawn === 'function') {
|
|
318
|
-
const ctx = {
|
|
318
|
+
const ctx = { config: registryItem };
|
|
319
319
|
if (!SpawnClass.canSpawn(element, ctx)) {
|
|
320
320
|
// canSpawn returned false, return undefined
|
|
321
321
|
return undefined;
|
|
@@ -330,7 +330,7 @@ class ElementEnhancementContainer {
|
|
|
330
330
|
}
|
|
331
331
|
|
|
332
332
|
// Create spawn context
|
|
333
|
-
const ctx = {
|
|
333
|
+
const ctx = { config: registryItem };
|
|
334
334
|
|
|
335
335
|
// Spawn the instance
|
|
336
336
|
instance = new SpawnClass(element, ctx, initVals);
|
package/package.json
CHANGED