code: function saveStateToLocalStorage(delay) {
      let timeId = null;
  
      // 同步存储
      if (delay < 1) {
          return function save(key, data) {
              try {
                  localStorage.setItem(key, JSON.stringify(data));
              } catch (error) {
                  // do nothing;
              }
          };
      }
  
      // 返回保存函数
      return function save(key, data) {
          timeId && clearTimeout(timeId);
          timeId = setTimeout(() => {
              try {
                  localStorage.setItem(key, JSON.stringify(data));
              } catch (error) {
                  // do nothing;
              } finally {
                  timeId = null;
              }
          }, delay);
      };
  }
docs: ****************************************
  保存状态
  ****************************************