@lumjs/core 1.37.1 → 1.37.2
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/lib/types/def.js +8 -7
- package/lib/types/root.js +60 -19
- package/lib/types/unbound/extend.js +15 -19
- package/lib/types/unbound/objects.js +2 -1
- package/package.json +1 -1
package/lib/types/def.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {F,
|
|
4
|
-
const {isObj,
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const {F,B} = require('./js');
|
|
4
|
+
const {isObj,isNil,isProperty,doesDescriptor} = require('./basics');
|
|
5
5
|
const clone = (...args) => Object.assign({}, ...args);
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -95,9 +95,10 @@ const clone = (...args) => Object.assign({}, ...args);
|
|
|
95
95
|
*/
|
|
96
96
|
function def(obj, name, value, opts)
|
|
97
97
|
{
|
|
98
|
-
const isBound
|
|
99
|
-
=
|
|
100
|
-
&& typeof this.bound === F
|
|
98
|
+
const isBound
|
|
99
|
+
= isObj(this)
|
|
100
|
+
&& typeof this.bound === F
|
|
101
|
+
&& this.bound.$this === this;
|
|
101
102
|
|
|
102
103
|
if (isNil(name) || typeof name === B)
|
|
103
104
|
{ // Binding of Isaac?
|
package/lib/types/root.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const {U} = require('./js');
|
|
2
|
-
const {isNil,isArray} = require('./basics');
|
|
2
|
+
const {isNil,isObj,isArray} = require('./basics');
|
|
3
3
|
|
|
4
4
|
// «private»
|
|
5
5
|
function no_root()
|
|
@@ -11,40 +11,81 @@ function no_root()
|
|
|
11
11
|
* The global root object. Usually `globalThis` these days.
|
|
12
12
|
* @alias module:@lumjs/core/types.root
|
|
13
13
|
*/
|
|
14
|
-
const root
|
|
15
|
-
|
|
16
|
-
: typeof
|
|
17
|
-
: typeof
|
|
14
|
+
const root
|
|
15
|
+
= typeof globalThis !== U ? globalThis
|
|
16
|
+
: typeof global !== U ? global
|
|
17
|
+
: typeof self !== U ? self
|
|
18
|
+
: typeof window !== U ? window
|
|
18
19
|
: no_root(); // Unlike the old way, we'll die if the environment is undetermined.
|
|
19
20
|
|
|
20
21
|
exports.root = root;
|
|
21
22
|
|
|
22
|
-
// A
|
|
23
|
+
// A Set of objects to be considered unbound globally.
|
|
23
24
|
const unboundObjects = require('./unbound/objects');
|
|
24
25
|
|
|
26
|
+
// Default options for unbound()
|
|
27
|
+
const UBDO =
|
|
28
|
+
{
|
|
29
|
+
nil: true,
|
|
30
|
+
root: true,
|
|
31
|
+
}
|
|
32
|
+
|
|
25
33
|
/**
|
|
26
34
|
* Pass `this` here to see if it is bound to an object.
|
|
27
35
|
*
|
|
28
|
-
*
|
|
36
|
+
* @param {*} whatIsThis - The `this` from any context
|
|
37
|
+
*
|
|
38
|
+
* @param {(boolean|object)} [opts] Options for advanced behaviours.
|
|
39
|
+
*
|
|
40
|
+
* If this is boolean then it'll be used as `opts.root`;
|
|
41
|
+
* If it is an `Array` or `Set` it will be used as `opts.list`;
|
|
42
|
+
* Use just a plain object literal for specifying named options.
|
|
43
|
+
*
|
|
44
|
+
* TODO: as of v2.0 this will no longer accept a boolean value
|
|
45
|
+
* as a shortcut to `opts.root`. That must be explicitly set.
|
|
46
|
+
*
|
|
47
|
+
* @param {boolean} [opts.root=true] The global root is unbound?
|
|
48
|
+
* @param {boolean} [opts.nil=true] `null` and `undefined` are unbound?
|
|
49
|
+
* @param {(Array|Set)} [opts.list] A list of additional values that
|
|
50
|
+
* for the purposes of this test will be considered unbound.
|
|
51
|
+
*
|
|
52
|
+
* @param {(Array|Set|boolean)} [list] A positional version of `opts.list`;
|
|
53
|
+
* ONLY used when the `opts` argument is boolean.
|
|
54
|
+
*
|
|
55
|
+
* TODO: remove this argument as of v2.0
|
|
29
56
|
*
|
|
30
|
-
* @param {*} whatIsThis - The `this` from any context.
|
|
31
|
-
* @param {boolean} [rootIsUnbound=true] The global root is unbound.
|
|
32
|
-
* @param {(boolean|Array)} [areUnbound=false] A list of unbound objects.
|
|
33
|
-
* If the is `true` we use an global list that can register special
|
|
34
|
-
* internal objects. Otherwise an `Array` of unbound objects may be used.
|
|
35
57
|
* @returns {boolean}
|
|
36
58
|
* @alias module:@lumjs/core/types.unbound
|
|
37
59
|
*/
|
|
38
|
-
function unbound(whatIsThis,
|
|
60
|
+
function unbound(whatIsThis, opts=true, list)
|
|
39
61
|
{
|
|
40
|
-
if (
|
|
41
|
-
{ //
|
|
42
|
-
|
|
62
|
+
if (isObj(opts))
|
|
63
|
+
{ // Merge in defaults
|
|
64
|
+
if (opts instanceof Set || isArray(opts))
|
|
65
|
+
{ // A shortcut to the `list` property
|
|
66
|
+
list = opts;
|
|
67
|
+
opts = Object.assign({}, UBDO);
|
|
68
|
+
}
|
|
69
|
+
else
|
|
70
|
+
{ // Regular options were specified.
|
|
71
|
+
opts = Object.assign({}, UBDO, {list}, opts);
|
|
72
|
+
list = opts.list;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else
|
|
76
|
+
{ // Assume old positional arguments are being used
|
|
77
|
+
opts = Object.assign({}, UBDO, {root: opts});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (list === true)
|
|
81
|
+
{ // Internal special unbound values
|
|
82
|
+
list = unboundObjects;
|
|
43
83
|
}
|
|
44
84
|
|
|
45
|
-
if (isNil(whatIsThis)) return true;
|
|
46
|
-
if (
|
|
47
|
-
if (
|
|
85
|
+
if (opts.nil && isNil(whatIsThis)) return true;
|
|
86
|
+
if (opts.root && whatIsThis === root) return true;
|
|
87
|
+
if (list instanceof Set && list.has(whatIsThis)) return true;
|
|
88
|
+
if (isArray(list) && list.includes(whatIsThis)) return true;
|
|
48
89
|
|
|
49
90
|
// Nothing considered unbound.
|
|
50
91
|
return false;
|
|
@@ -2,45 +2,41 @@
|
|
|
2
2
|
|
|
3
3
|
const def = require('../def');
|
|
4
4
|
const {needObj} = require('../needs');
|
|
5
|
-
const removeFromArray = require('../../arrays/list').removeItems;
|
|
6
5
|
const unboundObjects = require('./objects');
|
|
7
6
|
|
|
8
|
-
// Adds a couple
|
|
7
|
+
// Adds a couple proxy methods to the `unbound` function.
|
|
9
8
|
module.exports = function(unbound)
|
|
10
9
|
{
|
|
11
10
|
/**
|
|
12
11
|
* Add an item to the unbound global objects list.
|
|
13
12
|
*
|
|
14
|
-
* @
|
|
15
|
-
* @
|
|
16
|
-
* @
|
|
17
|
-
* @
|
|
18
|
-
* @
|
|
13
|
+
* @deprecated the global list is going away in 2.0
|
|
14
|
+
* @function module:@lumjs/core/types.unbound.add
|
|
15
|
+
* @param {(object|function)} obj - Value to be added
|
|
16
|
+
* @returns {boolean} always true as of v1.37.2
|
|
17
|
+
* @throws {TypeError} If `obj` was not a valid value
|
|
19
18
|
*/
|
|
20
19
|
def(unbound, 'add', function (obj)
|
|
21
20
|
{
|
|
22
21
|
needObj(obj, true);
|
|
23
|
-
if (
|
|
24
|
-
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
// Add to list and we're done.
|
|
28
|
-
unboundObjects.push(obj);
|
|
22
|
+
if (unboundObjects.has(obj)) return false;
|
|
23
|
+
unboundObjects.add(obj);
|
|
29
24
|
return true;
|
|
30
25
|
});
|
|
31
26
|
|
|
32
27
|
/**
|
|
33
28
|
* Remove an item from the unbound global objects list.
|
|
34
29
|
*
|
|
35
|
-
* @
|
|
36
|
-
* @
|
|
37
|
-
* @
|
|
38
|
-
* @
|
|
39
|
-
* @
|
|
30
|
+
* @deprecated the global list is going away in 2.0
|
|
31
|
+
* @function module:@lumjs/core/types.unbound.remove
|
|
32
|
+
* @param {(object|function)} obj - value to be removed
|
|
33
|
+
* @returns {boolean} always true as of v1.37.2
|
|
34
|
+
* @throws {TypeError} If `obj` was not a valid value
|
|
40
35
|
*/
|
|
41
36
|
def(unbound, 'remove', function(obj)
|
|
42
37
|
{
|
|
43
38
|
needObj(obj, true);
|
|
44
|
-
|
|
39
|
+
unboundObjects.delete(obj);
|
|
40
|
+
return true;
|
|
45
41
|
});
|
|
46
42
|
}
|