export type UpdateCenter = ReturnType<typeof useUpdateCenter>;

export function useUpdateCenter() {
  const eventCenter = new Map<string, Fn>();

  const update = () => {
    eventCenter.forEach((method) => {
      method();
    });
  };

  const add = (key: string, method: Fn) => {
    if (eventCenter.has(key)) {
      window.console.log(`Update Center Has Exist This Update Method(${key})`);
      return;
    }
    eventCenter.set(key, method);
  };

  const remove = (key: string) => {
    if (eventCenter.has(key)) eventCenter.delete(key);
  };

  return { update, add, remove };
}
