docs: function clearStore(_options) {
      const store = this;
      const state = store.state;
      entityRecords = {}, entityRefs = {}, weakParts = [];
      entityNames.forEach((name) => {
        entityRefs[name] = {};
        entityRecords[name] = state[_entityName2StoreKey[name]];
      });
  
      options = _options && typeof _options === 'object' ? _options : {};
      if (typeof options.truncate === 'number' && options.truncate >= 0) options.truncate = ~~options.truncate;
      else options.truncate = -1;
  
      if (beforeClear && typeof beforeClear === 'function') {
        const customRefs = beforeClear.call(store, state);
        if (customRefs && customRefs.length > 0) {
          customRefs.forEach((ref) => {
            const refs = entityRefs[ref.entity];
            if (!refs) return;
            refs[ref.id] = true;
          });
        }
      }
  
      // first run: calc non-weak and non-chain position
      _calcRef(state, structure);
  
      // second run: calc weak parts
      weakParts.forEach((part) => {
        let refs = entityRefs[part.entity],
          partState = part.state,
          partStruct = part.structure;
        Object.keys(part.state).forEach((id) => {
          if (!refs[id]) return;
          _calcRefForValue(partState[id], partStruct);
        });
      });
  
      // last run: calc ref in entity structure(for the chain ref)
      entityNameLastRefCount = {};
      Object.keys(_entityNameChain).forEach((entityName) => {
        _calcEntityOwnStructure(entityName);
      });
  
      // remove entities which not referenced
      const newState = Object.assign({}, state);
      entityNames.forEach((entityName) => {
        const storeKey = _entityName2StoreKey[entityName];
        let entities = newState[storeKey],
          refs = entityRefs[entityName];
        Object.keys(entities).forEach((id) => {
          if (!refs[id]) delete entities[id];
        });
      });
  
      options = null, entityRecords = null, entityRefs = null, weakParts = null, entityNameLastRefCount = null;
      store.setState(newState);
    }