1 |
|
2 |
|
3 |
|
4 | import {
|
5 | isFun,
|
6 | isObj,
|
7 | isStr,
|
8 | isArray
|
9 | } from 'LIB/util';
|
10 |
|
11 | let stack = [];
|
12 |
|
13 | export default stack;
|
14 |
|
15 | export const pushStack = function (
|
16 | key: object
|
17 | ) {
|
18 | let has = false;
|
19 | for (let i = 0; i < stack.length; i++) {
|
20 | if (stack[i].name === key.name) {
|
21 | stack[i] = key;
|
22 | has = true;
|
23 | }
|
24 | }
|
25 |
|
26 | if (!has) stack.push(key);
|
27 | };
|
28 |
|
29 | export const updateStack = function (
|
30 | key: object | Array,
|
31 | name: string
|
32 | ) {
|
33 | try {
|
34 | for (let i = 0; i < stack.length; i++) {
|
35 | if (stack[i].name === name) {
|
36 | stack[i].value = key;
|
37 | }
|
38 | }
|
39 | } catch (e) {
|
40 | console.log(e);
|
41 | }
|
42 | };
|
43 |
|
44 | export const removeStack = function (
|
45 | name: string
|
46 | ) {
|
47 | for (let i = 0; i < stack.length;) {
|
48 | if (stack[i].name === name) {
|
49 | stack.splice(i, 1);
|
50 | } else {
|
51 | i++;
|
52 | }
|
53 | }
|
54 | };
|
55 |
|
56 | export const cleanStack = function () {
|
57 | stack = [];
|
58 | };
|