@alitajs/layout
Version:
12 lines (9 loc) • 2.06 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _default = function _default() {
return "\n\nimport { NavBarListItem } from '@alitajs/alita-layout';\n\nlet pageNavBar = {};\nlet tabBarList = {};\n\ntype Subscription<T> = (val: T) => void;\n\nclass EventEmitter<T> {\n private subscriptions = new Set<Subscription<T>>();\n\n emit = (val: T) => {\n for (const subscription of this.subscriptions) {\n subscription(val);\n }\n };\n\n useSubscription = (callback: Subscription<T>) => {\n function subscription(val: T) {\n if (callback) {\n callback(val);\n }\n }\n this.subscriptions.add(subscription);\n };\n}\nconst layoutEmitter = new EventEmitter();\n\nconst setPageNavBar = (value: NavBarListItem) => {\n if (!value.pagePath || !value.navBar) {\n console.error('setPageNavBar: value.pagePath can not be undefined')\n return;\n }\n pageNavBar = { ...pageNavBar, [value.pagePath]: value.navBar }\n layoutEmitter.emit('');\n}\nconst getPageNavBar = () => pageNavBar;\n\ninterface TabBarListItem {\n pagePath: string;\n text?: string;\n iconSize?: string;\n badge?: string;\n iconPath?: string;\n selectedIconPath?: string;\n onPress?: () => {};\n title?: string;\n remove?: boolean;\n replace?: string;\n}\n\nconst checkPagePath = (pagePath: string | undefined) => {\n if(!pagePath) {\n console.error('setTabBarList: value.pagePath can not be undefined');\n return false;\n } else return true;\n\n}\n\nconst setTabBarList = (value: TabBarListItem | TabBarListItem[]): void => {\n if(Array.isArray(value)){\n value.forEach((item: TabBarListItem) => {\n tabBarList[item.pagePath] = item;\n });\n } else {\n if (!checkPagePath(value.pagePath)) return;\n tabBarList = { ...tabBarList, [value.pagePath]: value };\n }\n layoutEmitter.emit('');\n}\n\nconst getTabBarList = () => tabBarList;\n\nexport {\n getPageNavBar, setPageNavBar, setTabBarList, getTabBarList, layoutEmitter\n}\n";
};
exports.default = _default;