UNPKG

1.01 kBJavaScriptView Raw
1/**
2 * @description 存储公共内容
3 */
4import {
5 isFun,
6 isObj,
7 isStr,
8 isArray
9} from 'LIB/util';
10
11let stack = [];
12
13export default stack;
14
15export 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
29export 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
44export 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
56export const cleanStack = function () {
57 stack = [];
58};