reecho
Version:
Reecho 是一款基于依赖收集的MVVM框架,它具有以下特点 - 声明式数据: 基于proxy的依赖收集 - 使用函数定义组件,但组件不会如React一样重复执行造成心智负担 - 读写分离,读取状态和更改状态统一使用函数,避免vue3的ref一样有时需要`xxx.value`有时不需要的不一致性 - 使用TS编写,类型友好
43 lines (33 loc) • 797 B
text/typescript
import { Ref, ref } from "../reactivity/index";
/**
* Generic state of a Store
*/
export type StateTree = Record<string | number | symbol, any>;
export type _Method = (...args: any[]) => any;
export type _ActionsTree = Record<string, _Method>;
export type _GettersTree = Record<string, () => any>;
export interface StoreGeneric {
state: StateTree;
actions: _ActionsTree;
getters: _GettersTree;
}
export interface Store {
/**
* root state
*/
state: Ref<Record<string, StateTree>>;
/**
* Registry of stores used by this pinia.
*
* @internal
*/
store: Map<string, any>;
}
export function createRootStore(): Store {
return {
state: ref({}),
store: new Map(),
};
}
export const root = createRootStore();
export let activePinia: Store | undefined;