// prefix 一般是这个子应用的代号，或者其他

export const localstorageExtendRegister = (prefix = '') => {
  const originSetItem = window.localStorage.setItem;
  const originGetItem = window.localStorage.getItem;
  window.localStorage.setItem = function (key, value) {
    originSetItem.apply(this, [`${prefix}__${key}`, value]);
  };
  window.localStorage.getItem = function (key: string) {
    return originGetItem.apply(this, [`${prefix}__${key}`]);
  };
};
export const sessionStorageExtendRegister = (prefix = '') => {
  const originSetItem = window.sessionStorage.setItem;
  const originGetItem = window.sessionStorage.getItem;
  window.sessionStorage.setItem = function (key: string, value: string) {
    originSetItem.apply(this, [`${prefix}__${key}`, value]);
  };
  window.sessionStorage.getItem = function (key: string) {
    return originGetItem.apply(this, [`${prefix}__${key}`]);
  };
};
// 需要传入 js-cookie 对象
export const jsCookieExtendRegister = (prefix = '', jsCookie: any) => {
  const originSet = jsCookie.set;
  const originGet = jsCookie.get;
  jsCookie.set = function (name: string, value: string, options?: any) {
    originSet.apply(this, [`${prefix}__${name}`, value, options]);
  };
  // jsCookie get 有一个重载，这里也要实现
  jsCookie.get = function (name?: string) {
    return originGet.apply(this, name ? [`${prefix}__${name}`] : []);
  };
};
