@webqit/observer 1.7.6 → 2.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 (58) hide show
  1. package/.gitignore +3 -3
  2. package/LICENSE +20 -20
  3. package/README.md +202 -199
  4. package/dist/main.js +2 -2
  5. package/dist/main.js.map +7 -1
  6. package/package.json +68 -68
  7. package/src/actors.js +175 -0
  8. package/src/core/Descriptor.js +23 -0
  9. package/src/core/ListenerRegistration.js +54 -0
  10. package/src/core/ListenerRegistry.js +41 -0
  11. package/src/core/Registration.js +35 -0
  12. package/src/core/Registry.js +96 -0
  13. package/src/core/TrapsRegistration.js +35 -0
  14. package/src/core/TrapsRegistry.js +51 -0
  15. package/src/index.js +10 -74
  16. package/src/main.js +547 -0
  17. package/src/targets.browser.js +9 -0
  18. package/test/reactions.test.js +326 -337
  19. package/webpack.config.cjs +5 -5
  20. package/src/actions/_exec.js +0 -33
  21. package/src/actions/_setOrDefine.js +0 -136
  22. package/src/actions/apply.js +0 -19
  23. package/src/actions/construct.js +0 -19
  24. package/src/actions/defineProperty.js +0 -20
  25. package/src/actions/deleteProperty.js +0 -80
  26. package/src/actions/get.js +0 -53
  27. package/src/actions/getOwnPropertyDescriptor.js +0 -18
  28. package/src/actions/getPrototypeOf.js +0 -17
  29. package/src/actions/has.js +0 -18
  30. package/src/actions/isExtensible.js +0 -17
  31. package/src/actions/ownKeys.js +0 -17
  32. package/src/actions/preventExtensions.js +0 -17
  33. package/src/actions/set.js +0 -21
  34. package/src/actions/setPrototypeOf.js +0 -18
  35. package/src/actors/accessorize.js +0 -162
  36. package/src/actors/proxy.js +0 -59
  37. package/src/actors/unaccessorize.js +0 -26
  38. package/src/actors/unproxy.js +0 -17
  39. package/src/browser-entry.js +0 -11
  40. package/src/connectors/build.js +0 -64
  41. package/src/connectors/link.js +0 -76
  42. package/src/connectors/unlink.js +0 -35
  43. package/src/core/Action.js +0 -33
  44. package/src/core/Delta.js +0 -46
  45. package/src/core/Event.js +0 -141
  46. package/src/core/Fireable.js +0 -34
  47. package/src/core/Firebase.js +0 -136
  48. package/src/core/Interceptor.js +0 -33
  49. package/src/core/Interceptors.js +0 -61
  50. package/src/core/Mutation.js +0 -46
  51. package/src/core/Observer.js +0 -99
  52. package/src/core/Observers.js +0 -75
  53. package/src/core/utils.js +0 -51
  54. package/src/reactions/closure.js +0 -88
  55. package/src/reactions/intercept.js +0 -53
  56. package/src/reactions/observe.js +0 -45
  57. package/src/reactions/unintercept.js +0 -43
  58. package/src/reactions/unobserve.js +0 -36
package/src/index.js CHANGED
@@ -1,74 +1,10 @@
1
-
2
- /**
3
- * @imports
4
- */
5
- // Actions
6
- import apply from './actions/apply.js';
7
- import construct from './actions/construct.js';
8
- import defineProperty from './actions/defineProperty.js';
9
- import deleteProperty from './actions/deleteProperty.js';
10
- import get from './actions/get.js';
11
- import getOwnPropertyDescriptor from './actions/getOwnPropertyDescriptor.js';
12
- import getPrototypeOf from './actions/getPrototypeOf.js';
13
- import has from './actions/has.js';
14
- import isExtensible from './actions/isExtensible.js';
15
- import ownKeys from './actions/ownKeys.js';
16
- import preventExtensions from './actions/preventExtensions.js';
17
- import set from './actions/set.js';
18
- import setPrototypeOf from './actions/setPrototypeOf.js';
19
- // Actors
20
- import accessorize from './actors/accessorize.js';
21
- import unaccessorize from './actors/unaccessorize.js';
22
- import proxy from './actors/proxy.js';
23
- import unproxy from './actors/unproxy.js';
24
- // Reactions
25
- import observe from './reactions/observe.js';
26
- import unobserve from './reactions/unobserve.js';
27
- import intercept from './reactions/intercept.js';
28
- import unintercept from './reactions/unintercept.js';
29
- import closure from './reactions/closure.js';
30
- // Connectors
31
- import build from './connectors/build.js';
32
- import link from './connectors/link.js';
33
- import unlink from './connectors/unlink.js';
34
- // Core
35
- import Observers from './core/Observers.js';
36
- import Interceptors from './core/Interceptors.js';
37
-
38
- /**
39
- * @exports
40
- */
41
- export default {
42
- // Actions
43
- apply,
44
- construct,
45
- defineProperty,
46
- deleteProperty,
47
- get,
48
- getOwnPropertyDescriptor,
49
- getPrototypeOf,
50
- has,
51
- isExtensible,
52
- ownKeys,
53
- preventExtensions,
54
- set,
55
- setPrototypeOf,
56
- // Actors
57
- accessorize,
58
- unaccessorize,
59
- proxy,
60
- unproxy,
61
- // Reactions
62
- observe,
63
- unobserve,
64
- intercept,
65
- unintercept,
66
- closure,
67
- // Connectors
68
- build,
69
- link,
70
- unlink,
71
- // Core
72
- Observers,
73
- Interceptors,
74
- }
1
+
2
+ /**
3
+ * @imports
4
+ */
5
+ import * as main from './main.js';
6
+ import * as actors from './actors.js';
7
+
8
+ const Observer = { ...main, ...actors };
9
+
10
+ export default Observer;
package/src/main.js ADDED
@@ -0,0 +1,547 @@
1
+
2
+ /**
3
+ * @imports
4
+ */
5
+ import { _internals, _isObject, _isTypeObject, _isFunction, _getType } from '@webqit/util/js/index.js';
6
+ import { _from as _arrFrom } from '@webqit/util/arr/index.js';
7
+ import ListenerRegistry from './core/ListenerRegistry.js';
8
+ import TrapsRegistry from './core/TrapsRegistry.js';
9
+ import Descriptor from './core/Descriptor.js';
10
+ import { unproxy } from './actors.js';
11
+
12
+ /* ---------------SPECIAL APIs--------------- */
13
+
14
+ /**
15
+ * Reduces a path array against handler.
16
+ *
17
+ * @param Array|Object target
18
+ * @param Array path
19
+ * @param Function receiver
20
+ * @param Function final
21
+ * @param Object params
22
+ *
23
+ * @example deep( object, [ segement1, segement2 ], observe, ( value, flags ) => {}, params );
24
+ *
25
+ * @return Any
26
+ */
27
+ export function deep( target, path, receiver, final = x => x, params = {} ) {
28
+ return ( function eat( target, path, _params ) {
29
+ const segment = path[ _params.level ];
30
+ // ---------------
31
+ if ( _params.level < path.length - 1 ) { _params = { ..._params, preflight: true }; }
32
+ else { _params = { ..._params, preflight: /*reset*/params.preflight }; }
33
+ // ---------------
34
+ return receiver( target, segment, ( result, ...args ) => {
35
+ // -----------
36
+ const paramsNext = ( flags = {} ) => ( { ..._params, ...flags, level: _params.level + 1, } );
37
+ const addTrail = desc => {
38
+ if ( !( desc instanceof Descriptor ) ) return;
39
+ desc.path = [ desc.key ];
40
+ if ( target instanceof Descriptor ) {
41
+ desc.path = target.path.concat( desc.key );
42
+ desc.context = target;
43
+ }
44
+ };
45
+ // -----------
46
+ if ( isPropsList( segment ) && Array.isArray( result ) ) {
47
+ // -----------
48
+ result.forEach( addTrail );
49
+ if ( _params.level === path.length - 1 || ( !result.length && _params.midwayResults ) ) return final( result, ...args );
50
+ return result.map( entry => eat( entry, path, paramsNext( ...args ) ) )
51
+ // -----------
52
+ }
53
+ // -----------
54
+ addTrail( result );
55
+ const $isTypeObject = _isTypeObject( resolveObj( result, false ) );
56
+ if ( _params.level === path.length - 1 || ( !$isTypeObject && _params.midwayResults ) ) return final( result, ...args );
57
+ return $isTypeObject && eat( result, path, paramsNext( ...args ) );
58
+ // -----------
59
+ }, _params );
60
+ } )( target, path.slice( 0 ), { ...params, level: 0 } );
61
+ }
62
+
63
+ /**
64
+ * Adds an observer to a target's registry.
65
+ *
66
+ * @param Array|Object target
67
+ * @param String|Object prop
68
+ * @param Function receiver
69
+ * @param Object params
70
+ *
71
+ * @return AbortController
72
+ */
73
+ export function observe( target, prop, receiver, params = {} ) {
74
+ // ---------------
75
+ target = resolveObj( target );
76
+ if ( _isFunction( arguments[ 1 ] ) ) {
77
+ [ , receiver, params = {} ] = arguments;
78
+ prop = Infinity;
79
+ }
80
+ if ( !_isFunction( receiver ) ) throw new Error( `Handler must be a function; "${ _getType( receiver ) }" given!` );
81
+ // ---------------
82
+ const emit = bind( target, prop, receiver, params );
83
+ if ( params.preflight ) {
84
+ params = { ...params, descripted: true };
85
+ delete params.live;
86
+ return get( target, prop, emit, params );
87
+ }
88
+ return emit();
89
+ }
90
+
91
+ /**
92
+ * Adds an interceptor object to a target's registry.
93
+ *
94
+ * @param Array|Object target
95
+ * @param Object traps
96
+ * @param Object params
97
+ *
98
+ * @return AbortRegistry
99
+ */
100
+ export function intercept( target, traps, params = {} ) {
101
+ // ---------------
102
+ target = resolveObj( target );
103
+ if ( !_isObject( traps ) ) {
104
+ [ /*target*/, /*type*/, /*handler*/, params = {} ] = arguments;
105
+ traps = { [ arguments[ 1 ] ]: arguments[ 2 ] };
106
+ }
107
+ // ---------------
108
+ return TrapsRegistry.getInstance( target, true, params.namespace ).addRegistration( { traps, params } );
109
+ }
110
+
111
+ /* ---------------QUERY APIs--------------- */
112
+
113
+ /**
114
+ * Performs a "getOwnPropertyDescriptor" operation.
115
+ *
116
+ * @param Array|Object target
117
+ * @param String|Number prop
118
+ * @param Function receiver
119
+ * @param Object params
120
+ *
121
+ * @return Any
122
+ */
123
+ export function getOwnPropertyDescriptor( target, prop, receiver = x => x, params = {} ) {
124
+ return exec( target, 'getOwnPropertyDescriptor', { key: prop }, receiver, params );
125
+ }
126
+
127
+ /**
128
+ * Performs a "getOwnPropertyDescriptors" operation.
129
+ * @note this isn't part of the standard Reflect API.
130
+ *
131
+ * @param Array|Object target
132
+ * @param String|Number prop
133
+ * @param Function receiver
134
+ * @param Object params
135
+ *
136
+ * @return Any
137
+ */
138
+ export function getOwnPropertyDescriptors( target, prop, receiver = x => x, params = {} ) {
139
+ return exec( target, 'getOwnPropertyDescriptors', { key: prop }, receiver, params );
140
+ }
141
+
142
+ /**
143
+ * Performs a "getPrototypeOf" operation.
144
+ *
145
+ * @param Array|Object target
146
+ * @param Function receiver
147
+ * @param Object params
148
+ *
149
+ * @return Any
150
+ */
151
+ export function getPrototypeOf( target, receiver = x => x, params = {} ) {
152
+ return exec( target, 'getPrototypeOf', {}, receiver, params );
153
+ }
154
+
155
+ /**
156
+ * Performs a "isExtensible" operation.
157
+ *
158
+ * @param Array|Object target
159
+ * @param Function receiver
160
+ * @param Object params
161
+ *
162
+ * @return Any
163
+ */
164
+ export function isExtensible( target, receiver = x => x, params = {} ) {
165
+ return exec( target, 'isExtensible', {}, receiver, params );
166
+ }
167
+
168
+ /**
169
+ * Performs a "ownKeys" operation.
170
+ *
171
+ * @param Array|Object target
172
+ * @param Function receiver
173
+ * @param Object params
174
+ *
175
+ * @return Any
176
+ */
177
+ export function ownKeys( target, receiver = x => x, params = {} ) {
178
+ return exec( target, 'ownKeys', {}, receiver, params );
179
+ }
180
+
181
+ /**
182
+ * Performs an operation of the given "type".
183
+ *
184
+ * @param Array|Object target
185
+ * @param String|Number prop
186
+ * @param Function receiver
187
+ * @param Object params
188
+ *
189
+ * @return Any
190
+ */
191
+ export function has( target, prop, receiver = x => x, params = {} ) {
192
+ return exec( target, 'has', { key: prop }, receiver, params );
193
+ }
194
+
195
+ /**
196
+ * Performs a get operation.
197
+ *
198
+ * @param Array|Object target
199
+ * @param String|Number prop
200
+ * @param Function receiver
201
+ * @param Object params
202
+ *
203
+ * @return Any
204
+ */
205
+ export function get( target, prop, receiver = x => x, params = {} ) {
206
+ // ---------------
207
+ let isLive;
208
+ target = resolveObj( target );
209
+ if ( _isObject( receiver ) ) { [ params, receiver ] = [ receiver, x => x ]; }
210
+ else if ( params.live ) { isLive = true; }
211
+ // ---------------
212
+ return resolveProps( target, prop, props => {
213
+ const related = [ ...props ];
214
+ return ( function next( results, _props, _done ) {
215
+ if ( !_props.length ) return _done( results );
216
+ const prop = _props.shift();
217
+ // ---------
218
+ function defaultGet( descriptor, value = undefined ) {
219
+ const _next = value => ( descriptor.value = value, next( results.concat( params.live || params.descripted ? descriptor : value ), _props, _done ) );
220
+ if ( arguments.length > 1 ) return _next( value );
221
+ const accessorizedProps = _internals( target, 'accessorizedProps', false );
222
+ const accessorization = accessorizedProps && accessorizedProps.get( descriptor.key );
223
+ if ( accessorization && accessorization.intact() ) {
224
+ return _next( accessorization.getValue() );
225
+ }
226
+ return _next( Reflect.get( target, descriptor.key, ...( params.receiver ? [ params.receiver ] : [] ) ) );
227
+ }
228
+ // ---------
229
+ const descriptor = new Descriptor( target, {
230
+ type: 'get',
231
+ key: prop,
232
+ value: undefined,
233
+ related,
234
+ } );
235
+ const listenerRegistry = TrapsRegistry.getInstance( target, false, params.namespace );
236
+ if ( listenerRegistry ) {
237
+ return listenerRegistry.emit( descriptor, defaultGet );
238
+ }
239
+ return defaultGet( descriptor );
240
+ } )( [], props.slice( 0 ), results => {
241
+ const result_s = isPropsList( prop/*original*/ ) ? results : results[ 0 ];
242
+ if ( isLive ) {
243
+ const emit = bind( target, prop, receiver, params );
244
+ return emit( result_s );
245
+ }
246
+ return receiver( result_s );
247
+ } );
248
+ } );
249
+ }
250
+
251
+ /* ---------------MUTATION APIs--------------- */
252
+
253
+ /**
254
+ * Performs a set operation.
255
+ *
256
+ * @param Object target
257
+ * @param String|Number prop
258
+ * @param Any value
259
+ * @param Function receiver
260
+ * @param Object params
261
+ * @param Bool def
262
+ *
263
+ * @return Any
264
+ */
265
+ export function set( target, prop, value, receiver = x => x, params = {}, def = false ) {
266
+ // ---------------
267
+ target = resolveObj( target );
268
+ let entries = [ [ prop, value ] ];
269
+ if ( _isObject( prop ) ) {
270
+ [ /*target*/, /*hash*/, receiver = x => x, params = {}, def = false ] = arguments;
271
+ entries = Object.entries( prop );
272
+ }
273
+ if ( _isObject( receiver ) ) { [ def, params, receiver ] = [ typeof params === 'boolean' ? params : false, receiver, x => x ]; }
274
+ // ---------------
275
+ const related = entries.map( ( [ prop ] ) => prop );
276
+ return ( function next( descriptors, entries, _done ) {
277
+ if ( !entries.length ) return _done( descriptors );
278
+ const [ prop, value ] = entries.shift();
279
+ // ---------
280
+ function defaultSet( descriptor, status = undefined ) {
281
+ const _next = status => ( descriptor.status = status, next( descriptors.concat( descriptor ), entries, _done ) );
282
+ if ( arguments.length > 1 ) return _next( descriptor, status );
283
+ const accessorizedProps = _internals( target, 'accessorizedProps', false );
284
+ const accessorization = accessorizedProps && accessorizedProps.get( descriptor.key );
285
+ if ( descriptor.type === 'defineProperty' ) {
286
+ if ( accessorization && !accessorization.restore() ) _next( false );
287
+ Object.defineProperty( target, descriptor.key, descriptor.value );
288
+ return _next( true );
289
+ }
290
+ if ( accessorization && accessorization.intact() ) {
291
+ return _next( accessorization.setValue( descriptor.value ) );
292
+ }
293
+ return _next( Reflect.set( target, descriptor.key, descriptor.value ) );
294
+ }
295
+ // ---------
296
+ function exec( isUpdate, oldValue ) {
297
+ const descriptor = new Descriptor( target, {
298
+ type: def ? 'defineProperty' : 'set',
299
+ key: prop,
300
+ value,
301
+ isUpdate,
302
+ oldValue,
303
+ related: [ ...related ],
304
+ detail: params.detail,
305
+ } );
306
+ const listenerRegistry = TrapsRegistry.getInstance( target, false, params.namespace );
307
+ return listenerRegistry
308
+ ? listenerRegistry.emit( descriptor, defaultSet )
309
+ : defaultSet( descriptor );
310
+ }
311
+ // ---------
312
+ return has( target, prop, isUpdate => {
313
+ if ( !isUpdate || params.oldValue !== true ) return exec( isUpdate );
314
+ return get( target, prop, oldValue => exec( isUpdate, oldValue ), params );
315
+ }, params );
316
+ // ---------
317
+ } )( [], entries.slice( 0 ), descriptors => {
318
+ const listenerRegistry = ListenerRegistry.getInstance( target, false, params.namespace );
319
+ if ( listenerRegistry ) listenerRegistry.emit( descriptors );
320
+ return receiver(
321
+ isPropsList( prop/*original*/ ) ? descriptors.map( opr => opr.status ) : descriptors[ 0 ].status
322
+ );
323
+ } );
324
+ }
325
+
326
+ /**
327
+ * Performs a defineProperty operation.
328
+ *
329
+ * @param Object target
330
+ * @param String|Number prop
331
+ * @param Object descriptor
332
+ * @param Function receiver
333
+ * @param Object params
334
+ *
335
+ * @return Any
336
+ */
337
+ export function defineProperty( target, prop, descriptor, receiver = x => x, params = {} ) {
338
+ return set( target, prop, descriptor, receiver, params, true/*def*/ );
339
+ }
340
+
341
+ /**
342
+ * Performs a defineProperties operation.
343
+ * @note this isn't part of the standard Reflect API.
344
+ *
345
+ * @param Object target
346
+ * @param Object descriptors
347
+ * @param Function receiver
348
+ * @param Object params
349
+ *
350
+ * @return Any
351
+ */
352
+ export function defineProperties( target, descriptors, receiver = x => x, params = {} ) {
353
+ return set( target, descriptors, receiver, params, true/*def*/ );
354
+ }
355
+
356
+ /**
357
+ * Performs a delete operation.
358
+ *
359
+ * @param Object target
360
+ * @param String|Number prop
361
+ * @param Function receiver
362
+ * @param Object params
363
+ *
364
+ * @return Any
365
+ */
366
+ export function deleteProperty( target, prop, receiver = x => x, params = {} ) {
367
+ // ---------------
368
+ target = resolveObj( target );
369
+ if ( _isObject( receiver ) ) { [ params, receiver ] = [ receiver, x => x ]; }
370
+ // ---------------
371
+ const props = _arrFrom( prop ), related = [ ...props ];
372
+ return ( function next( descriptors, props, _done ) {
373
+ if ( !props.length ) return _done( descriptors );
374
+ const prop = props.shift();
375
+ // ---------
376
+ function defaultDel( descriptor, status = undefined ) {
377
+ const _next = status => ( descriptor.status = status, next( descriptors.concat( descriptor ), props, _done ) );
378
+ if ( arguments.length > 1 ) return _next( descriptor, status );
379
+ const accessorizedProps = _internals( target, 'accessorizedProps', false );
380
+ const accessorization = accessorizedProps && accessorizedProps.get( descriptor.key );
381
+ if ( accessorization && !accessorization.restore() ) _next( false );
382
+ return _next( Reflect.deleteProperty( target, descriptor.key ) );
383
+ }
384
+ // ---------
385
+ function exec( oldValue ) {
386
+ const descriptor = new Descriptor( target, {
387
+ type: 'deleteProperty',
388
+ key: prop,
389
+ oldValue,
390
+ related: [ ...related ],
391
+ detail: params.detail,
392
+ } );
393
+ const listenerRegistry = TrapsRegistry.getInstance( target, false, params.namespace );
394
+ return listenerRegistry
395
+ ? listenerRegistry.emit( descriptor, defaultDel )
396
+ : defaultDel( descriptor );
397
+ }
398
+ // ---------
399
+ if ( params.oldValue === false ) return exec();
400
+ return get( target, prop, exec, params );
401
+ // ---------
402
+ } )( [], props.slice( 0 ), descriptors => {
403
+ const listenerRegistry = ListenerRegistry.getInstance( target, false, params.namespace );
404
+ if ( listenerRegistry ) listenerRegistry.emit( descriptors );
405
+ return receiver(
406
+ isPropsList( prop/*original*/ ) ? descriptors.map( opr => opr.status ) : descriptors[ 0 ].status
407
+ );
408
+ } );
409
+ }
410
+
411
+ /* ---------------EFFECT APIs--------------- */
412
+
413
+ /**
414
+ * Performs a "construct" operation.
415
+ *
416
+ * @param Array|Object target
417
+ * @param Array argumentsList
418
+ * @param Object newTarget
419
+ * @param Function receiver
420
+ * @param Object params
421
+ *
422
+ * @return Any
423
+ */
424
+ export function construct( target, argumentsList, newTarget = null, receiver = x => x, params = {} ) {
425
+ return exec( target, 'construct', arguments.length > 2 ? { argumentsList, newTarget } : { argumentsList }, receiver, params );
426
+ }
427
+
428
+ /**
429
+ * Performs an "apply" operation.
430
+ *
431
+ * @param Array|Object target
432
+ * @param Any thisArgument
433
+ * @param Array argumentsList
434
+ * @param Function receiver
435
+ * @param Object params
436
+ *
437
+ * @return Any
438
+ */
439
+ export function apply( target, thisArgument, argumentsList, receiver = x => x, params = {} ) {
440
+ return exec( target, 'apply', { thisArgument, argumentsList }, receiver, params );
441
+ }
442
+
443
+ /**
444
+ * Performs a "setPrototypeOf" operation.
445
+ *
446
+ * @param Array|Object target
447
+ * @param Anyr proto
448
+ * @param Function receiver
449
+ * @param Object params
450
+ *
451
+ * @return Any
452
+ */
453
+ export function setPrototypeOf( target, proto, receiver = x => x, params = {} ) {
454
+ return exec( target, 'setPrototypeOf', { proto }, receiver, params );
455
+ }
456
+
457
+ /**
458
+ * Performs a "preventExtension" operation.
459
+ *
460
+ * @param Array|Object target
461
+ * @param Function receiver
462
+ * @param Object params
463
+ *
464
+ * @return Any
465
+ */
466
+ export function preventExtensions( target, receiver = x => x, params = {} ) {
467
+ return exec( target, 'preventExtensions', {}, receiver, params );
468
+ }
469
+
470
+ /* ---------------HELPER APIs--------------- */
471
+
472
+ /**
473
+ * Adds an observer to a target's registry.
474
+ *
475
+ * @param Array|Object target
476
+ * @param String|Object prop
477
+ * @param Function receiver
478
+ * @param Object params
479
+ *
480
+ * @return Function: AbortController
481
+ */
482
+ function bind( target, prop, receiver, params = {} ) {
483
+ let controller;
484
+ if ( !params.signal ) {
485
+ controller = new AbortController;
486
+ params = { ...params, signal: controller.signal };
487
+ }
488
+ const listenerRegistry = ListenerRegistry.getInstance( target, true, params.namespace );
489
+ return function emit( descriptor_s, prevRegistration = null ) {
490
+ prevRegistration?.remove();
491
+ const registrationNext = listenerRegistry.addRegistration( prop, emit, params );
492
+ const flags = { signal: registrationNext.signal, };
493
+ if ( arguments.length ) {
494
+ receiver( descriptor_s, flags );
495
+ }
496
+ return controller;
497
+ };
498
+ }
499
+
500
+ /**
501
+ * Performs an operation of the given "type".
502
+ *
503
+ * @param Array|Object target
504
+ * @param String type
505
+ * @param Object payload
506
+ * @param Function receiver
507
+ * @param Object params
508
+ *
509
+ * @return Any
510
+ */
511
+ function exec( target, type, payload = {}, receiver = x => x, params = {} ) {
512
+ // ---------
513
+ target = resolveObj( target );
514
+ if ( _isObject( receiver ) ) { [ params, receiver ] = [ receiver, x => x ]; }
515
+ // ---------
516
+ function defaultExec( descriptor, result ) {
517
+ if ( arguments.length > 1 ) return receiver( result );
518
+ return receiver( Reflect[ type ]( target, ...Object.values( payload ) ) );
519
+ }
520
+ // ---------
521
+ const descriptor = new Descriptor( target, { type, ...payload } );
522
+ const listenerRegistry = TrapsRegistry.getInstance( target, false, params.namespace );
523
+ if ( listenerRegistry ) {
524
+ return listenerRegistry.emit( descriptor, defaultExec );
525
+ }
526
+ return defaultExec( descriptor );
527
+ }
528
+
529
+ // Asks if prop is a multi-result field
530
+ function isPropsList( prop ) {
531
+ return prop === Infinity || Array.isArray( prop );
532
+ }
533
+
534
+ // Resolves obj down to it's self
535
+ function resolveObj( obj, assert = true ) {
536
+ if ( ( !obj || !_isTypeObject( obj ) ) && assert ) throw new Error( `Object must be of type object or array! "${ _getType( obj ) }" given.` );
537
+ if ( obj instanceof Descriptor ) {
538
+ obj = obj.value;
539
+ }
540
+ return obj && unproxy( obj );
541
+ }
542
+
543
+ // Resolves prop down to actual keys
544
+ function resolveProps( obj, prop, receiver ) {
545
+ if ( prop === Infinity ) return ownKeys( obj, receiver );
546
+ return receiver( _arrFrom( prop ) );
547
+ }
@@ -0,0 +1,9 @@
1
+
2
+ /**
3
+ * @imports
4
+ */
5
+ import * as Observer from './index.js';
6
+
7
+ // As globals
8
+ if ( !window.wq ) { window.wq = {}; }
9
+ window.wq.Observer = Observer;