@_lan/web-libs
Version:
<div align="center"> <img src="./public/favicon.svg" width="160" /> <h1>SoybeanAdmin AntDesign</h1> <span>中文 | <a href="./README.en_US.md">English</a></span> </div>
23 lines (18 loc) • 589 B
text/typescript
import type { PiniaPluginContext } from 'pinia';
import { jsonClone } from '@sa/utils';
import { SetupStoreId } from '@/enum';
/**
* The plugin reset the state of the store which is written by setup syntax
*
* @param context
*/
export function resetSetupStore(context: PiniaPluginContext) {
const setupSyntaxIds = Object.values(SetupStoreId) as string[];
if (setupSyntaxIds.includes(context.store.$id)) {
const { $state } = context.store;
const defaultStore = jsonClone($state);
context.store.$reset = () => {
context.store.$patch(defaultStore);
};
}
}