Skip to content

Commit abe348b

Browse files
committed
build
1 parent 4e6ffee commit abe348b

File tree

1 file changed

+115
-76
lines changed

1 file changed

+115
-76
lines changed

dist/util/LoopController.js

Lines changed: 115 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -3,93 +3,132 @@
33
Object.defineProperty(exports, "__esModule", {
44
value: true
55
});
6-
exports.default = void 0;
6+
exports.createLoopController = createLoopController;
7+
exports.default = exports.LoopController = void 0;
8+
9+
function LoopControllerClass() {
10+
var _this = this;
11+
12+
/**
13+
* @typedef {Object} Scrollbar
14+
* @property {function} update
15+
*/
16+
17+
/**
18+
* @type {Scrollbar[]}
19+
*/
20+
var scrollbarsRegister = [];
21+
/**
22+
* true if loop is active
23+
* @type {boolean}
24+
*/
25+
26+
var isActive = false;
27+
/**
28+
* ID of requested animation frame
29+
* @type {null|number}
30+
*/
31+
32+
var animationFrameId = null;
33+
/**
34+
* Function that called in animation frame
35+
*/
36+
37+
var animationFrameCallback = function animationFrameCallback() {
38+
if (!isActive) {
39+
return;
40+
}
741

8-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
42+
for (var _i = 0; _i < scrollbarsRegister.length; _i++) {
43+
var scrollbar = scrollbarsRegister[_i];
44+
scrollbar.update();
45+
}
946

10-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
47+
requestAnimationFrame(animationFrameCallback);
48+
};
49+
/**
50+
* Stop the loop if it wasn't active
51+
* @return {LoopControllerClass}
52+
*/
1153

12-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
1354

14-
var loopIsActive = false;
15-
var animationFrame = null;
16-
var loopRegister = [];
55+
this.start = function () {
56+
if (isActive) {
57+
return _this;
58+
}
1759

18-
var LoopController =
19-
/*#__PURE__*/
20-
function () {
21-
function LoopController() {
22-
_classCallCheck(this, LoopController);
60+
isActive = true;
61+
animationFrameId && cancelAnimationFrame(animationFrameId);
62+
requestAnimationFrame(animationFrameCallback);
63+
};
64+
/**
65+
* Stop the loop if it is active
66+
* @return {LoopControllerClass}
67+
*/
2368

24-
this.rafStep = this.rafStep.bind(this);
25-
}
2669

27-
_createClass(LoopController, [{
28-
key: "getRegisteredItems",
29-
value: function getRegisteredItems() {
30-
return loopRegister.concat();
31-
}
32-
}, {
33-
key: "registerScrollbar",
34-
value: function registerScrollbar(scrollbar) {
35-
if (!loopRegister.includes(scrollbar)) {
36-
loopRegister.push(scrollbar);
37-
this.start();
38-
}
39-
40-
return this;
70+
this.stop = function () {
71+
if (!isActive) {
72+
return _this;
4173
}
42-
}, {
43-
key: "unregisterScrollbar",
44-
value: function unregisterScrollbar(scrollbar) {
45-
var index = loopRegister.indexOf(scrollbar);
4674

47-
if (index !== -1) {
48-
loopRegister.length === 1 && this.stop();
49-
loopRegister.splice(index, 1);
50-
}
75+
isActive = false;
76+
animationFrameId && cancelAnimationFrame(animationFrameId);
77+
animationFrameId = null;
78+
};
79+
/**
80+
* Return the array pf registered scrollbars
81+
* @return {Scrollbar[]}
82+
*/
5183

52-
return this;
53-
}
54-
}, {
55-
key: "start",
56-
value: function start() {
57-
if (!loopIsActive) {
58-
loopIsActive = true;
59-
animationFrame && cancelAnimationFrame(animationFrame);
60-
animationFrame = requestAnimationFrame(this.rafStep);
61-
}
62-
63-
return this;
64-
}
65-
}, {
66-
key: "rafStep",
67-
value: function rafStep() {
68-
if (!loopIsActive) {
69-
return;
70-
}
71-
72-
for (var i = 0; i < loopRegister.length; i++) {
73-
loopRegister[i].update();
74-
}
75-
76-
animationFrame = requestAnimationFrame(this.rafStep);
84+
85+
this.getRegisteredScrollbars = function () {
86+
return scrollbarsRegister.concat();
87+
};
88+
/**
89+
* Add the scrollbar to list to iterate each loop
90+
* @param {Scrollbar} scrollbar
91+
* @return {LoopControllerClass}
92+
*/
93+
94+
95+
this.registerScrollbar = function (scrollbar) {
96+
if (scrollbarsRegister.indexOf(scrollbar) === -1) {
97+
scrollbarsRegister.push(scrollbar);
98+
99+
_this.start();
77100
}
78-
}, {
79-
key: "stop",
80-
value: function stop() {
81-
if (loopIsActive) {
82-
loopIsActive = false;
83-
animationFrame && cancelAnimationFrame(animationFrame);
84-
}
85-
86-
return this;
101+
102+
return _this;
103+
};
104+
/**
105+
* Remove the scrollbar from list to iterate each loop
106+
* @param {Scrollbar} scrollbar
107+
* @return {LoopControllerClass}
108+
*/
109+
110+
111+
this.unregisterScrollbar = function (scrollbar) {
112+
var index = scrollbarsRegister.indexOf(scrollbar);
113+
114+
if (index !== -1) {
115+
scrollbarsRegister.splice(index, 1);
87116
}
88-
}]);
89117

90-
return LoopController;
91-
}();
118+
return _this;
119+
};
120+
}
121+
122+
var LoopController = new LoopControllerClass();
123+
exports.LoopController = LoopController;
124+
var _default = LoopController;
125+
/**
126+
* Return new instance of LoopControllerClass
127+
* @return {LoopControllerClass}
128+
*/
129+
130+
exports.default = _default;
92131

93-
var instance = new LoopController();
94-
var _default = instance;
95-
exports.default = _default;
132+
function createLoopController() {
133+
return new LoopControllerClass();
134+
}

0 commit comments

Comments
 (0)