mirror of
https://github.com/robonen/tools.git
synced 2026-03-20 02:44:45 +00:00
feat(packages/vue): add useAppSharedState composable
This commit is contained in:
@@ -3,7 +3,7 @@ import { ref, reactive } from 'vue';
|
||||
import { useAppSharedState } from '.';
|
||||
|
||||
describe('useAppSharedState', () => {
|
||||
it('should initialize state only once', () => {
|
||||
it('initialize state only once', () => {
|
||||
const stateFactory = (initValue?: number) => {
|
||||
const count = ref(initValue ?? 0);
|
||||
return { count };
|
||||
@@ -19,7 +19,7 @@ describe('useAppSharedState', () => {
|
||||
expect(state1).toBe(state2);
|
||||
});
|
||||
|
||||
it('should return the same state object across different calls', () => {
|
||||
it('return the same state object across different calls', () => {
|
||||
const stateFactory = () => {
|
||||
const state = reactive({ count: 0 });
|
||||
const increment = () => state.count++;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { AnyFunction } from '@robonen/stdlib';
|
||||
import { effectScope, onScopeDispose } from 'vue';
|
||||
import { effectScope } from 'vue';
|
||||
|
||||
// TODO: maybe we should control subscriptions and dispose them when the child scope is disposed
|
||||
|
||||
@@ -8,8 +8,8 @@ import { effectScope, onScopeDispose } from 'vue';
|
||||
* @category State
|
||||
* @description Provides a shared state object for use across Vue instances
|
||||
*
|
||||
* @param {Function} stateFactory The factory function to create the shared state
|
||||
* @returns {Function} The shared state object
|
||||
* @param {Function} stateFactory A factory function that returns the shared state object
|
||||
* @returns {Function} A function that returns the shared state object
|
||||
*
|
||||
* @example
|
||||
* const useSharedState = useAppSharedState((initValue?: number) => {
|
||||
|
||||
Reference in New Issue
Block a user