@builder.io/sdk 3.0.2-2 → 3.0.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/.yarnrc.yml +1 -0
- package/CHANGELOG.md +6 -0
- package/dist/index.browser.js +13 -5
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs.js +13 -5
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +13 -5
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +13 -49
- package/dist/index.umd.js +13 -5
- package/dist/index.umd.js.map +1 -1
- package/dist/package.json +3 -3
- package/dist/src/builder.class.js +12 -4
- package/dist/src/builder.class.js.map +1 -1
- package/dist/src/builder.class.test.js +153 -171
- package/dist/src/classes/animator.class.js +195 -218
- package/dist/src/classes/observable.class.js +97 -102
- package/dist/src/classes/promise.class.js +154 -150
- package/dist/src/classes/query-string.class.js +74 -73
- package/dist/src/classes/query-string.class.test.js +20 -20
- package/dist/src/constants/builder.js +4 -4
- package/dist/src/functions/assign.function.js +19 -19
- package/dist/src/functions/fetch.function.js +75 -97
- package/dist/src/functions/finder.function.js +274 -389
- package/dist/src/functions/next-tick.function.js +23 -26
- package/dist/src/functions/omit.function.js +13 -13
- package/dist/src/functions/server-only-require.function.js +9 -10
- package/dist/src/functions/throttle.function.js +37 -35
- package/dist/src/functions/to-error.js +6 -5
- package/dist/src/functions/uuid.js +8 -9
- package/dist/src/types/api-version.js +3 -3
- package/dist/src/types/content.js +3 -3
- package/dist/src/types/element.js +3 -3
- package/dist/src/url.js +42 -41
- package/dist/src/url.test.js +118 -222
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -6
- package/dist/src/functions/get-top-level-domain.d.ts +0 -6
- package/dist/src/functions/get-top-level-domain.js +0 -17
- package/dist/src/functions/get-top-level-domain.js.map +0 -1
|
@@ -1,231 +1,208 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Animator = void 0;
|
|
4
|
-
var throttle_function_1 = require(
|
|
5
|
-
var assign_function_1 = require(
|
|
4
|
+
var throttle_function_1 = require("../functions/throttle.function");
|
|
5
|
+
var assign_function_1 = require("../functions/assign.function");
|
|
6
6
|
var camelCaseToKebabCase = function (str) {
|
|
7
|
-
|
|
8
|
-
? str.replace(/([A-Z])/g, function (g) {
|
|
9
|
-
return '-'.concat(g[0].toLowerCase());
|
|
10
|
-
})
|
|
11
|
-
: '';
|
|
7
|
+
return str ? str.replace(/([A-Z])/g, function (g) { return "-".concat(g[0].toLowerCase()); }) : '';
|
|
12
8
|
};
|
|
13
9
|
var Animator = /** @class */ (function () {
|
|
14
|
-
|
|
15
|
-
Animator.prototype.bindAnimations = function (animations) {
|
|
16
|
-
for (var _i = 0, animations_1 = animations; _i < animations_1.length; _i++) {
|
|
17
|
-
var animation = animations_1[_i];
|
|
18
|
-
switch (animation.trigger) {
|
|
19
|
-
case 'pageLoad':
|
|
20
|
-
this.triggerAnimation(animation);
|
|
21
|
-
break;
|
|
22
|
-
case 'hover':
|
|
23
|
-
this.bindHoverAnimation(animation);
|
|
24
|
-
break;
|
|
25
|
-
case 'scrollInView':
|
|
26
|
-
this.bindScrollInViewAnimation(animation);
|
|
27
|
-
break;
|
|
28
|
-
}
|
|
10
|
+
function Animator() {
|
|
29
11
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
for (var _i = 0, bothStyles_1 = bothStyles; _i < bothStyles_1.length; _i++) {
|
|
45
|
-
var styles = bothStyles_1[_i];
|
|
46
|
-
for (var _a = 0, stylesUsed_1 = stylesUsed; _a < stylesUsed_1.length; _a++) {
|
|
47
|
-
var style = stylesUsed_1[_a];
|
|
48
|
-
if (!(style in styles)) {
|
|
49
|
-
styles[style] = computedStyle[style];
|
|
12
|
+
Animator.prototype.bindAnimations = function (animations) {
|
|
13
|
+
for (var _i = 0, animations_1 = animations; _i < animations_1.length; _i++) {
|
|
14
|
+
var animation = animations_1[_i];
|
|
15
|
+
switch (animation.trigger) {
|
|
16
|
+
case 'pageLoad':
|
|
17
|
+
this.triggerAnimation(animation);
|
|
18
|
+
break;
|
|
19
|
+
case 'hover':
|
|
20
|
+
this.bindHoverAnimation(animation);
|
|
21
|
+
break;
|
|
22
|
+
case 'scrollInView':
|
|
23
|
+
this.bindScrollInViewAnimation(animation);
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
50
26
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if
|
|
60
|
-
|
|
27
|
+
};
|
|
28
|
+
Animator.prototype.warnElementNotPresent = function (id) {
|
|
29
|
+
console.warn("Cannot animate element: element with ID ".concat(id, " not found!"));
|
|
30
|
+
};
|
|
31
|
+
Animator.prototype.augmentAnimation = function (animation, element) {
|
|
32
|
+
var stylesUsed = this.getAllStylesUsed(animation);
|
|
33
|
+
var computedStyle = getComputedStyle(element);
|
|
34
|
+
// const computedStyle = getComputedStyle(element);
|
|
35
|
+
// // FIXME: this will break if original load is in one reponsive size then resize to another hmmm
|
|
36
|
+
// Need to use transform instead of left since left can change on screen sizes
|
|
37
|
+
var firstStyles = animation.steps[0].styles;
|
|
38
|
+
var lastStyles = animation.steps[animation.steps.length - 1].styles;
|
|
39
|
+
var bothStyles = [firstStyles, lastStyles];
|
|
40
|
+
// FIXME: this won't work as expected for augmented animations - may need the editor itself to manage this
|
|
41
|
+
for (var _i = 0, bothStyles_1 = bothStyles; _i < bothStyles_1.length; _i++) {
|
|
42
|
+
var styles = bothStyles_1[_i];
|
|
43
|
+
for (var _a = 0, stylesUsed_1 = stylesUsed; _a < stylesUsed_1.length; _a++) {
|
|
44
|
+
var style = stylesUsed_1[_a];
|
|
45
|
+
if (!(style in styles)) {
|
|
46
|
+
styles[style] = computedStyle[style];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
61
49
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (!elements.length) {
|
|
73
|
-
this.warnElementNotPresent(animation.elementId || animation.id || '');
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
Array.from(elements).forEach(function (element) {
|
|
77
|
-
_this.augmentAnimation(animation, element);
|
|
78
|
-
// TODO: do this properly, may have other animations of different properties
|
|
79
|
-
// TODO: only override the properties
|
|
80
|
-
// TODO: if there is an entrance and hover animation, the transition duration will get effed
|
|
81
|
-
// element.setAttribute('style', '');
|
|
82
|
-
// const styledUsed = this.getAllStylesUsed(animation);
|
|
83
|
-
element.style.transition = 'none';
|
|
84
|
-
element.style.transitionDelay = '0';
|
|
85
|
-
(0, assign_function_1.assign)(element.style, animation.steps[0].styles);
|
|
86
|
-
// TODO: queue/batch these timeouts
|
|
87
|
-
// TODO: only include properties explicitly set in the animation
|
|
88
|
-
// using Object.keys(styles)
|
|
89
|
-
setTimeout(function () {
|
|
90
|
-
element.style.transition = 'all '
|
|
91
|
-
.concat(animation.duration, 's ')
|
|
92
|
-
.concat(camelCaseToKebabCase(animation.easing));
|
|
93
|
-
if (animation.delay) {
|
|
94
|
-
element.style.transitionDelay = animation.delay + 's';
|
|
50
|
+
};
|
|
51
|
+
Animator.prototype.getAllStylesUsed = function (animation) {
|
|
52
|
+
var properties = [];
|
|
53
|
+
for (var _i = 0, _a = animation.steps; _i < _a.length; _i++) {
|
|
54
|
+
var step = _a[_i];
|
|
55
|
+
for (var key in step.styles) {
|
|
56
|
+
if (properties.indexOf(key) === -1) {
|
|
57
|
+
properties.push(key);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
95
60
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
(animation.delay || 0) * 1000 + animation.duration * 1000 + 100
|
|
106
|
-
);
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
};
|
|
110
|
-
Animator.prototype.bindHoverAnimation = function (animation) {
|
|
111
|
-
var _this = this;
|
|
112
|
-
// TODO: is it multiple binding when editing...?
|
|
113
|
-
// TODO: unbind on element remove
|
|
114
|
-
// TODO: apply to ALL elements
|
|
115
|
-
var elements = Array.prototype.slice.call(
|
|
116
|
-
document.getElementsByClassName(animation.elementId || animation.id || '')
|
|
117
|
-
);
|
|
118
|
-
if (!elements.length) {
|
|
119
|
-
this.warnElementNotPresent(animation.elementId || animation.id || '');
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
Array.from(elements).forEach(function (element) {
|
|
123
|
-
_this.augmentAnimation(animation, element);
|
|
124
|
-
var defaultState = animation.steps[0].styles;
|
|
125
|
-
var hoverState = animation.steps[1].styles;
|
|
126
|
-
function attachDefaultState() {
|
|
127
|
-
(0, assign_function_1.assign)(element.style, defaultState);
|
|
128
|
-
}
|
|
129
|
-
function attachHoverState() {
|
|
130
|
-
(0, assign_function_1.assign)(element.style, hoverState);
|
|
131
|
-
}
|
|
132
|
-
attachDefaultState();
|
|
133
|
-
element.addEventListener('mouseenter', attachHoverState);
|
|
134
|
-
element.addEventListener('mouseleave', attachDefaultState);
|
|
135
|
-
// TODO: queue/batch these timeouts
|
|
136
|
-
setTimeout(function () {
|
|
137
|
-
element.style.transition = 'all '
|
|
138
|
-
.concat(animation.duration, 's ')
|
|
139
|
-
.concat(camelCaseToKebabCase(animation.easing));
|
|
140
|
-
if (animation.delay) {
|
|
141
|
-
element.style.transitionDelay = animation.delay + 's';
|
|
61
|
+
return properties;
|
|
62
|
+
};
|
|
63
|
+
Animator.prototype.triggerAnimation = function (animation) {
|
|
64
|
+
var _this = this;
|
|
65
|
+
// TODO: do for ALL elements
|
|
66
|
+
var elements = Array.prototype.slice.call(document.getElementsByClassName(animation.elementId || animation.id || ''));
|
|
67
|
+
if (!elements.length) {
|
|
68
|
+
this.warnElementNotPresent(animation.elementId || animation.id || '');
|
|
69
|
+
return;
|
|
142
70
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
var triggered = false;
|
|
161
|
-
var pendingAnimation = false;
|
|
162
|
-
function immediateOnScroll() {
|
|
163
|
-
if (!triggered && isScrolledIntoView(element)) {
|
|
164
|
-
triggered = true;
|
|
165
|
-
pendingAnimation = true;
|
|
166
|
-
setTimeout(function () {
|
|
167
|
-
(0, assign_function_1.assign)(element.style, animation.steps[1].styles);
|
|
168
|
-
if (!animation.repeat) {
|
|
169
|
-
document.removeEventListener('scroll', onScroll);
|
|
170
|
-
}
|
|
171
|
-
setTimeout(
|
|
172
|
-
function () {
|
|
173
|
-
pendingAnimation = false;
|
|
174
|
-
if (!animation.repeat) {
|
|
175
|
-
element.style.transition = '';
|
|
176
|
-
element.style.transitionDelay = '';
|
|
71
|
+
Array.from(elements).forEach(function (element) {
|
|
72
|
+
_this.augmentAnimation(animation, element);
|
|
73
|
+
// TODO: do this properly, may have other animations of different properties
|
|
74
|
+
// TODO: only override the properties
|
|
75
|
+
// TODO: if there is an entrance and hover animation, the transition duration will get effed
|
|
76
|
+
// element.setAttribute('style', '');
|
|
77
|
+
// const styledUsed = this.getAllStylesUsed(animation);
|
|
78
|
+
element.style.transition = 'none';
|
|
79
|
+
element.style.transitionDelay = '0';
|
|
80
|
+
(0, assign_function_1.assign)(element.style, animation.steps[0].styles);
|
|
81
|
+
// TODO: queue/batch these timeouts
|
|
82
|
+
// TODO: only include properties explicitly set in the animation
|
|
83
|
+
// using Object.keys(styles)
|
|
84
|
+
setTimeout(function () {
|
|
85
|
+
element.style.transition = "all ".concat(animation.duration, "s ").concat(camelCaseToKebabCase(animation.easing));
|
|
86
|
+
if (animation.delay) {
|
|
87
|
+
element.style.transitionDelay = animation.delay + 's';
|
|
177
88
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
)
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
89
|
+
(0, assign_function_1.assign)(element.style, animation.steps[1].styles);
|
|
90
|
+
// TODO: maybe remove/reset transitoin property after animation duration
|
|
91
|
+
// TODO: queue timers
|
|
92
|
+
setTimeout(function () {
|
|
93
|
+
// TODO: what if has other transition (reset back to what it was)
|
|
94
|
+
element.style.transition = '';
|
|
95
|
+
element.style.transitionDelay = '';
|
|
96
|
+
}, (animation.delay || 0) * 1000 + animation.duration * 1000 + 100);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
Animator.prototype.bindHoverAnimation = function (animation) {
|
|
101
|
+
var _this = this;
|
|
102
|
+
// TODO: is it multiple binding when editing...?
|
|
103
|
+
// TODO: unbind on element remove
|
|
104
|
+
// TODO: apply to ALL elements
|
|
105
|
+
var elements = Array.prototype.slice.call(document.getElementsByClassName(animation.elementId || animation.id || ''));
|
|
106
|
+
if (!elements.length) {
|
|
107
|
+
this.warnElementNotPresent(animation.elementId || animation.id || '');
|
|
108
|
+
return;
|
|
191
109
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
110
|
+
Array.from(elements).forEach(function (element) {
|
|
111
|
+
_this.augmentAnimation(animation, element);
|
|
112
|
+
var defaultState = animation.steps[0].styles;
|
|
113
|
+
var hoverState = animation.steps[1].styles;
|
|
114
|
+
function attachDefaultState() {
|
|
115
|
+
(0, assign_function_1.assign)(element.style, defaultState);
|
|
116
|
+
}
|
|
117
|
+
function attachHoverState() {
|
|
118
|
+
(0, assign_function_1.assign)(element.style, hoverState);
|
|
119
|
+
}
|
|
120
|
+
attachDefaultState();
|
|
121
|
+
element.addEventListener('mouseenter', attachHoverState);
|
|
122
|
+
element.addEventListener('mouseleave', attachDefaultState);
|
|
123
|
+
// TODO: queue/batch these timeouts
|
|
124
|
+
setTimeout(function () {
|
|
125
|
+
element.style.transition = "all ".concat(animation.duration, "s ").concat(camelCaseToKebabCase(animation.easing));
|
|
126
|
+
if (animation.delay) {
|
|
127
|
+
element.style.transitionDelay = animation.delay + 's';
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
// TODO: unbind on element remove
|
|
133
|
+
Animator.prototype.bindScrollInViewAnimation = function (animation) {
|
|
134
|
+
var _this = this;
|
|
135
|
+
// TODO: apply to ALL matching elements
|
|
136
|
+
var elements = Array.prototype.slice.call(document.getElementsByClassName(animation.elementId || animation.id || ''));
|
|
137
|
+
if (!elements.length) {
|
|
138
|
+
this.warnElementNotPresent(animation.elementId || animation.id || '');
|
|
139
|
+
return;
|
|
220
140
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
141
|
+
// TODO: if server side rendered and scrolled into view don't animate...
|
|
142
|
+
Array.from(elements).forEach(function (element) {
|
|
143
|
+
_this.augmentAnimation(animation, element);
|
|
144
|
+
var triggered = false;
|
|
145
|
+
var pendingAnimation = false;
|
|
146
|
+
function immediateOnScroll() {
|
|
147
|
+
if (!triggered && isScrolledIntoView(element)) {
|
|
148
|
+
triggered = true;
|
|
149
|
+
pendingAnimation = true;
|
|
150
|
+
setTimeout(function () {
|
|
151
|
+
(0, assign_function_1.assign)(element.style, animation.steps[1].styles);
|
|
152
|
+
if (!animation.repeat) {
|
|
153
|
+
document.removeEventListener('scroll', onScroll);
|
|
154
|
+
}
|
|
155
|
+
setTimeout(function () {
|
|
156
|
+
pendingAnimation = false;
|
|
157
|
+
if (!animation.repeat) {
|
|
158
|
+
element.style.transition = '';
|
|
159
|
+
element.style.transitionDelay = '';
|
|
160
|
+
}
|
|
161
|
+
}, (animation.duration + (animation.delay || 0)) * 1000 + 100);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
else if (animation.repeat &&
|
|
165
|
+
triggered &&
|
|
166
|
+
!pendingAnimation &&
|
|
167
|
+
!isScrolledIntoView(element)) {
|
|
168
|
+
// we want to repeat the animation every time the the element is out of view and back again
|
|
169
|
+
triggered = false;
|
|
170
|
+
(0, assign_function_1.assign)(element.style, animation.steps[0].styles);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
// TODO: roll all of these in one for more efficiency of checking all the rects
|
|
174
|
+
var onScroll = (0, throttle_function_1.throttle)(immediateOnScroll, 200, { leading: false });
|
|
175
|
+
// TODO: fully in view or partially
|
|
176
|
+
function isScrolledIntoView(elem) {
|
|
177
|
+
var rect = elem.getBoundingClientRect();
|
|
178
|
+
var windowHeight = window.innerHeight;
|
|
179
|
+
var thresholdPercent = (animation.thresholdPercent || 0) / 100;
|
|
180
|
+
var threshold = thresholdPercent * windowHeight;
|
|
181
|
+
// TODO: partial in view? or what if element is larger than screen itself
|
|
182
|
+
return (rect.bottom > threshold && rect.top < windowHeight - threshold // Element is peeking top or bottom
|
|
183
|
+
// (rect.top > 0 && rect.bottom < window.innerHeight) || // element fits within the screen and is fully on screen (not hanging off at all)
|
|
184
|
+
// (rect.top < 0 && rect.bottom > window.innerHeight) // element is larger than the screen and hangs over the top and bottom
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
var defaultState = animation.steps[0].styles;
|
|
188
|
+
function attachDefaultState() {
|
|
189
|
+
(0, assign_function_1.assign)(element.style, defaultState);
|
|
190
|
+
}
|
|
191
|
+
attachDefaultState();
|
|
192
|
+
// TODO: queue/batch these timeouts!
|
|
193
|
+
setTimeout(function () {
|
|
194
|
+
element.style.transition = "all ".concat(animation.duration, "s ").concat(camelCaseToKebabCase(animation.easing));
|
|
195
|
+
if (animation.delay) {
|
|
196
|
+
element.style.transitionDelay = animation.delay + 's';
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
// TODO: one listener for everything
|
|
200
|
+
document.addEventListener('scroll', onScroll, { capture: true, passive: true });
|
|
201
|
+
// Do an initial check
|
|
202
|
+
immediateOnScroll();
|
|
203
|
+
});
|
|
204
|
+
};
|
|
205
|
+
return Animator;
|
|
206
|
+
}());
|
|
230
207
|
exports.Animator = Animator;
|
|
231
|
-
//# sourceMappingURL=animator.class.js.map
|
|
208
|
+
//# sourceMappingURL=animator.class.js.map
|
|
@@ -1,115 +1,110 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Observable = exports.Observer = exports.BehaviorSubject = exports.Subscription = void 0;
|
|
4
4
|
var Subscription = /** @class */ (function () {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
Object.defineProperty(Subscription.prototype, 'closed', {
|
|
12
|
-
get: function () {
|
|
13
|
-
return this.unsubscribed;
|
|
14
|
-
},
|
|
15
|
-
enumerable: false,
|
|
16
|
-
configurable: true,
|
|
17
|
-
});
|
|
18
|
-
Subscription.prototype.add = function (subscription) {
|
|
19
|
-
this.otherSubscriptions.push(subscription);
|
|
20
|
-
};
|
|
21
|
-
Subscription.prototype.unsubscribe = function () {
|
|
22
|
-
if (this.unsubscribed) {
|
|
23
|
-
return;
|
|
5
|
+
function Subscription(listeners, listener) {
|
|
6
|
+
this.listeners = listeners;
|
|
7
|
+
this.listener = listener;
|
|
8
|
+
this.unsubscribed = false;
|
|
9
|
+
this.otherSubscriptions = [];
|
|
24
10
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
this.otherSubscriptions.forEach(function (sub) {
|
|
32
|
-
return sub.unsubscribe();
|
|
11
|
+
Object.defineProperty(Subscription.prototype, "closed", {
|
|
12
|
+
get: function () {
|
|
13
|
+
return this.unsubscribed;
|
|
14
|
+
},
|
|
15
|
+
enumerable: false,
|
|
16
|
+
configurable: true
|
|
33
17
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
18
|
+
Subscription.prototype.add = function (subscription) {
|
|
19
|
+
this.otherSubscriptions.push(subscription);
|
|
20
|
+
};
|
|
21
|
+
Subscription.prototype.unsubscribe = function () {
|
|
22
|
+
if (this.unsubscribed) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (this.listener && this.listeners) {
|
|
26
|
+
var index = this.listeners.indexOf(this.listener);
|
|
27
|
+
if (index > -1) {
|
|
28
|
+
this.listeners.splice(index, 1);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
this.otherSubscriptions.forEach(function (sub) { return sub.unsubscribe(); });
|
|
32
|
+
this.unsubscribed = true;
|
|
33
|
+
};
|
|
34
|
+
return Subscription;
|
|
35
|
+
}());
|
|
38
36
|
exports.Subscription = Subscription;
|
|
39
37
|
// TODO: follow minimal basic spec: https://github.com/tc39/proposal-observable
|
|
40
38
|
var BehaviorSubject = /** @class */ (function () {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
BehaviorSubject.prototype.next = function (value) {
|
|
56
|
-
this.value = value;
|
|
57
|
-
for (var _i = 0, _a = this.listeners; _i < _a.length; _i++) {
|
|
58
|
-
var listener = _a[_i];
|
|
59
|
-
listener(value);
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
// TODO: implement this as PIPE instead
|
|
63
|
-
BehaviorSubject.prototype.map = function (fn) {
|
|
64
|
-
var newSubject = new BehaviorSubject(fn(this.value));
|
|
65
|
-
// TODO: on destroy delete these
|
|
66
|
-
this.subscribe(function (val) {
|
|
67
|
-
newSubject.next(fn(val));
|
|
68
|
-
});
|
|
69
|
-
this.catch(function (err) {
|
|
70
|
-
newSubject.error(err);
|
|
71
|
-
});
|
|
72
|
-
return newSubject;
|
|
73
|
-
};
|
|
74
|
-
BehaviorSubject.prototype.catch = function (errorListener) {
|
|
75
|
-
this.errorListeners.push(errorListener);
|
|
76
|
-
return new Subscription(this.errorListeners, errorListener);
|
|
77
|
-
};
|
|
78
|
-
BehaviorSubject.prototype.error = function (error) {
|
|
79
|
-
for (var _i = 0, _a = this.errorListeners; _i < _a.length; _i++) {
|
|
80
|
-
var listener = _a[_i];
|
|
81
|
-
listener(error);
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
BehaviorSubject.prototype.subscribe = function (listener, errorListener) {
|
|
85
|
-
this.listeners.push(listener);
|
|
86
|
-
if (errorListener) {
|
|
87
|
-
this.errorListeners.push(errorListener);
|
|
39
|
+
function BehaviorSubject(value) {
|
|
40
|
+
var _this = this;
|
|
41
|
+
this.value = value;
|
|
42
|
+
this.listeners = [];
|
|
43
|
+
this.errorListeners = [];
|
|
44
|
+
this.then = function () {
|
|
45
|
+
var _a;
|
|
46
|
+
var args = [];
|
|
47
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
48
|
+
args[_i] = arguments[_i];
|
|
49
|
+
}
|
|
50
|
+
return (_a = _this.toPromise()).then.apply(_a, args);
|
|
51
|
+
};
|
|
88
52
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
var subscription = _this.subscribe(
|
|
95
|
-
function (value) {
|
|
96
|
-
resolve(value);
|
|
97
|
-
subscription.unsubscribe();
|
|
98
|
-
},
|
|
99
|
-
function (err) {
|
|
100
|
-
reject(err);
|
|
101
|
-
subscription.unsubscribe();
|
|
53
|
+
BehaviorSubject.prototype.next = function (value) {
|
|
54
|
+
this.value = value;
|
|
55
|
+
for (var _i = 0, _a = this.listeners; _i < _a.length; _i++) {
|
|
56
|
+
var listener = _a[_i];
|
|
57
|
+
listener(value);
|
|
102
58
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
})
|
|
59
|
+
};
|
|
60
|
+
// TODO: implement this as PIPE instead
|
|
61
|
+
BehaviorSubject.prototype.map = function (fn) {
|
|
62
|
+
var newSubject = new BehaviorSubject(fn(this.value));
|
|
63
|
+
// TODO: on destroy delete these
|
|
64
|
+
this.subscribe(function (val) {
|
|
65
|
+
newSubject.next(fn(val));
|
|
66
|
+
});
|
|
67
|
+
this.catch(function (err) {
|
|
68
|
+
newSubject.error(err);
|
|
69
|
+
});
|
|
70
|
+
return newSubject;
|
|
71
|
+
};
|
|
72
|
+
BehaviorSubject.prototype.catch = function (errorListener) {
|
|
73
|
+
this.errorListeners.push(errorListener);
|
|
74
|
+
return new Subscription(this.errorListeners, errorListener);
|
|
75
|
+
};
|
|
76
|
+
BehaviorSubject.prototype.error = function (error) {
|
|
77
|
+
for (var _i = 0, _a = this.errorListeners; _i < _a.length; _i++) {
|
|
78
|
+
var listener = _a[_i];
|
|
79
|
+
listener(error);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
BehaviorSubject.prototype.subscribe = function (listener, errorListener) {
|
|
83
|
+
this.listeners.push(listener);
|
|
84
|
+
if (errorListener) {
|
|
85
|
+
this.errorListeners.push(errorListener);
|
|
86
|
+
}
|
|
87
|
+
return new Subscription(this.listeners, listener);
|
|
88
|
+
};
|
|
89
|
+
BehaviorSubject.prototype.toPromise = function () {
|
|
90
|
+
var _this = this;
|
|
91
|
+
return new Promise(function (resolve, reject) {
|
|
92
|
+
var subscription = _this.subscribe(function (value) {
|
|
93
|
+
resolve(value);
|
|
94
|
+
subscription.unsubscribe();
|
|
95
|
+
}, function (err) {
|
|
96
|
+
reject(err);
|
|
97
|
+
subscription.unsubscribe();
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
BehaviorSubject.prototype.promise = function () {
|
|
102
|
+
return this.toPromise();
|
|
103
|
+
};
|
|
104
|
+
return BehaviorSubject;
|
|
105
|
+
}());
|
|
111
106
|
exports.BehaviorSubject = BehaviorSubject;
|
|
112
107
|
// TODO: make different classes
|
|
113
108
|
exports.Observer = BehaviorSubject;
|
|
114
109
|
exports.Observable = BehaviorSubject;
|
|
115
|
-
//# sourceMappingURL=observable.class.js.map
|
|
110
|
+
//# sourceMappingURL=observable.class.js.map
|