@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.
Files changed (40) hide show
  1. package/.yarnrc.yml +1 -0
  2. package/CHANGELOG.md +6 -0
  3. package/dist/index.browser.js +13 -5
  4. package/dist/index.browser.js.map +1 -1
  5. package/dist/index.cjs.js +13 -5
  6. package/dist/index.cjs.js.map +1 -1
  7. package/dist/index.esm.js +13 -5
  8. package/dist/index.esm.js.map +1 -1
  9. package/dist/index.js +13 -49
  10. package/dist/index.umd.js +13 -5
  11. package/dist/index.umd.js.map +1 -1
  12. package/dist/package.json +3 -3
  13. package/dist/src/builder.class.js +12 -4
  14. package/dist/src/builder.class.js.map +1 -1
  15. package/dist/src/builder.class.test.js +153 -171
  16. package/dist/src/classes/animator.class.js +195 -218
  17. package/dist/src/classes/observable.class.js +97 -102
  18. package/dist/src/classes/promise.class.js +154 -150
  19. package/dist/src/classes/query-string.class.js +74 -73
  20. package/dist/src/classes/query-string.class.test.js +20 -20
  21. package/dist/src/constants/builder.js +4 -4
  22. package/dist/src/functions/assign.function.js +19 -19
  23. package/dist/src/functions/fetch.function.js +75 -97
  24. package/dist/src/functions/finder.function.js +274 -389
  25. package/dist/src/functions/next-tick.function.js +23 -26
  26. package/dist/src/functions/omit.function.js +13 -13
  27. package/dist/src/functions/server-only-require.function.js +9 -10
  28. package/dist/src/functions/throttle.function.js +37 -35
  29. package/dist/src/functions/to-error.js +6 -5
  30. package/dist/src/functions/uuid.js +8 -9
  31. package/dist/src/types/api-version.js +3 -3
  32. package/dist/src/types/content.js +3 -3
  33. package/dist/src/types/element.js +3 -3
  34. package/dist/src/url.js +42 -41
  35. package/dist/src/url.test.js +118 -222
  36. package/dist/tsconfig.tsbuildinfo +1 -1
  37. package/package.json +5 -6
  38. package/dist/src/functions/get-top-level-domain.d.ts +0 -6
  39. package/dist/src/functions/get-top-level-domain.js +0 -17
  40. package/dist/src/functions/get-top-level-domain.js.map +0 -1
@@ -1,231 +1,208 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Animator = void 0;
4
- var throttle_function_1 = require('../functions/throttle.function');
5
- var assign_function_1 = require('../functions/assign.function');
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
- return str
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
- function Animator() {}
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
- Animator.prototype.warnElementNotPresent = function (id) {
32
- console.warn('Cannot animate element: element with ID '.concat(id, ' not found!'));
33
- };
34
- Animator.prototype.augmentAnimation = function (animation, element) {
35
- var stylesUsed = this.getAllStylesUsed(animation);
36
- var computedStyle = getComputedStyle(element);
37
- // const computedStyle = getComputedStyle(element);
38
- // // FIXME: this will break if original load is in one reponsive size then resize to another hmmm
39
- // Need to use transform instead of left since left can change on screen sizes
40
- var firstStyles = animation.steps[0].styles;
41
- var lastStyles = animation.steps[animation.steps.length - 1].styles;
42
- var bothStyles = [firstStyles, lastStyles];
43
- // FIXME: this won't work as expected for augmented animations - may need the editor itself to manage this
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
- Animator.prototype.getAllStylesUsed = function (animation) {
55
- var properties = [];
56
- for (var _i = 0, _a = animation.steps; _i < _a.length; _i++) {
57
- var step = _a[_i];
58
- for (var key in step.styles) {
59
- if (properties.indexOf(key) === -1) {
60
- properties.push(key);
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
- return properties;
65
- };
66
- Animator.prototype.triggerAnimation = function (animation) {
67
- var _this = this;
68
- // TODO: do for ALL elements
69
- var elements = Array.prototype.slice.call(
70
- document.getElementsByClassName(animation.elementId || animation.id || '')
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
- (0, assign_function_1.assign)(element.style, animation.steps[1].styles);
97
- // TODO: maybe remove/reset transitoin property after animation duration
98
- // TODO: queue timers
99
- setTimeout(
100
- function () {
101
- // TODO: what if has other transition (reset back to what it was)
102
- element.style.transition = '';
103
- element.style.transitionDelay = '';
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
- // TODO: unbind on element remove
147
- Animator.prototype.bindScrollInViewAnimation = function (animation) {
148
- var _this = this;
149
- // TODO: apply to ALL matching elements
150
- var elements = Array.prototype.slice.call(
151
- document.getElementsByClassName(animation.elementId || animation.id || '')
152
- );
153
- if (!elements.length) {
154
- this.warnElementNotPresent(animation.elementId || animation.id || '');
155
- return;
156
- }
157
- // TODO: if server side rendered and scrolled into view don't animate...
158
- Array.from(elements).forEach(function (element) {
159
- _this.augmentAnimation(animation, element);
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
- (animation.duration + (animation.delay || 0)) * 1000 + 100
180
- );
181
- });
182
- } else if (
183
- animation.repeat &&
184
- triggered &&
185
- !pendingAnimation &&
186
- !isScrolledIntoView(element)
187
- ) {
188
- // we want to repeat the animation every time the the element is out of view and back again
189
- triggered = false;
190
- (0, assign_function_1.assign)(element.style, animation.steps[0].styles);
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
- // TODO: roll all of these in one for more efficiency of checking all the rects
194
- var onScroll = (0, throttle_function_1.throttle)(immediateOnScroll, 200, { leading: false });
195
- // TODO: fully in view or partially
196
- function isScrolledIntoView(elem) {
197
- var rect = elem.getBoundingClientRect();
198
- var windowHeight = window.innerHeight;
199
- var thresholdPercent = (animation.thresholdPercent || 0) / 100;
200
- var threshold = thresholdPercent * windowHeight;
201
- // TODO: partial in view? or what if element is larger than screen itself
202
- return (
203
- rect.bottom > threshold && rect.top < windowHeight - threshold // Element is peeking top or bottom
204
- // (rect.top > 0 && rect.bottom < window.innerHeight) || // element fits within the screen and is fully on screen (not hanging off at all)
205
- // (rect.top < 0 && rect.bottom > window.innerHeight) // element is larger than the screen and hangs over the top and bottom
206
- );
207
- }
208
- var defaultState = animation.steps[0].styles;
209
- function attachDefaultState() {
210
- (0, assign_function_1.assign)(element.style, defaultState);
211
- }
212
- attachDefaultState();
213
- // TODO: queue/batch these timeouts!
214
- setTimeout(function () {
215
- element.style.transition = 'all '
216
- .concat(animation.duration, 's ')
217
- .concat(camelCaseToKebabCase(animation.easing));
218
- if (animation.delay) {
219
- element.style.transitionDelay = animation.delay + 's';
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
- // TODO: one listener for everything
223
- document.addEventListener('scroll', onScroll, { capture: true, passive: true });
224
- // Do an initial check
225
- immediateOnScroll();
226
- });
227
- };
228
- return Animator;
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
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
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
- function Subscription(listeners, listener) {
6
- this.listeners = listeners;
7
- this.listener = listener;
8
- this.unsubscribed = false;
9
- this.otherSubscriptions = [];
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
- 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) {
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
- this.unsubscribed = true;
35
- };
36
- return Subscription;
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
- function BehaviorSubject(value) {
42
- var _this = this;
43
- this.value = value;
44
- this.listeners = [];
45
- this.errorListeners = [];
46
- this.then = function () {
47
- var _a;
48
- var args = [];
49
- for (var _i = 0; _i < arguments.length; _i++) {
50
- args[_i] = arguments[_i];
51
- }
52
- return (_a = _this.toPromise()).then.apply(_a, args);
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
- return new Subscription(this.listeners, listener);
90
- };
91
- BehaviorSubject.prototype.toPromise = function () {
92
- var _this = this;
93
- return new Promise(function (resolve, reject) {
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
- BehaviorSubject.prototype.promise = function () {
107
- return this.toPromise();
108
- };
109
- return BehaviorSubject;
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