@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.
- package/.gitignore +3 -3
- package/LICENSE +20 -20
- package/README.md +202 -199
- package/dist/main.js +2 -2
- package/dist/main.js.map +7 -1
- package/package.json +68 -68
- package/src/actors.js +175 -0
- package/src/core/Descriptor.js +23 -0
- package/src/core/ListenerRegistration.js +54 -0
- package/src/core/ListenerRegistry.js +41 -0
- package/src/core/Registration.js +35 -0
- package/src/core/Registry.js +96 -0
- package/src/core/TrapsRegistration.js +35 -0
- package/src/core/TrapsRegistry.js +51 -0
- package/src/index.js +10 -74
- package/src/main.js +547 -0
- package/src/targets.browser.js +9 -0
- package/test/reactions.test.js +326 -337
- package/webpack.config.cjs +5 -5
- package/src/actions/_exec.js +0 -33
- package/src/actions/_setOrDefine.js +0 -136
- package/src/actions/apply.js +0 -19
- package/src/actions/construct.js +0 -19
- package/src/actions/defineProperty.js +0 -20
- package/src/actions/deleteProperty.js +0 -80
- package/src/actions/get.js +0 -53
- package/src/actions/getOwnPropertyDescriptor.js +0 -18
- package/src/actions/getPrototypeOf.js +0 -17
- package/src/actions/has.js +0 -18
- package/src/actions/isExtensible.js +0 -17
- package/src/actions/ownKeys.js +0 -17
- package/src/actions/preventExtensions.js +0 -17
- package/src/actions/set.js +0 -21
- package/src/actions/setPrototypeOf.js +0 -18
- package/src/actors/accessorize.js +0 -162
- package/src/actors/proxy.js +0 -59
- package/src/actors/unaccessorize.js +0 -26
- package/src/actors/unproxy.js +0 -17
- package/src/browser-entry.js +0 -11
- package/src/connectors/build.js +0 -64
- package/src/connectors/link.js +0 -76
- package/src/connectors/unlink.js +0 -35
- package/src/core/Action.js +0 -33
- package/src/core/Delta.js +0 -46
- package/src/core/Event.js +0 -141
- package/src/core/Fireable.js +0 -34
- package/src/core/Firebase.js +0 -136
- package/src/core/Interceptor.js +0 -33
- package/src/core/Interceptors.js +0 -61
- package/src/core/Mutation.js +0 -46
- package/src/core/Observer.js +0 -99
- package/src/core/Observers.js +0 -75
- package/src/core/utils.js +0 -51
- package/src/reactions/closure.js +0 -88
- package/src/reactions/intercept.js +0 -53
- package/src/reactions/observe.js +0 -45
- package/src/reactions/unintercept.js +0 -43
- package/src/reactions/unobserve.js +0 -36
package/src/actors/proxy.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @imports
|
|
4
|
-
*/
|
|
5
|
-
import {
|
|
6
|
-
_isClass, _isFunction, _isTypeObject,
|
|
7
|
-
_getType, _internals,
|
|
8
|
-
} from '@webqit/util/js/index.js';
|
|
9
|
-
import apply from '../actions/apply.js';
|
|
10
|
-
import construct from '../actions/construct.js';
|
|
11
|
-
import defineProperty from '../actions/defineProperty.js';
|
|
12
|
-
import deleteProperty from '../actions/deleteProperty.js';
|
|
13
|
-
import get from '../actions/get.js';
|
|
14
|
-
import getOwnPropertyDescriptor from '../actions/getOwnPropertyDescriptor.js';
|
|
15
|
-
import getPrototypeOf from '../actions/getPrototypeOf.js';
|
|
16
|
-
import has from '../actions/has.js';
|
|
17
|
-
import isExtensible from '../actions/isExtensible.js';
|
|
18
|
-
import ownKeys from '../actions/ownKeys.js';
|
|
19
|
-
import preventExtensions from '../actions/preventExtensions.js';
|
|
20
|
-
import set from '../actions/set.js';
|
|
21
|
-
import setPrototypeOf from '../actions/setPrototypeOf.js';
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Returns an object as a proxy and binds all instance methods
|
|
25
|
-
* to the proxy instead of the object itself.
|
|
26
|
-
*
|
|
27
|
-
* @param Object|Array target
|
|
28
|
-
* @param Object params
|
|
29
|
-
*
|
|
30
|
-
* @return Proxy
|
|
31
|
-
*/
|
|
32
|
-
export default function(target, params = {}) {
|
|
33
|
-
if (!_isTypeObject(target)) {
|
|
34
|
-
throw new Error('Object must be of type target; "' + _getType(target) + '" given!');
|
|
35
|
-
}
|
|
36
|
-
var proxy = new Proxy(target, {
|
|
37
|
-
apply: (target, thisArgument, argumentsList) => apply(target, thisArgument, argumentsList, params),
|
|
38
|
-
construct: (target, argumentsList, newTarget = null) => construct(target, argumentsList, newTarget, params),
|
|
39
|
-
defineProperty: (target, propertyKey, attributes) => defineProperty(target, propertyKey, attributes, params),
|
|
40
|
-
deleteProperty: (target, propertyKey) => deleteProperty(target, propertyKey, params),
|
|
41
|
-
get: (target, propertyKey, receiver = null) => {
|
|
42
|
-
var val = get(target, propertyKey, receiver, params);
|
|
43
|
-
if (params.proxyAutoBinding !== false && _isFunction(val) && !_isClass(val)) {
|
|
44
|
-
return val.bind(proxy);
|
|
45
|
-
}
|
|
46
|
-
return val;
|
|
47
|
-
},
|
|
48
|
-
getOwnPropertyDescriptor: (target, propertyKey) => getOwnPropertyDescriptor(target, propertyKey, params),
|
|
49
|
-
getPrototypeOf: target => getPrototypeOf(target, params),
|
|
50
|
-
has: (target, propertyKey) => has(target, propertyKey, params),
|
|
51
|
-
isExtensible: target => isExtensible(target, params),
|
|
52
|
-
ownKeys: target => ownKeys(target, params),
|
|
53
|
-
preventExtensions: target => preventExtensions(target, params),
|
|
54
|
-
set: (target, propertyKey, value, receiver = null) => set(target, propertyKey, value, receiver, params),
|
|
55
|
-
setPrototypeOf: (target, prototype) => setPrototypeOf(target, prototype, params),
|
|
56
|
-
});
|
|
57
|
-
_internals(proxy).set(proxy, target);
|
|
58
|
-
return proxy;
|
|
59
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @imports
|
|
4
|
-
*/
|
|
5
|
-
import { _isArray, _isObject, _internals } from '@webqit/util/js/index.js';
|
|
6
|
-
import { _from as _arrFrom } from '@webqit/util/arr/index.js';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Removes previously initialized "Reflxive getter/setter" traps from the target.
|
|
10
|
-
*
|
|
11
|
-
* @param array|object target
|
|
12
|
-
* @param string|array keys
|
|
13
|
-
* @param object params
|
|
14
|
-
*
|
|
15
|
-
* @return bool|array
|
|
16
|
-
*/
|
|
17
|
-
export default function(target, keys = [], params = {}) {
|
|
18
|
-
params = _isObject(keys) ? keys : params;
|
|
19
|
-
var successFlags = (arguments.length === 1 ? Object.keys(target) : _arrFrom(keys)).map(key => {
|
|
20
|
-
if (_internals(target, 'accessorizedProps', false).has(key)) {
|
|
21
|
-
return _internals(target, 'accessorizedProps').get(key).restore();
|
|
22
|
-
}
|
|
23
|
-
return true;
|
|
24
|
-
});
|
|
25
|
-
return _isArray(keys) ? successFlags : successFlags[0];
|
|
26
|
-
}
|
package/src/actors/unproxy.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @imports
|
|
4
|
-
*/
|
|
5
|
-
import { _internals } from '@webqit/util/js/index.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Returns the original object earlier proxied by proxy().
|
|
9
|
-
*
|
|
10
|
-
* @param Proxy|Any target
|
|
11
|
-
*
|
|
12
|
-
* @return Any
|
|
13
|
-
*/
|
|
14
|
-
export default function(target) {
|
|
15
|
-
// Proxy targets are mapped to their own instances internally
|
|
16
|
-
return _internals(target, false).get(target) || target;
|
|
17
|
-
}
|
package/src/browser-entry.js
DELETED
package/src/connectors/build.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @imports
|
|
4
|
-
*/
|
|
5
|
-
import { _isTypeObject } from '@webqit/util/js/index.js';
|
|
6
|
-
import { _from as _arrFrom } from '@webqit/util/arr/index.js';
|
|
7
|
-
import { _before, _after } from '@webqit/util/str/index.js';
|
|
8
|
-
import { paths2D } from '../core/utils.js';
|
|
9
|
-
import Observers from '../core/Observers.js';
|
|
10
|
-
import _get from '../actions/get.js';
|
|
11
|
-
import link from './link.js';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Recursively "connects" an object's members to the object
|
|
15
|
-
* for observer actions.
|
|
16
|
-
*
|
|
17
|
-
* @param array|object target
|
|
18
|
-
* @param string|array paths
|
|
19
|
-
* @param bool subtree
|
|
20
|
-
* @param String namespace
|
|
21
|
-
*
|
|
22
|
-
* @return void
|
|
23
|
-
*/
|
|
24
|
-
export default function build(target, paths = null, subtree = false, namespace = null) {
|
|
25
|
-
if (!target || !_isTypeObject(target)) {
|
|
26
|
-
throw new Error('Target must be of type object!');
|
|
27
|
-
}
|
|
28
|
-
var observers = Observers.getFirebase(target, true, namespace);
|
|
29
|
-
if (!observers || observers.build) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
observers.build = subtree;
|
|
33
|
-
// ---------------------------------
|
|
34
|
-
// For paths2D, refer to the comments at class Observer.
|
|
35
|
-
var _paths2D = paths2D(paths);
|
|
36
|
-
// If any path starts with a dot, (a wild card path), all keys at this level is implied
|
|
37
|
-
var rootLevelKeysToObserve = !_paths2D.length || _paths2D.filter(path => /*Starts with an empty segment*/!path[0] && path[0] !== 0).length
|
|
38
|
-
? Object.keys(target)
|
|
39
|
-
: _paths2D.map(path => path[0]);
|
|
40
|
-
var subLevelKeysToObserve = _paths2D.length ? _paths2D.map(path => path.slice(1)).filter(p => p.length) : null;
|
|
41
|
-
observers.subBuild = subLevelKeysToObserve && subLevelKeysToObserve.length ? subLevelKeysToObserve : null;
|
|
42
|
-
rootLevelKeysToObserve.forEach(key => {
|
|
43
|
-
var value = _get(target, key, null, { namespace });
|
|
44
|
-
try {
|
|
45
|
-
if (_isTypeObject(value)) {
|
|
46
|
-
link(target, key, value, null, params);
|
|
47
|
-
if ((observers.subBuild && isUserObject(value))
|
|
48
|
-
|| (_isFunction(subtree) ? subtree(value) : (subtree && isUserObject(value)))) {
|
|
49
|
-
build(value, observers.subBuild, subtree, namespace);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
} catch(e) {/* instanceof-ing certain primitives may throw */}
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Tells if an object if a User Object.
|
|
58
|
-
*
|
|
59
|
-
* @param Object value
|
|
60
|
-
*
|
|
61
|
-
* @return Bool
|
|
62
|
-
*/
|
|
63
|
-
export const isUserObject = value => ((value instanceof Object) || (value instanceof Array) || (value instanceof Function))
|
|
64
|
-
&& (typeof window === 'undefined' || value !== window);
|
package/src/connectors/link.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @imports
|
|
4
|
-
*/
|
|
5
|
-
import { _each, _merge } from '@webqit/util/obj/index.js';
|
|
6
|
-
import { _isObject } from '@webqit/util/js/index.js';
|
|
7
|
-
import Mutation from '../core/Mutation.js';
|
|
8
|
-
import Observers from '../core/Observers.js';
|
|
9
|
-
import observe from '../reactions/observe.js';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Bubble helper
|
|
13
|
-
*
|
|
14
|
-
* @param array|object target
|
|
15
|
-
* @param string field
|
|
16
|
-
* @param array|object value
|
|
17
|
-
* @param object event
|
|
18
|
-
* @param object params
|
|
19
|
-
*
|
|
20
|
-
* @return void
|
|
21
|
-
*/
|
|
22
|
-
export default function(target, field, value, event = null, params = {}) {
|
|
23
|
-
if (target === value) {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
var observers;
|
|
27
|
-
observe(value, (changes, eventObject) => {
|
|
28
|
-
if (observers = Observers.getFirebase(target, false, params.namespace)) {
|
|
29
|
-
var _changes = changes.map(delta => {
|
|
30
|
-
// ------------
|
|
31
|
-
// Recursive events must not propagate
|
|
32
|
-
// ------------
|
|
33
|
-
var d = delta;
|
|
34
|
-
do {
|
|
35
|
-
if (d.target === target) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
} while(d = d.src);
|
|
39
|
-
// ------------
|
|
40
|
-
// Create propagation
|
|
41
|
-
// ------------
|
|
42
|
-
var dfn = {}; _each(delta, (key, value) => {
|
|
43
|
-
if (key !== 'target' && key !== 'name' && key !== 'path' && key !== 'src') {
|
|
44
|
-
dfn[key] = value;
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
dfn.name = field;
|
|
48
|
-
dfn.path = [field].concat(delta.path);
|
|
49
|
-
dfn.originalSubject = delta.originalSubject;
|
|
50
|
-
dfn.src = delta;
|
|
51
|
-
return new Mutation(target, dfn);
|
|
52
|
-
}).filter(c => c);
|
|
53
|
-
if (_changes.length) {
|
|
54
|
-
return observers.fire(_changes, eventObject.cancellable);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}, {subtree: true, ...params, unique: true, tags: [linkTag, field, target]});
|
|
58
|
-
if (_isObject(event) && (observers = Observers.getFirebase(target, false, params.namespace))) {
|
|
59
|
-
// The event object
|
|
60
|
-
var _event = _merge({
|
|
61
|
-
name: field,
|
|
62
|
-
type: 'set',
|
|
63
|
-
value,
|
|
64
|
-
related: [field],
|
|
65
|
-
}, event);
|
|
66
|
-
let eventObject = observers.fire(_event, params.cancellable);
|
|
67
|
-
if (params.eventTypeReturn) {
|
|
68
|
-
return eventObject;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* @var object
|
|
75
|
-
*/
|
|
76
|
-
export const linkTag = {};
|
package/src/connectors/unlink.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @imports
|
|
4
|
-
*/
|
|
5
|
-
import { _merge } from '@webqit/util/obj/index.js';
|
|
6
|
-
import { _isObject } from '@webqit/util/js/index.js';
|
|
7
|
-
import Observers from '../core/Observers.js';
|
|
8
|
-
import unobserve from '../reactions/unobserve.js';
|
|
9
|
-
import { linkTag } from './link.js';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Unbubble helper
|
|
13
|
-
*
|
|
14
|
-
* @param array|object target
|
|
15
|
-
* @param string field
|
|
16
|
-
* @param array|object object
|
|
17
|
-
* @param object event
|
|
18
|
-
* @param object params
|
|
19
|
-
*
|
|
20
|
-
* @return void
|
|
21
|
-
*/
|
|
22
|
-
export default function(target, field, value, event = null, params = {}) {
|
|
23
|
-
unobserve(value, null, null, {...params, tags:[linkTag, field, target]});
|
|
24
|
-
var observers;
|
|
25
|
-
if (_isObject(event) && (observers = Observers.getFirebase(target, false, params.namespace))) {
|
|
26
|
-
// The event object
|
|
27
|
-
var _event = _merge({
|
|
28
|
-
name: field,
|
|
29
|
-
type: 'del',
|
|
30
|
-
oldValue: value,
|
|
31
|
-
related: [field],
|
|
32
|
-
}, event);
|
|
33
|
-
observers.fire(_event, params.cancellable);
|
|
34
|
-
}
|
|
35
|
-
}
|
package/src/core/Action.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @imports
|
|
4
|
-
*/
|
|
5
|
-
import { _each } from '@webqit/util/obj/index.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* ---------------------------
|
|
9
|
-
* The QueryEvent class
|
|
10
|
-
* ---------------------------
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
export default class Action {
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Initializes the instance.
|
|
17
|
-
*
|
|
18
|
-
* @param array|object target
|
|
19
|
-
* @param object dfn
|
|
20
|
-
*
|
|
21
|
-
* @return void
|
|
22
|
-
*/
|
|
23
|
-
constructor(target, dfn) {
|
|
24
|
-
this.target = target;
|
|
25
|
-
if (!dfn.type) {
|
|
26
|
-
throw new Error('Action type must be given in definition!');
|
|
27
|
-
}
|
|
28
|
-
_each(dfn, (key, value) => {
|
|
29
|
-
Object.defineProperty(this, key, {value, enumerable:true});
|
|
30
|
-
});
|
|
31
|
-
Object.seal(this);
|
|
32
|
-
}
|
|
33
|
-
}
|
package/src/core/Delta.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @imports
|
|
4
|
-
*/
|
|
5
|
-
import _each from '@webqit/util/obj/each.js';
|
|
6
|
-
import { DotSafePath } from './utils.js';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* ---------------------------
|
|
10
|
-
* The QueryEvent class
|
|
11
|
-
* ---------------------------
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
export default class Delta {
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Initializes the instance.
|
|
18
|
-
*
|
|
19
|
-
* @param array|object target
|
|
20
|
-
* @param object dfn
|
|
21
|
-
*
|
|
22
|
-
* @return void
|
|
23
|
-
*/
|
|
24
|
-
constructor(target, dfn) {
|
|
25
|
-
this.target = target;
|
|
26
|
-
if (!dfn.originalSubject) {
|
|
27
|
-
this.originalSubject = target;
|
|
28
|
-
}
|
|
29
|
-
if (!('type' in dfn)) {
|
|
30
|
-
throw new Error('Delta type must be given in definition!');
|
|
31
|
-
}
|
|
32
|
-
if (!('name' in dfn)) {
|
|
33
|
-
throw new Error('Property name must be given in definition!');
|
|
34
|
-
}
|
|
35
|
-
_each(dfn, (key, value) => {
|
|
36
|
-
if (key === 'path') {
|
|
37
|
-
value = DotSafePath.resolve(value);
|
|
38
|
-
}
|
|
39
|
-
Object.defineProperty(this, key, {value, enumerable:true});
|
|
40
|
-
});
|
|
41
|
-
if (!this.path) {
|
|
42
|
-
Object.defineProperty(this, 'path', {value: DotSafePath.resolve([dfn.name]), enumerable:true});
|
|
43
|
-
}
|
|
44
|
-
Object.seal(this);
|
|
45
|
-
}
|
|
46
|
-
}
|
package/src/core/Event.js
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @imports
|
|
4
|
-
*/
|
|
5
|
-
import { _isUndefined, _isObject } from '@webqit/util/js/index.js';
|
|
6
|
-
import { _each } from '@webqit/util/obj/index.js';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* ---------------------------
|
|
10
|
-
* The Event class
|
|
11
|
-
* ---------------------------
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
export default class Event {
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Initializes the instance.
|
|
18
|
-
*
|
|
19
|
-
* @param array|object target
|
|
20
|
-
* @param bool cancellable
|
|
21
|
-
*
|
|
22
|
-
* @return void
|
|
23
|
-
*/
|
|
24
|
-
constructor(target, cancellable = false) {
|
|
25
|
-
this._ = {};
|
|
26
|
-
this._.target = target;
|
|
27
|
-
this._.cancellable = cancellable;
|
|
28
|
-
this._.propagationStopped = false;
|
|
29
|
-
this._.defaultPrevented = false;
|
|
30
|
-
this._.promisesInstance = null;
|
|
31
|
-
this._.promises = [];
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Gets the "target" object.
|
|
36
|
-
*
|
|
37
|
-
* @return array|object
|
|
38
|
-
*/
|
|
39
|
-
get target() {
|
|
40
|
-
return this._.target;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Gets the "cancellable" flag.
|
|
45
|
-
*
|
|
46
|
-
* @return bool
|
|
47
|
-
*/
|
|
48
|
-
get cancellable() {
|
|
49
|
-
return this._.cancellable;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* -----------------------
|
|
54
|
-
* RESPONSE HANDLERS
|
|
55
|
-
* -----------------------
|
|
56
|
-
*/
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Stops the evnt from reaching other listeners.
|
|
60
|
-
*
|
|
61
|
-
* @return bool
|
|
62
|
-
*/
|
|
63
|
-
stopPropagation() {
|
|
64
|
-
this._.propagationStopped = true;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* (Readonly) tells if stopPropagation() has been called.
|
|
69
|
-
*
|
|
70
|
-
* @return bool
|
|
71
|
-
*/
|
|
72
|
-
get propagationStopped() {
|
|
73
|
-
return this._.propagationStopped;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Sets a disposition that asks event initiator not to
|
|
78
|
-
* proceed with default action.
|
|
79
|
-
*
|
|
80
|
-
* @return void
|
|
81
|
-
*/
|
|
82
|
-
preventDefault() {
|
|
83
|
-
this._.defaultPrevented = true;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* (Readonly) tells if preventDefault() has been called.
|
|
88
|
-
*
|
|
89
|
-
* @return bool
|
|
90
|
-
*/
|
|
91
|
-
get defaultPrevented() {
|
|
92
|
-
return this._.defaultPrevented;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Sets a Promise disposition.
|
|
97
|
-
*
|
|
98
|
-
* @param Promise promise
|
|
99
|
-
*
|
|
100
|
-
* @return void
|
|
101
|
-
*/
|
|
102
|
-
waitUntil(promise) {
|
|
103
|
-
if (promise instanceof Promise) {
|
|
104
|
-
this._.promises.push(promise);
|
|
105
|
-
this._.promisesInstance = null;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* (Readonly) returns all promises.
|
|
111
|
-
*
|
|
112
|
-
* @return Promise|null
|
|
113
|
-
*/
|
|
114
|
-
get promises() {
|
|
115
|
-
if (!this._.promisesInstance && this._.promises.length) {
|
|
116
|
-
this._.promisesInstance = Promise.all(this._.promises);
|
|
117
|
-
}
|
|
118
|
-
return this._.promisesInstance;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Evaluates the given disposition value and
|
|
123
|
-
* calls an appropriate disposition method.
|
|
124
|
-
*
|
|
125
|
-
* @params mixed rspns
|
|
126
|
-
*
|
|
127
|
-
* @return void
|
|
128
|
-
*/
|
|
129
|
-
respondWith(rspns) {
|
|
130
|
-
var proms;
|
|
131
|
-
var isEvent = _isObject(rspns) && !_isUndefined(rspns.propagationStopped) && !_isUndefined(rspns.defaultPrevented)
|
|
132
|
-
if ((rspns === false) || (isEvent && rspns.propagationStopped)) {
|
|
133
|
-
this.stopPropagation();
|
|
134
|
-
} else if ((rspns === false) || (isEvent && rspns.defaultPrevented)) {
|
|
135
|
-
this.preventDefault();
|
|
136
|
-
} else if ((rspns instanceof Promise && (proms = rspns))
|
|
137
|
-
|| (isEvent && (proms = rspns.promises))) {
|
|
138
|
-
this.waitUntil(proms);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
package/src/core/Fireable.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* ---------------------------
|
|
4
|
-
* The Fireable class
|
|
5
|
-
* ---------------------------
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export default class Fireable {
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Initializes the instance.
|
|
12
|
-
*
|
|
13
|
-
* @param object|array target
|
|
14
|
-
* @param object dfn
|
|
15
|
-
*
|
|
16
|
-
* @return void
|
|
17
|
-
*/
|
|
18
|
-
constructor(target, dfn) {
|
|
19
|
-
this.target = target;
|
|
20
|
-
this.handler = dfn.handler;
|
|
21
|
-
this.filter = dfn.filter;
|
|
22
|
-
this.params = dfn.params;
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Sets a "disconnected" flag on the Fireable.
|
|
28
|
-
*
|
|
29
|
-
* @return void
|
|
30
|
-
*/
|
|
31
|
-
disconnect() {
|
|
32
|
-
this.disconnected = true;
|
|
33
|
-
}
|
|
34
|
-
}
|
package/src/core/Firebase.js
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @imports
|
|
4
|
-
*/
|
|
5
|
-
import { _isTypeObject, _isFunction, _getType, _internals } from '@webqit/util/js/index.js';
|
|
6
|
-
import { _from as _arrFrom, _intersect, _equals as _arrEquals } from '@webqit/util/arr/index.js';
|
|
7
|
-
import { paths2D } from './utils.js'
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* ---------------------------
|
|
11
|
-
* The Firebase class
|
|
12
|
-
* ---------------------------
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
export default class Firebase {
|
|
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.fireables = [];
|
|
27
|
-
this.currentlyFiring = [];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Adds an Fireable instance
|
|
32
|
-
* with optional tags.
|
|
33
|
-
*
|
|
34
|
-
* @param Fireable fireable
|
|
35
|
-
*
|
|
36
|
-
* @return Fireable
|
|
37
|
-
*/
|
|
38
|
-
add(fireable) {
|
|
39
|
-
this.fireables.push(fireable);
|
|
40
|
-
return fireable;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Removes fireables by instance.
|
|
45
|
-
*
|
|
46
|
-
* @param Fireable fireable
|
|
47
|
-
*
|
|
48
|
-
* @return void
|
|
49
|
-
*/
|
|
50
|
-
remove(fireable) {
|
|
51
|
-
this.fireables = this.fireables.filter(_fireable => _fireable !== fireable);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Removes fireables by definition.
|
|
56
|
-
*
|
|
57
|
-
* @param object dfn
|
|
58
|
-
*
|
|
59
|
-
* @return void
|
|
60
|
-
*/
|
|
61
|
-
removeMatches(dfn) {
|
|
62
|
-
this.match(dfn).forEach(fireable => {
|
|
63
|
-
this.fireables = this.fireables.filter(_fireable => _fireable !== fireable);
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Finds fireables by definition.
|
|
69
|
-
*
|
|
70
|
-
* @param object dfn
|
|
71
|
-
*
|
|
72
|
-
* @return array
|
|
73
|
-
*/
|
|
74
|
-
match(dfn) {
|
|
75
|
-
return this.fireables.filter(fireable => {
|
|
76
|
-
var fireableFilter = paths2D(fireable.filter);
|
|
77
|
-
var fireableTags = _arrFrom((fireable.params || {}).tags);
|
|
78
|
-
// -----------------------
|
|
79
|
-
var dfnFilter = paths2D(dfn.filter);
|
|
80
|
-
var dfnTags = _arrFrom((dfn.params || {}).tags);
|
|
81
|
-
// -----------------------
|
|
82
|
-
return (!dfn.originalHandler || fireable.handler === dfn.originalHandler)
|
|
83
|
-
&& (!dfnFilter.length || _arrEquals(dfnFilter, fireableFilter))
|
|
84
|
-
&& (!dfnTags.length || (dfnTags.length === fireableTags.length && _intersect(fireableTags, dfnTags).length === dfnTags.length));
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Returns a observer-specific object embedded on an element.
|
|
90
|
-
*
|
|
91
|
-
* @param string type
|
|
92
|
-
* @param array|object target
|
|
93
|
-
* @param bool createIfNotExists
|
|
94
|
-
* @param string namespace
|
|
95
|
-
*
|
|
96
|
-
* @return Firebase
|
|
97
|
-
*/
|
|
98
|
-
static _getFirebase(type, target, createIfNotExists = true, namespace = this.__namespace) {
|
|
99
|
-
if (!_isTypeObject(target)) {
|
|
100
|
-
throw new Error('Subject must be of type object; "' + _getType(target) + '" given!');
|
|
101
|
-
}
|
|
102
|
-
var ImplementationClass = this;
|
|
103
|
-
if (namespace && globalThis.WebQitObserverNamespaceRegistry.has(type + '-' + namespace)) {
|
|
104
|
-
ImplementationClass = globalThis.WebQitObserverNamespaceRegistry.get(type + '-' + namespace);
|
|
105
|
-
type += '-' + namespace
|
|
106
|
-
}
|
|
107
|
-
if (!_internals(target, 'firebases').has(type) && createIfNotExists) {
|
|
108
|
-
_internals(target, 'firebases').set(type, new ImplementationClass(target));
|
|
109
|
-
}
|
|
110
|
-
return _internals(target, 'firebases').get(type);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Extend a Fireable Class with a namespace.
|
|
115
|
-
*
|
|
116
|
-
* @param string namespace
|
|
117
|
-
* @param class ImplementationClass
|
|
118
|
-
*
|
|
119
|
-
* @return void|class
|
|
120
|
-
*/
|
|
121
|
-
static _namespace(type, namespace, ImplementationClass = null) {
|
|
122
|
-
type += '-' + namespace;
|
|
123
|
-
if (arguments.length === 2) {
|
|
124
|
-
return globalThis.WebQitObserverNamespaceRegistry.get(type);
|
|
125
|
-
}
|
|
126
|
-
if (!(ImplementationClass.prototype instanceof this)) {
|
|
127
|
-
throw new Error(`The implementation of the namespace ${this.name}.${namespace} must be a subclass of ${this.name}.`);
|
|
128
|
-
}
|
|
129
|
-
globalThis.WebQitObserverNamespaceRegistry.set(type, ImplementationClass);
|
|
130
|
-
ImplementationClass.__namespace = namespace;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if (!globalThis.WebQitObserverNamespaceRegistry) {
|
|
135
|
-
globalThis.WebQitObserverNamespaceRegistry = new Map();
|
|
136
|
-
}
|