refactor(menu): added component. Solve the menu stuck problem

This commit is contained in:
vben
2021-01-17 22:36:06 +08:00
parent 056fc13116
commit ff2b12b409
43 changed files with 1794 additions and 214 deletions

View File

@@ -28,7 +28,7 @@ export default class Mitt {
* @param {Function} handler Function to call in response to given event
*/
on(type: string | Symbol, handler: Fn) {
const handlers = this.cache.get(type);
const handlers = this.cache?.get(type);
const added = handlers && handlers.push(handler);
if (!added) {
this.cache.set(type, [handler]);
@@ -57,7 +57,7 @@ export default class Mitt {
* @param {string|symbol} type The event type to invoke
* @param {*} [evt] Any value (object is recommended and powerful), passed to each handler
*/
emit(type: string | Symbol, evt: any) {
emit(type: string | Symbol, evt?: any) {
for (const handler of (this.cache.get(type) || []).slice()) handler(evt);
for (const handler of (this.cache.get('*') || []).slice()) handler(type, evt);
}