bigpipe-util 0.2.3 → 0.2.5
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/CHANGELOG.md +21 -2
- package/package.json +1 -1
- package/src/core/Arbiter.js +53 -0
- package/src/core/Dialog.js +10 -12
- package/src/core/Parent.js +31 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,11 +4,30 @@ All notable changes to `bigpipe-util` will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
|
|
6
6
|
|
|
7
|
+
## v0.2.5 - 2023-03-07
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
- Added `Arbiter.js` event system
|
|
11
|
+
- Added methods `byClass`, `byAttribute`, `find` to `Parent.js`
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
- Fixed controller calling
|
|
15
|
+
|
|
16
|
+
## v0.2.4 - 2023-02-03
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
- Fixed controller calling
|
|
20
|
+
|
|
21
|
+
## v0.2.3 - 2023-02-04
|
|
22
|
+
|
|
23
|
+
### Added
|
|
24
|
+
- Added setFinallyHandler for AsyncRequest
|
|
25
|
+
|
|
7
26
|
## v0.2.2 - 2022-08-03
|
|
8
27
|
|
|
9
28
|
### Fixed
|
|
10
|
-
-
|
|
11
|
-
-
|
|
29
|
+
- Calls for modules without constructor
|
|
30
|
+
- Dialog opening when using instant closing
|
|
12
31
|
|
|
13
32
|
## v0.2.1 - 2022-06-02
|
|
14
33
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bigpipe-util",
|
|
3
3
|
"description": "This library currently implements small part of Facebook BigPipe so far, but the advantage is to efficiently insert/replace content and work with the DOM. It is also possible to easily call JavaScript modules from PHP.",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.5",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bigpipe",
|
|
7
7
|
"xhr",
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const _events = {};
|
|
2
|
+
|
|
3
|
+
export default class Arbiter {
|
|
4
|
+
constructor() {
|
|
5
|
+
this._events = _events;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
inform(what, ...args) {
|
|
9
|
+
const list = [...this.getSubscribers(what)];
|
|
10
|
+
for (let i = 0; i < list.length; i++) {
|
|
11
|
+
if (list[i] === null) {
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
list[i].apply(this, args);
|
|
17
|
+
} catch (e) {
|
|
18
|
+
window.setTimeout(() => {
|
|
19
|
+
throw e;
|
|
20
|
+
}, 0);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
getSubscribers(toWhat) {
|
|
27
|
+
return this._events[toWhat] || (this._events[toWhat] = []);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
clearSubscribers(toWhat) {
|
|
31
|
+
if (toWhat) {
|
|
32
|
+
this._events[toWhat] = [];
|
|
33
|
+
}
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
subscribe(toWhat, withWhat) {
|
|
38
|
+
const list = this.getSubscribers(toWhat);
|
|
39
|
+
list.push(withWhat);
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
unsubscribe(toWhat, withWhat) {
|
|
44
|
+
const list = this.getSubscribers(toWhat);
|
|
45
|
+
for (let i = 0; i < list.length; i++) {
|
|
46
|
+
if (list[i] === withWhat) {
|
|
47
|
+
list.splice(i, 1);
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
}
|
package/src/core/Dialog.js
CHANGED
|
@@ -39,10 +39,10 @@ export default class Dialog {
|
|
|
39
39
|
const dialog = this._show({
|
|
40
40
|
el: document.getElementById(this.id),
|
|
41
41
|
animate: false,
|
|
42
|
-
keyboard: options.keyboard
|
|
43
|
-
backdrop: options.backdrop
|
|
44
|
-
transition: options.transition
|
|
45
|
-
backdropTransition: options.backdropTransition
|
|
42
|
+
keyboard: options.keyboard !== null && options.keyboard !== undefined ? options.keyboard : true,
|
|
43
|
+
backdrop: options.backdrop !== null && options.backdrop !== undefined ? options.backdrop : true,
|
|
44
|
+
transition: options.transition !== null && options.transition !== undefined ? options.transition : 0,
|
|
45
|
+
backdropTransition: options.backdropTransition !== null && options.backdropTransition !== undefined ? options.backdropTransition : 0,
|
|
46
46
|
}, options.controller, args);
|
|
47
47
|
|
|
48
48
|
stack.push(dialog);
|
|
@@ -56,10 +56,10 @@ export default class Dialog {
|
|
|
56
56
|
content: model.body,
|
|
57
57
|
footer: model.footer || false,
|
|
58
58
|
animate: false,
|
|
59
|
-
keyboard: model.keyboard
|
|
60
|
-
backdrop: model.backdrop
|
|
61
|
-
transition: model.transition
|
|
62
|
-
backdropTransition: model.backdropTransition
|
|
59
|
+
keyboard: model.keyboard !== null && model.keyboard !== undefined ? model.keyboard : true,
|
|
60
|
+
backdrop: model.backdrop !== null && model.backdrop !== undefined ? model.backdrop : true,
|
|
61
|
+
transition: model.transition !== null && model.transition !== undefined ? model.transition : 0,
|
|
62
|
+
backdropTransition: model.backdropTransition !== null && model.backdropTransition !== undefined ? model.backdropTransition : 0,
|
|
63
63
|
}, model.controller, args);
|
|
64
64
|
|
|
65
65
|
stack.push(dialog);
|
|
@@ -76,10 +76,8 @@ export default class Dialog {
|
|
|
76
76
|
|
|
77
77
|
if (controller) {
|
|
78
78
|
if (typeof controller === 'string') {
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (typeof controller === 'function') {
|
|
79
|
+
(new (window.require(controller))(_modal, ...args));
|
|
80
|
+
} else if (typeof controller === 'function') {
|
|
83
81
|
controller(_modal, ...args);
|
|
84
82
|
}
|
|
85
83
|
}
|
package/src/core/Parent.js
CHANGED
|
@@ -1,9 +1,38 @@
|
|
|
1
|
+
import CSSCore from "fbjs/lib/CSSCore";
|
|
2
|
+
|
|
1
3
|
export function byTag(node, tagName) {
|
|
2
4
|
tagName = tagName.toUpperCase();
|
|
5
|
+
node = find(node, function (el) {
|
|
6
|
+
return el.nodeName === tagName;
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
return node instanceof Element ? node : null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function byClass(node, className) {
|
|
13
|
+
node = find(node, function (el) {
|
|
14
|
+
return el instanceof Element && CSSCore.hasClass(el, className);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
return node instanceof Element ? node : null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function byAttribute(node, attribute) {
|
|
21
|
+
node = find(node, function (el) {
|
|
22
|
+
return el instanceof Element && el.hasAttribute(attribute);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return node instanceof Element ? node : null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function find(node, callback) {
|
|
29
|
+
while (node) {
|
|
30
|
+
if (callback(node)) {
|
|
31
|
+
return node;
|
|
32
|
+
}
|
|
3
33
|
|
|
4
|
-
while (node && node.nodeName !== tagName) {
|
|
5
34
|
node = node.parentNode;
|
|
6
35
|
}
|
|
7
36
|
|
|
8
|
-
return
|
|
37
|
+
return null;
|
|
9
38
|
}
|