ccstate-vue 4.13.0 → 5.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,34 @@
1
1
  # ccstate-vue
2
2
 
3
+ ## 5.2.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [304895d]
8
+ - ccstate@5.2.0
9
+
10
+ ## 5.1.0
11
+
12
+ ### Patch Changes
13
+
14
+ - ccstate@5.1.0
15
+
16
+ ## 5.0.0
17
+
18
+ ### Major Changes
19
+
20
+ - 2fdba09: feat: provide watch method to replace sub
21
+
22
+ ### Minor Changes
23
+
24
+ - 52c52fd: refactor: remove defaultStore
25
+
26
+ ### Patch Changes
27
+
28
+ - Updated dependencies [2fdba09]
29
+ - Updated dependencies [52c52fd]
30
+ - ccstate@5.0.0
31
+
3
32
  ## 4.13.0
4
33
 
5
34
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  var vue = require('vue');
4
- var ccstate = require('ccstate');
5
4
 
6
5
  var StoreKey = Symbol('ccstate-vue-store');
7
6
  var provideStore = function provideStore(store) {
@@ -9,19 +8,17 @@ var provideStore = function provideStore(store) {
9
8
  };
10
9
  var useStore = function useStore() {
11
10
  return vue.inject(StoreKey, function () {
12
- return ccstate.getDefaultStore();
11
+ throw new Error('useStore must be used within a provideStore');
13
12
  }, true);
14
13
  };
15
14
 
16
15
  function useGet(atom) {
17
16
  var store = useStore();
18
- var initialValue = store.get(atom);
19
- var vueState = vue.shallowRef(initialValue);
17
+ var vueState = vue.shallowRef(store.get(atom));
20
18
  var controller = new AbortController();
21
- store.sub(atom, ccstate.command(function () {
22
- var nextValue = store.get(atom);
23
- vueState.value = nextValue;
24
- }), {
19
+ store.watch(function (get) {
20
+ vueState.value = get(atom);
21
+ }, {
25
22
  signal: controller.signal
26
23
  });
27
24
  if (vue.getCurrentInstance()) {
package/dist/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { provide, inject, shallowRef, getCurrentInstance, onScopeDispose, shallowReadonly } from 'vue';
2
- import { getDefaultStore, command } from 'ccstate';
3
2
 
4
3
  var StoreKey = Symbol('ccstate-vue-store');
5
4
  var provideStore = function provideStore(store) {
@@ -7,19 +6,17 @@ var provideStore = function provideStore(store) {
7
6
  };
8
7
  var useStore = function useStore() {
9
8
  return inject(StoreKey, function () {
10
- return getDefaultStore();
9
+ throw new Error('useStore must be used within a provideStore');
11
10
  }, true);
12
11
  };
13
12
 
14
13
  function useGet(atom) {
15
14
  var store = useStore();
16
- var initialValue = store.get(atom);
17
- var vueState = shallowRef(initialValue);
15
+ var vueState = shallowRef(store.get(atom));
18
16
  var controller = new AbortController();
19
- store.sub(atom, command(function () {
20
- var nextValue = store.get(atom);
21
- vueState.value = nextValue;
22
- }), {
17
+ store.watch(function (get) {
18
+ vueState.value = get(atom);
19
+ }, {
23
20
  signal: controller.signal
24
21
  });
25
22
  if (getCurrentInstance()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccstate-vue",
3
- "version": "4.13.0",
3
+ "version": "5.2.0",
4
4
  "description": "CCState Vue Hooks",
5
5
  "repository": {
6
6
  "type": "git",
@@ -8,6 +8,10 @@
8
8
  },
9
9
  "license": "MIT",
10
10
  "type": "module",
11
+ "scripts": {
12
+ "build": "rollup -c",
13
+ "prebuild": "shx rm -rf dist"
14
+ },
11
15
  "main": "./dist/index.cjs",
12
16
  "module": "./dist/index.js",
13
17
  "exports": {
@@ -20,7 +24,7 @@
20
24
  "vue": ">=3.2.0"
21
25
  },
22
26
  "dependencies": {
23
- "ccstate": "^4.13.0"
27
+ "ccstate": "workspace:^"
24
28
  },
25
29
  "devDependencies": {
26
30
  "@babel/preset-env": "^7.26.0",
@@ -39,9 +43,5 @@
39
43
  "signal-timers": "^1.0.4",
40
44
  "vitest": "^2.1.8",
41
45
  "vue": "^3.5.13"
42
- },
43
- "scripts": {
44
- "build": "rollup -c",
45
- "prebuild": "shx rm -rf dist"
46
46
  }
47
- }
47
+ }
@@ -2,7 +2,7 @@
2
2
  import '@testing-library/jest-dom/vitest';
3
3
  import { fireEvent, render, cleanup, screen } from '@testing-library/vue';
4
4
  import { afterEach, expect, it } from 'vitest';
5
- import { command, createStore, getDefaultStore, state } from 'ccstate';
5
+ import { command, createStore, state } from 'ccstate';
6
6
  import { provideStore } from '../provider';
7
7
  import { useGet, useSet } from '..';
8
8
 
@@ -87,26 +87,24 @@ it('call command by useSet', async () => {
87
87
  expect(screen.getByText('Times clicked: 30')).toBeInTheDocument();
88
88
  });
89
89
 
90
- it('should use default store if no provider', () => {
90
+ it('should throw error if no store provide', () => {
91
91
  const count$ = state(0);
92
- getDefaultStore().set(count$, 10);
92
+ const store = createStore();
93
+ store.set(count$, 10);
93
94
 
94
95
  const Component = {
95
96
  setup() {
96
- const count = useGet(count$);
97
- return { count };
97
+ useGet(count$);
98
98
  },
99
99
  template: `
100
- <div>
101
- <p>{{ count }}</p>
102
- </div>
100
+ <div></div>
103
101
  `,
104
102
  };
105
103
 
106
- render({
107
- components: { Component },
108
- template: `<div><Component /></div>`,
109
- });
110
-
111
- expect(screen.getByText('10')).toBeInTheDocument();
104
+ expect(() => {
105
+ render({
106
+ components: { Component },
107
+ template: `<div><Component /></div>`,
108
+ });
109
+ }).toThrowError('useStore must be used within a provideStore');
112
110
  });
package/src/provider.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { inject, provide, type InjectionKey } from 'vue';
2
- import { getDefaultStore } from 'ccstate';
3
2
  import type { Store } from 'ccstate';
4
3
 
5
4
  export const StoreKey = Symbol('ccstate-vue-store') as InjectionKey<Store>;
@@ -12,7 +11,7 @@ export const useStore = (): Store => {
12
11
  return inject(
13
12
  StoreKey,
14
13
  () => {
15
- return getDefaultStore();
14
+ throw new Error('useStore must be used within a provideStore');
16
15
  },
17
16
  true,
18
17
  );
package/src/useGet.ts CHANGED
@@ -1,20 +1,17 @@
1
1
  import { getCurrentInstance, onScopeDispose, shallowReadonly, shallowRef, type ShallowRef } from 'vue';
2
2
  import { useStore } from './provider';
3
- import { command, type Computed, type State } from 'ccstate';
3
+ import { type Computed, type State } from 'ccstate';
4
4
 
5
5
  export function useGet<Value>(atom: Computed<Value> | State<Value>): Readonly<ShallowRef<Value>> {
6
6
  const store = useStore();
7
- const initialValue = store.get(atom);
8
7
 
9
- const vueState = shallowRef(initialValue);
8
+ const vueState = shallowRef(store.get(atom));
10
9
 
11
10
  const controller = new AbortController();
12
- store.sub(
13
- atom,
14
- command(() => {
15
- const nextValue = store.get(atom);
16
- vueState.value = nextValue;
17
- }),
11
+ store.watch(
12
+ (get) => {
13
+ vueState.value = get(atom);
14
+ },
18
15
  {
19
16
  signal: controller.signal,
20
17
  },
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2019 e7h4n
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN EFFECT OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.