main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
864 bytes
|
Line | |
---|
1 | import { __spreadArrays } from "tslib";
|
---|
2 | import { useState } from 'react';
|
---|
3 | var useQueue = function (initialValue) {
|
---|
4 | if (initialValue === void 0) { initialValue = []; }
|
---|
5 | var _a = useState(initialValue), state = _a[0], set = _a[1];
|
---|
6 | return {
|
---|
7 | add: function (value) {
|
---|
8 | set(function (queue) { return __spreadArrays(queue, [value]); });
|
---|
9 | },
|
---|
10 | remove: function () {
|
---|
11 | var result;
|
---|
12 | set(function (_a) {
|
---|
13 | var first = _a[0], rest = _a.slice(1);
|
---|
14 | result = first;
|
---|
15 | return rest;
|
---|
16 | });
|
---|
17 | return result;
|
---|
18 | },
|
---|
19 | get first() {
|
---|
20 | return state[0];
|
---|
21 | },
|
---|
22 | get last() {
|
---|
23 | return state[state.length - 1];
|
---|
24 | },
|
---|
25 | get size() {
|
---|
26 | return state.length;
|
---|
27 | },
|
---|
28 | };
|
---|
29 | };
|
---|
30 | export default useQueue;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.