@webqit/observer 2.0.7 → 2.1.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/.gitignore +3 -3
- package/LICENSE +20 -20
- package/README.md +416 -202
- package/dist/main.js +1 -1
- package/dist/main.js.map +3 -3
- package/package.json +68 -68
- package/src/actors.js +180 -176
- package/src/core/Descriptor.js +22 -22
- package/src/core/ListenerRegistration.js +61 -57
- package/src/core/ListenerRegistry.js +73 -70
- package/src/core/Registration.js +34 -34
- package/src/core/Registry.js +92 -92
- package/src/core/TrapsRegistration.js +34 -34
- package/src/core/TrapsRegistry.js +50 -50
- package/src/index.js +9 -9
- package/src/main.js +585 -561
- package/src/targets.browser.js +8 -8
- package/src/util.js +9 -7
- package/test/reactions.test.js +351 -352
- package/webpack.config.cjs +5 -5
|
@@ -1,71 +1,74 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @imports
|
|
4
|
-
*/
|
|
5
|
-
import ListenerRegistration from './ListenerRegistration.js';
|
|
6
|
-
import Registry from './Registry.js';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
|
|
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
|
-
const
|
|
65
|
-
|
|
66
|
-
batch
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @imports
|
|
4
|
+
*/
|
|
5
|
+
import ListenerRegistration from './ListenerRegistration.js';
|
|
6
|
+
import Registry from './Registry.js';
|
|
7
|
+
import { _await } from '../util.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* ---------------------------
|
|
11
|
+
* The ListenerRegistry class
|
|
12
|
+
* ---------------------------
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export default class ListenerRegistry extends Registry {
|
|
16
|
+
|
|
17
|
+
static getInstance( target, createIfNotExists = true, namespace = null ) {
|
|
18
|
+
return super._getInstance( 'listeners', ...arguments );
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
static namespace( namespace, ImplementationClass = null ) {
|
|
22
|
+
return super._namespace( 'listeners', ...arguments );
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @constructor
|
|
27
|
+
*/
|
|
28
|
+
constructor( target ) {
|
|
29
|
+
super( target );
|
|
30
|
+
this.batches = [];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @addRegistration
|
|
35
|
+
*/
|
|
36
|
+
addRegistration( filter, handler, params ) {
|
|
37
|
+
return super.addRegistration( new ListenerRegistration( this, { filter, handler, params } ) );
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Fires all observers with the given evt (change).
|
|
42
|
+
*
|
|
43
|
+
* @param Arrayn events
|
|
44
|
+
*
|
|
45
|
+
* @return Void
|
|
46
|
+
*/
|
|
47
|
+
emit( events ) {
|
|
48
|
+
if ( this.batches.length ) {
|
|
49
|
+
this.batches[ 0 ].events.push( ...events );
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
this.entries.forEach( listener => listener.fire( events ) );
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Fires all observers with the given evt (change).
|
|
57
|
+
*
|
|
58
|
+
* @param Arrayn events
|
|
59
|
+
*
|
|
60
|
+
* @return Void
|
|
61
|
+
*/
|
|
62
|
+
batch( callback ) {
|
|
63
|
+
this.batches.unshift( { entries: [ ...this.entries ], events: [] } );
|
|
64
|
+
const returnValue = callback();
|
|
65
|
+
return _await( returnValue, returnValue => {
|
|
66
|
+
const batch = this.batches.shift();
|
|
67
|
+
if ( batch.events.length ) {
|
|
68
|
+
batch.entries.forEach( listener => listener.fire( batch.events ) );
|
|
69
|
+
}
|
|
70
|
+
return returnValue;
|
|
71
|
+
} )
|
|
72
|
+
}
|
|
73
|
+
|
|
71
74
|
}
|
package/src/core/Registration.js
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* ---------------------------
|
|
4
|
-
* The Registration class
|
|
5
|
-
* ---------------------------
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export default class Registration {
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Initializes the instance.
|
|
12
|
-
*
|
|
13
|
-
* @param Registry registry
|
|
14
|
-
* @param object dfn
|
|
15
|
-
*
|
|
16
|
-
* @return void
|
|
17
|
-
*/
|
|
18
|
-
constructor( registry, dfn ) {
|
|
19
|
-
this.registry = registry;
|
|
20
|
-
Object.assign( this, { ...dfn, target: registry.target } );
|
|
21
|
-
if ( this.params.signal ) {
|
|
22
|
-
this.params.signal.addEventListener( 'abort', () => this.remove() );
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Sets a "disconnected" flag on the Registration.
|
|
28
|
-
*
|
|
29
|
-
* @return void
|
|
30
|
-
*/
|
|
31
|
-
remove() {
|
|
32
|
-
this.removed = true;
|
|
33
|
-
return this.registry.removeRegistration( this );
|
|
34
|
-
}
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* ---------------------------
|
|
4
|
+
* The Registration class
|
|
5
|
+
* ---------------------------
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export default class Registration {
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Initializes the instance.
|
|
12
|
+
*
|
|
13
|
+
* @param Registry registry
|
|
14
|
+
* @param object dfn
|
|
15
|
+
*
|
|
16
|
+
* @return void
|
|
17
|
+
*/
|
|
18
|
+
constructor( registry, dfn ) {
|
|
19
|
+
this.registry = registry;
|
|
20
|
+
Object.assign( this, { ...dfn, target: registry.target } );
|
|
21
|
+
if ( this.params.signal ) {
|
|
22
|
+
this.params.signal.addEventListener( 'abort', () => this.remove() );
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Sets a "disconnected" flag on the Registration.
|
|
28
|
+
*
|
|
29
|
+
* @return void
|
|
30
|
+
*/
|
|
31
|
+
remove() {
|
|
32
|
+
this.removed = true;
|
|
33
|
+
return this.registry.removeRegistration( this );
|
|
34
|
+
}
|
|
35
35
|
}
|
package/src/core/Registry.js
CHANGED
|
@@ -1,93 +1,93 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @imports
|
|
4
|
-
*/
|
|
5
|
-
import { _isTypeObject, _getType } from '@webqit/util/js/index.js';
|
|
6
|
-
import { _from as _arrFrom, _intersect, _equals as _arrEquals } from '@webqit/util/arr/index.js';
|
|
7
|
-
import { _ } from '../util.js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* ---------------------------
|
|
11
|
-
* The Registry class
|
|
12
|
-
* ---------------------------
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
export default class Registry {
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Initializes the instance.
|
|
19
|
-
*
|
|
20
|
-
* @param object target
|
|
21
|
-
*
|
|
22
|
-
* @return void
|
|
23
|
-
*/
|
|
24
|
-
constructor( target ) {
|
|
25
|
-
this.target = target;
|
|
26
|
-
this.entries = [];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Adds an Registration instance
|
|
31
|
-
* with optional tags.
|
|
32
|
-
*
|
|
33
|
-
* @param Registration registration
|
|
34
|
-
*
|
|
35
|
-
* @return Registration
|
|
36
|
-
*/
|
|
37
|
-
addRegistration( registration ) {
|
|
38
|
-
this.entries.push( registration );
|
|
39
|
-
return registration;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Removes registrations by reference.
|
|
44
|
-
*
|
|
45
|
-
* @param Registration registration
|
|
46
|
-
*
|
|
47
|
-
* @return void
|
|
48
|
-
*/
|
|
49
|
-
removeRegistration( registration ) {
|
|
50
|
-
this.entries = this.entries.filter( _entry => _entry !== registration );
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Returns a observer-specific object embedded on an element.
|
|
55
|
-
*
|
|
56
|
-
* @param string type
|
|
57
|
-
* @param array|object target
|
|
58
|
-
* @param bool createIfNotExists
|
|
59
|
-
* @param string namespace
|
|
60
|
-
*
|
|
61
|
-
* @return Registry
|
|
62
|
-
*/
|
|
63
|
-
static _getInstance( type, target, createIfNotExists = true, namespace = this.__namespace ) {
|
|
64
|
-
if ( !_isTypeObject( target ) ) throw new Error( `Subject must be of type object; "${ _getType( target ) }" given!` );
|
|
65
|
-
let ImplementationClass = this;
|
|
66
|
-
if ( namespace && _( 'namespaces' ).has( type + '-' + namespace ) ) {
|
|
67
|
-
ImplementationClass = _( 'namespaces' ).get( type + '-' + namespace );
|
|
68
|
-
type += '-' + namespace
|
|
69
|
-
}
|
|
70
|
-
if ( !_( target, 'registry' ).has( type ) && createIfNotExists ) {
|
|
71
|
-
_( target, 'registry' ).set( type, new ImplementationClass( target ) );
|
|
72
|
-
}
|
|
73
|
-
return _( target, 'registry' ).get( type );
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Extend a Fireable Class with a namespace.
|
|
78
|
-
*
|
|
79
|
-
* @param string namespace
|
|
80
|
-
* @param class ImplementationClass
|
|
81
|
-
*
|
|
82
|
-
* @return void|class
|
|
83
|
-
*/
|
|
84
|
-
static _namespace( type, namespace, ImplementationClass = null ) {
|
|
85
|
-
type += '-' + namespace;
|
|
86
|
-
if ( arguments.length === 2 ) return _( 'namespaces' ).get( type );
|
|
87
|
-
if ( !( ImplementationClass.prototype instanceof this ) ) {
|
|
88
|
-
throw new Error( `The implementation of the namespace ${ this.name }.${ namespace } must be a subclass of ${ this.name }.` );
|
|
89
|
-
}
|
|
90
|
-
_( 'namespaces' ).set( type, ImplementationClass );
|
|
91
|
-
ImplementationClass.__namespace = namespace;
|
|
92
|
-
}
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @imports
|
|
4
|
+
*/
|
|
5
|
+
import { _isTypeObject, _getType } from '@webqit/util/js/index.js';
|
|
6
|
+
import { _from as _arrFrom, _intersect, _equals as _arrEquals } from '@webqit/util/arr/index.js';
|
|
7
|
+
import { _ } from '../util.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* ---------------------------
|
|
11
|
+
* The Registry class
|
|
12
|
+
* ---------------------------
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export default class Registry {
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Initializes the instance.
|
|
19
|
+
*
|
|
20
|
+
* @param object target
|
|
21
|
+
*
|
|
22
|
+
* @return void
|
|
23
|
+
*/
|
|
24
|
+
constructor( target ) {
|
|
25
|
+
this.target = target;
|
|
26
|
+
this.entries = [];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Adds an Registration instance
|
|
31
|
+
* with optional tags.
|
|
32
|
+
*
|
|
33
|
+
* @param Registration registration
|
|
34
|
+
*
|
|
35
|
+
* @return Registration
|
|
36
|
+
*/
|
|
37
|
+
addRegistration( registration ) {
|
|
38
|
+
this.entries.push( registration );
|
|
39
|
+
return registration;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Removes registrations by reference.
|
|
44
|
+
*
|
|
45
|
+
* @param Registration registration
|
|
46
|
+
*
|
|
47
|
+
* @return void
|
|
48
|
+
*/
|
|
49
|
+
removeRegistration( registration ) {
|
|
50
|
+
this.entries = this.entries.filter( _entry => _entry !== registration );
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Returns a observer-specific object embedded on an element.
|
|
55
|
+
*
|
|
56
|
+
* @param string type
|
|
57
|
+
* @param array|object target
|
|
58
|
+
* @param bool createIfNotExists
|
|
59
|
+
* @param string namespace
|
|
60
|
+
*
|
|
61
|
+
* @return Registry
|
|
62
|
+
*/
|
|
63
|
+
static _getInstance( type, target, createIfNotExists = true, namespace = this.__namespace ) {
|
|
64
|
+
if ( !_isTypeObject( target ) ) throw new Error( `Subject must be of type object; "${ _getType( target ) }" given!` );
|
|
65
|
+
let ImplementationClass = this;
|
|
66
|
+
if ( namespace && _( 'namespaces' ).has( type + '-' + namespace ) ) {
|
|
67
|
+
ImplementationClass = _( 'namespaces' ).get( type + '-' + namespace );
|
|
68
|
+
type += '-' + namespace
|
|
69
|
+
}
|
|
70
|
+
if ( !_( target, 'registry' ).has( type ) && createIfNotExists ) {
|
|
71
|
+
_( target, 'registry' ).set( type, new ImplementationClass( target ) );
|
|
72
|
+
}
|
|
73
|
+
return _( target, 'registry' ).get( type );
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Extend a Fireable Class with a namespace.
|
|
78
|
+
*
|
|
79
|
+
* @param string namespace
|
|
80
|
+
* @param class ImplementationClass
|
|
81
|
+
*
|
|
82
|
+
* @return void|class
|
|
83
|
+
*/
|
|
84
|
+
static _namespace( type, namespace, ImplementationClass = null ) {
|
|
85
|
+
type += '-' + namespace;
|
|
86
|
+
if ( arguments.length === 2 ) return _( 'namespaces' ).get( type );
|
|
87
|
+
if ( !( ImplementationClass.prototype instanceof this ) ) {
|
|
88
|
+
throw new Error( `The implementation of the namespace ${ this.name }.${ namespace } must be a subclass of ${ this.name }.` );
|
|
89
|
+
}
|
|
90
|
+
_( 'namespaces' ).set( type, ImplementationClass );
|
|
91
|
+
ImplementationClass.__namespace = namespace;
|
|
92
|
+
}
|
|
93
93
|
}
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @imports
|
|
4
|
-
*/
|
|
5
|
-
import Registration from './Registration.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* ---------------------------
|
|
9
|
-
* The TrapsRegistration class
|
|
10
|
-
* ---------------------------
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
export default class TrapsRegistration extends Registration {
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Calls the observer's handler function
|
|
17
|
-
* on matching with the descriptor's fields.
|
|
18
|
-
*
|
|
19
|
-
* @param Descriptor descriptor
|
|
20
|
-
* @param function next
|
|
21
|
-
* @param mixed recieved
|
|
22
|
-
*
|
|
23
|
-
* @return void
|
|
24
|
-
*/
|
|
25
|
-
exec( descriptor, next, recieved ) {
|
|
26
|
-
if ( this.running || !this.traps[ descriptor.type ] ) {
|
|
27
|
-
return next( ...Array.prototype.slice.call( arguments, 2 ) );
|
|
28
|
-
}
|
|
29
|
-
this.running = true;
|
|
30
|
-
return this.traps[ descriptor.type ]( descriptor, recieved, ( ...args ) => {
|
|
31
|
-
this.running = false;
|
|
32
|
-
return next( ...args );
|
|
33
|
-
} );
|
|
34
|
-
}
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @imports
|
|
4
|
+
*/
|
|
5
|
+
import Registration from './Registration.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* ---------------------------
|
|
9
|
+
* The TrapsRegistration class
|
|
10
|
+
* ---------------------------
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export default class TrapsRegistration extends Registration {
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Calls the observer's handler function
|
|
17
|
+
* on matching with the descriptor's fields.
|
|
18
|
+
*
|
|
19
|
+
* @param Descriptor descriptor
|
|
20
|
+
* @param function next
|
|
21
|
+
* @param mixed recieved
|
|
22
|
+
*
|
|
23
|
+
* @return void
|
|
24
|
+
*/
|
|
25
|
+
exec( descriptor, next, recieved ) {
|
|
26
|
+
if ( this.running || !this.traps[ descriptor.type ] ) {
|
|
27
|
+
return next( ...Array.prototype.slice.call( arguments, 2 ) );
|
|
28
|
+
}
|
|
29
|
+
this.running = true;
|
|
30
|
+
return this.traps[ descriptor.type ]( descriptor, recieved, ( ...args ) => {
|
|
31
|
+
this.running = false;
|
|
32
|
+
return next( ...args );
|
|
33
|
+
} );
|
|
34
|
+
}
|
|
35
35
|
}
|
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @imports
|
|
4
|
-
*/
|
|
5
|
-
import TrapsRegistration from './TrapsRegistration.js';
|
|
6
|
-
import Registry from './Registry.js';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* ---------------------------
|
|
10
|
-
* The TrapsRegistry class
|
|
11
|
-
* ---------------------------
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
export default class TrapsRegistry extends Registry {
|
|
15
|
-
|
|
16
|
-
static getInstance( target, createIfNotExists = true, namespace = null ) {
|
|
17
|
-
return super._getInstance( 'traps', ...arguments );
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
static namespace( namespace, ImplementationClass = null ) {
|
|
21
|
-
return super._namespace( 'traps', ...arguments );
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @inheritdoc
|
|
26
|
-
*/
|
|
27
|
-
addRegistration( dfn ) {
|
|
28
|
-
return super.addRegistration( new TrapsRegistration( this, dfn ) );
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Fires all interceptors with the given action.
|
|
33
|
-
*
|
|
34
|
-
* @param Descriptor descriptor
|
|
35
|
-
* @param function defaultHandler
|
|
36
|
-
*
|
|
37
|
-
* @return mixed
|
|
38
|
-
*/
|
|
39
|
-
emit( descriptor, defaultHandler = null ) {
|
|
40
|
-
const $this = this;
|
|
41
|
-
return ( function next( index, ..._args ) {
|
|
42
|
-
const registration = $this.entries[ index ];
|
|
43
|
-
if ( registration ) {
|
|
44
|
-
return registration.exec( descriptor, ( ...args ) => {
|
|
45
|
-
return next( index + 1, ...args );
|
|
46
|
-
}/*next*/, ..._args );
|
|
47
|
-
}
|
|
48
|
-
return defaultHandler ? defaultHandler( descriptor, ..._args ) : _args[ 0 ];
|
|
49
|
-
} )( 0 );
|
|
50
|
-
}
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @imports
|
|
4
|
+
*/
|
|
5
|
+
import TrapsRegistration from './TrapsRegistration.js';
|
|
6
|
+
import Registry from './Registry.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* ---------------------------
|
|
10
|
+
* The TrapsRegistry class
|
|
11
|
+
* ---------------------------
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export default class TrapsRegistry extends Registry {
|
|
15
|
+
|
|
16
|
+
static getInstance( target, createIfNotExists = true, namespace = null ) {
|
|
17
|
+
return super._getInstance( 'traps', ...arguments );
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static namespace( namespace, ImplementationClass = null ) {
|
|
21
|
+
return super._namespace( 'traps', ...arguments );
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @inheritdoc
|
|
26
|
+
*/
|
|
27
|
+
addRegistration( dfn ) {
|
|
28
|
+
return super.addRegistration( new TrapsRegistration( this, dfn ) );
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Fires all interceptors with the given action.
|
|
33
|
+
*
|
|
34
|
+
* @param Descriptor descriptor
|
|
35
|
+
* @param function defaultHandler
|
|
36
|
+
*
|
|
37
|
+
* @return mixed
|
|
38
|
+
*/
|
|
39
|
+
emit( descriptor, defaultHandler = null ) {
|
|
40
|
+
const $this = this;
|
|
41
|
+
return ( function next( index, ..._args ) {
|
|
42
|
+
const registration = $this.entries[ index ];
|
|
43
|
+
if ( registration ) {
|
|
44
|
+
return registration.exec( descriptor, ( ...args ) => {
|
|
45
|
+
return next( index + 1, ...args );
|
|
46
|
+
}/*next*/, ..._args );
|
|
47
|
+
}
|
|
48
|
+
return defaultHandler ? defaultHandler( descriptor, ..._args ) : _args[ 0 ];
|
|
49
|
+
} )( 0 );
|
|
50
|
+
}
|
|
51
51
|
}
|
package/src/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
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
|
-
|
|
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
10
|
export default Observer;
|