1
0
mirror of https://github.com/robonen/tools.git synced 2026-03-20 10:54:44 +00:00

feat(packages/vue): add useAppSharedState composable

This commit is contained in:
2024-10-19 06:41:02 +07:00
parent 7b4f2d0c0a
commit 6814b16d4d
2 changed files with 5 additions and 5 deletions

View File

@@ -3,7 +3,7 @@ import { ref, reactive } from 'vue';
import { useAppSharedState } from '.'; import { useAppSharedState } from '.';
describe('useAppSharedState', () => { describe('useAppSharedState', () => {
it('should initialize state only once', () => { it('initialize state only once', () => {
const stateFactory = (initValue?: number) => { const stateFactory = (initValue?: number) => {
const count = ref(initValue ?? 0); const count = ref(initValue ?? 0);
return { count }; return { count };
@@ -19,7 +19,7 @@ describe('useAppSharedState', () => {
expect(state1).toBe(state2); 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 stateFactory = () => {
const state = reactive({ count: 0 }); const state = reactive({ count: 0 });
const increment = () => state.count++; const increment = () => state.count++;

View File

@@ -1,5 +1,5 @@
import type { AnyFunction } from '@robonen/stdlib'; 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 // 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 * @category State
* @description Provides a shared state object for use across Vue instances * @description Provides a shared state object for use across Vue instances
* *
* @param {Function} stateFactory The factory function to create the shared state * @param {Function} stateFactory A factory function that returns the shared state object
* @returns {Function} The shared state object * @returns {Function} A function that returns the shared state object
* *
* @example * @example
* const useSharedState = useAppSharedState((initValue?: number) => { * const useSharedState = useAppSharedState((initValue?: number) => {