@coaction/svelte 1.5.0 → 2.1.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/README.md CHANGED
@@ -1,17 +1,15 @@
1
1
  # @coaction/svelte
2
2
 
3
- ![Node CI](https://github.com/unadlib/coaction/workflows/Node%20CI/badge.svg)
4
- [![npm](https://img.shields.io/npm/v/@coaction/svelte.svg)](https://www.npmjs.com/package/@coaction/svelte)
5
- ![license](https://img.shields.io/npm/l/@coaction/svelte)
3
+ ![Node CI](https://github.com/coactionjs/coaction/workflows/Node%20CI/badge.svg) [![npm](https://img.shields.io/npm/v/@coaction/svelte.svg)](https://www.npmjs.com/package/@coaction/svelte) ![license](https://img.shields.io/npm/l/@coaction/svelte)
6
4
 
7
5
  A Coaction integration tool for Svelte.
8
6
 
9
7
  ## Installation
10
8
 
11
- You can install it via npm, yarn or pnpm.
9
+ Install it with pnpm:
12
10
 
13
11
  ```sh
14
- npm install coaction @coaction/svelte
12
+ pnpm add coaction @coaction/svelte
15
13
  ```
16
14
 
17
15
  ## Usage
@@ -36,4 +34,4 @@ count.subscribe((value) => {
36
34
 
37
35
  ## Documentation
38
36
 
39
- You can find the documentation [here](https://github.com/unadlib/coaction).
37
+ You can find the documentation [here](https://github.com/coactionjs/coaction).
package/dist/index.d.mts CHANGED
@@ -1,36 +1,43 @@
1
- import { ISlices, Slice, StoreOptions, Store, SliceState, ClientStoreOptions, Asyncify } from 'coaction';
2
- export * from 'coaction';
1
+ import { Asyncify, ClientStoreOptions, ISlices, Slice, SliceState, Store, StoreOptions } from "coaction";
2
+ export * from "coaction";
3
3
 
4
+ //#region \0rolldown/runtime.js
5
+ //#endregion
6
+ //#region packages/coaction-svelte/src/index.d.ts
4
7
  type Unsubscriber = () => void;
5
- type Listener = () => void;
6
8
  type Readable<T> = {
7
- subscribe: (run: (value: T) => void, invalidate?: (value?: T) => void) => Unsubscriber;
9
+ subscribe: (run: (value: T) => void, invalidate?: (value?: T) => void) => Unsubscriber;
8
10
  };
9
- type StoreReturn<T extends object> = Store<T> & {
10
- (): T;
11
- <P>(selector: (state: T) => P): Readable<P>;
12
- subscribe: {
13
- (listener: Listener): Unsubscriber;
14
- (run: (value: T) => void, invalidate?: (value?: T) => void): Unsubscriber;
15
- };
16
- select: <P>(selector: (state: T) => P) => Readable<P>;
11
+ type StoreReturn<T extends object> = Omit<Store<T>, 'subscribe'> & {
12
+ (): T;
13
+ <P>(selector: (state: T) => P): Readable<P>;
14
+ subscribe: Readable<T>['subscribe'];
15
+ select: <P>(selector: (state: T) => P) => Readable<P>;
17
16
  };
18
- type StoreWithAsyncFunction<T extends object, D extends true | false = false> = Store<Asyncify<T, D>> & {
19
- (): Asyncify<T, D>;
20
- <P>(selector: (state: Asyncify<T, D>) => P): Readable<P>;
21
- subscribe: {
22
- (listener: Listener): Unsubscriber;
23
- (run: (value: Asyncify<T, D>) => void, invalidate?: (value?: Asyncify<T, D>) => void): Unsubscriber;
24
- };
25
- select: <P>(selector: (state: Asyncify<T, D>) => P) => Readable<P>;
17
+ type StoreWithAsyncFunction<T extends object, D extends true | false = false> = Omit<Store<Asyncify<T, D>>, 'subscribe'> & {
18
+ (): Asyncify<T, D>;
19
+ <P>(selector: (state: Asyncify<T, D>) => P): Readable<P>;
20
+ subscribe: Readable<Asyncify<T, D>>['subscribe'];
21
+ select: <P>(selector: (state: Asyncify<T, D>) => P) => Readable<P>;
22
+ };
23
+ type CreateState = ISlices | Record<PropertyKey, Slice<any>>;
24
+ type SingleStoreOptions<T extends CreateState> = StoreOptions<T> & {
25
+ sliceMode: 'single';
26
+ };
27
+ type SingleClientStoreOptions<T extends CreateState> = ClientStoreOptions<T> & {
28
+ sliceMode: 'single';
26
29
  };
27
- type CreateState = ISlices | Record<string, Slice<any>>;
28
30
  type Creator = {
29
- <T extends Record<string, Slice<any>>>(createState: T, options?: StoreOptions<T>): StoreReturn<SliceState<T>>;
30
- <T extends ISlices>(createState: Slice<T>, options?: StoreOptions<T>): StoreReturn<T>;
31
- <T extends Record<string, Slice<any>>>(createState: T, options?: ClientStoreOptions<T>): StoreWithAsyncFunction<SliceState<T>, true>;
32
- <T extends ISlices>(createState: Slice<T>, options?: ClientStoreOptions<T>): StoreWithAsyncFunction<T>;
31
+ <T extends ISlices>(createState: T, options: SingleStoreOptions<T>): StoreReturn<T>;
32
+ <T extends Record<PropertyKey, Slice<any>>>(createState: T, options?: StoreOptions<T>): StoreReturn<SliceState<T>>;
33
+ <T extends ISlices>(createState: Slice<T> | T, options?: StoreOptions<T>): StoreReturn<T>;
34
+ <T extends ISlices>(createState: T, options: SingleClientStoreOptions<T>): StoreWithAsyncFunction<T>;
35
+ <T extends Record<PropertyKey, Slice<any>>>(createState: T, options?: ClientStoreOptions<T>): StoreWithAsyncFunction<SliceState<T>, true>;
36
+ <T extends ISlices>(createState: Slice<T> | T, options?: ClientStoreOptions<T>): StoreWithAsyncFunction<T>;
33
37
  };
34
38
  declare const create: Creator;
35
-
36
- export { type CreateState, type Creator, type StoreReturn, type StoreWithAsyncFunction, create };
39
+ declare namespace index_d_exports {
40
+ export { CreateState, Creator, StoreReturn, StoreWithAsyncFunction, create };
41
+ }
42
+ //#endregion
43
+ export { CreateState, Creator, StoreReturn, StoreWithAsyncFunction, create };
package/dist/index.d.ts CHANGED
@@ -1,36 +1,43 @@
1
- import { ISlices, Slice, StoreOptions, Store, SliceState, ClientStoreOptions, Asyncify } from 'coaction';
2
- export * from 'coaction';
1
+ import { Asyncify, ClientStoreOptions, ISlices, Slice, SliceState, Store, StoreOptions } from "coaction";
2
+ export * from "coaction";
3
3
 
4
+ //#region \0rolldown/runtime.js
5
+ //#endregion
6
+ //#region packages/coaction-svelte/src/index.d.ts
4
7
  type Unsubscriber = () => void;
5
- type Listener = () => void;
6
8
  type Readable<T> = {
7
- subscribe: (run: (value: T) => void, invalidate?: (value?: T) => void) => Unsubscriber;
9
+ subscribe: (run: (value: T) => void, invalidate?: (value?: T) => void) => Unsubscriber;
8
10
  };
9
- type StoreReturn<T extends object> = Store<T> & {
10
- (): T;
11
- <P>(selector: (state: T) => P): Readable<P>;
12
- subscribe: {
13
- (listener: Listener): Unsubscriber;
14
- (run: (value: T) => void, invalidate?: (value?: T) => void): Unsubscriber;
15
- };
16
- select: <P>(selector: (state: T) => P) => Readable<P>;
11
+ type StoreReturn<T extends object> = Omit<Store<T>, 'subscribe'> & {
12
+ (): T;
13
+ <P>(selector: (state: T) => P): Readable<P>;
14
+ subscribe: Readable<T>['subscribe'];
15
+ select: <P>(selector: (state: T) => P) => Readable<P>;
17
16
  };
18
- type StoreWithAsyncFunction<T extends object, D extends true | false = false> = Store<Asyncify<T, D>> & {
19
- (): Asyncify<T, D>;
20
- <P>(selector: (state: Asyncify<T, D>) => P): Readable<P>;
21
- subscribe: {
22
- (listener: Listener): Unsubscriber;
23
- (run: (value: Asyncify<T, D>) => void, invalidate?: (value?: Asyncify<T, D>) => void): Unsubscriber;
24
- };
25
- select: <P>(selector: (state: Asyncify<T, D>) => P) => Readable<P>;
17
+ type StoreWithAsyncFunction<T extends object, D extends true | false = false> = Omit<Store<Asyncify<T, D>>, 'subscribe'> & {
18
+ (): Asyncify<T, D>;
19
+ <P>(selector: (state: Asyncify<T, D>) => P): Readable<P>;
20
+ subscribe: Readable<Asyncify<T, D>>['subscribe'];
21
+ select: <P>(selector: (state: Asyncify<T, D>) => P) => Readable<P>;
22
+ };
23
+ type CreateState = ISlices | Record<PropertyKey, Slice<any>>;
24
+ type SingleStoreOptions<T extends CreateState> = StoreOptions<T> & {
25
+ sliceMode: 'single';
26
+ };
27
+ type SingleClientStoreOptions<T extends CreateState> = ClientStoreOptions<T> & {
28
+ sliceMode: 'single';
26
29
  };
27
- type CreateState = ISlices | Record<string, Slice<any>>;
28
30
  type Creator = {
29
- <T extends Record<string, Slice<any>>>(createState: T, options?: StoreOptions<T>): StoreReturn<SliceState<T>>;
30
- <T extends ISlices>(createState: Slice<T>, options?: StoreOptions<T>): StoreReturn<T>;
31
- <T extends Record<string, Slice<any>>>(createState: T, options?: ClientStoreOptions<T>): StoreWithAsyncFunction<SliceState<T>, true>;
32
- <T extends ISlices>(createState: Slice<T>, options?: ClientStoreOptions<T>): StoreWithAsyncFunction<T>;
31
+ <T extends ISlices>(createState: T, options: SingleStoreOptions<T>): StoreReturn<T>;
32
+ <T extends Record<PropertyKey, Slice<any>>>(createState: T, options?: StoreOptions<T>): StoreReturn<SliceState<T>>;
33
+ <T extends ISlices>(createState: Slice<T> | T, options?: StoreOptions<T>): StoreReturn<T>;
34
+ <T extends ISlices>(createState: T, options: SingleClientStoreOptions<T>): StoreWithAsyncFunction<T>;
35
+ <T extends Record<PropertyKey, Slice<any>>>(createState: T, options?: ClientStoreOptions<T>): StoreWithAsyncFunction<SliceState<T>, true>;
36
+ <T extends ISlices>(createState: Slice<T> | T, options?: ClientStoreOptions<T>): StoreWithAsyncFunction<T>;
33
37
  };
34
38
  declare const create: Creator;
35
-
36
- export { type CreateState, type Creator, type StoreReturn, type StoreWithAsyncFunction, create };
39
+ declare namespace index_d_exports {
40
+ export { CreateState, Creator, StoreReturn, StoreWithAsyncFunction, create };
41
+ }
42
+ //#endregion
43
+ export { CreateState, Creator, StoreReturn, StoreWithAsyncFunction, create };
package/dist/index.js CHANGED
@@ -1,78 +1,45 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#endregion
3
+ let coaction = require("coaction");
4
+ //#region packages/coaction-svelte/src/index.ts
5
+ const createReadable = (store, selector, subscribeStore = store.subscribe.bind(store)) => ({ subscribe(run, invalidate) {
6
+ run(selector(store.getState()));
7
+ return subscribeStore(() => {
8
+ const value = selector(store.getState());
9
+ invalidate?.(value);
10
+ run(value);
11
+ });
12
+ } });
13
+ const create = (createState, options) => {
14
+ const store = (0, coaction.create)(createState, options);
15
+ const baseSubscribe = store.subscribe.bind(store);
16
+ function select(selector) {
17
+ return createReadable(store, selector, baseSubscribe);
18
+ }
19
+ const subscribe = ((run, invalidate) => {
20
+ run(store.getState());
21
+ return baseSubscribe(() => {
22
+ const state = store.getState();
23
+ invalidate?.(state);
24
+ run(state);
25
+ });
26
+ });
27
+ Object.assign(store, {
28
+ subscribe,
29
+ select
30
+ });
31
+ return (0, coaction.wrapStore)(store, (selector) => {
32
+ if (typeof selector === "function") return select(selector);
33
+ return store.getState();
34
+ });
9
35
  };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
-
21
- // index.ts
22
- var index_exports = {};
23
- __export(index_exports, {
24
- create: () => create
25
- });
26
- module.exports = __toCommonJS(index_exports);
27
-
28
- // src/index.ts
29
- var src_exports = {};
30
- __export(src_exports, {
31
- create: () => create
32
- });
33
- var import_coaction = require("coaction");
34
- __reExport(src_exports, require("coaction"));
35
- var createReadable = (store, selector) => ({
36
- subscribe(run) {
37
- run(selector(store.getState()));
38
- return store.subscribe(() => {
39
- run(selector(store.getState()));
40
- });
41
- }
42
- });
43
- var create = (createState, options) => {
44
- const store = (0, import_coaction.create)(createState, options);
45
- const baseSubscribe = store.subscribe.bind(store);
46
- function select(selector) {
47
- return createReadable(store, selector);
48
- }
49
- const subscribe = ((listener, invalidate) => {
50
- if (typeof invalidate === "function") {
51
- invalidate();
52
- }
53
- if (typeof listener === "function" && listener.length > 0) {
54
- listener(store.getState());
55
- return baseSubscribe(() => {
56
- listener(store.getState());
57
- });
58
- }
59
- return baseSubscribe(listener);
60
- });
61
- Object.assign(store, {
62
- subscribe,
63
- select
64
- });
65
- return (0, import_coaction.wrapStore)(store, (selector) => {
66
- if (typeof selector === "function") {
67
- return select(selector);
68
- }
69
- return store.getState();
70
- });
71
- };
72
-
73
- // index.ts
74
- __reExport(index_exports, src_exports, module.exports);
75
- // Annotate the CommonJS export names for ESM import in node:
76
- 0 && (module.exports = {
77
- create
36
+ //#endregion
37
+ exports.create = create;
38
+ Object.keys(coaction).forEach(function(k) {
39
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
40
+ enumerable: true,
41
+ get: function() {
42
+ return coaction[k];
43
+ }
44
+ });
78
45
  });
package/dist/index.mjs CHANGED
@@ -1,75 +1,37 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
18
-
19
- // index.ts
20
- var index_exports = {};
21
- __export(index_exports, {
22
- create: () => create
23
- });
24
-
25
- // src/index.ts
26
- var src_exports = {};
27
- __export(src_exports, {
28
- create: () => create
29
- });
30
- __reExport(src_exports, coaction_star);
31
- import { create as createVanilla, wrapStore } from "coaction";
32
- import * as coaction_star from "coaction";
33
- var createReadable = (store, selector) => ({
34
- subscribe(run) {
35
- run(selector(store.getState()));
36
- return store.subscribe(() => {
37
- run(selector(store.getState()));
38
- });
39
- }
40
- });
41
- var create = (createState, options) => {
42
- const store = createVanilla(createState, options);
43
- const baseSubscribe = store.subscribe.bind(store);
44
- function select(selector) {
45
- return createReadable(store, selector);
46
- }
47
- const subscribe = ((listener, invalidate) => {
48
- if (typeof invalidate === "function") {
49
- invalidate();
50
- }
51
- if (typeof listener === "function" && listener.length > 0) {
52
- listener(store.getState());
53
- return baseSubscribe(() => {
54
- listener(store.getState());
55
- });
56
- }
57
- return baseSubscribe(listener);
58
- });
59
- Object.assign(store, {
60
- subscribe,
61
- select
62
- });
63
- return wrapStore(store, (selector) => {
64
- if (typeof selector === "function") {
65
- return select(selector);
66
- }
67
- return store.getState();
68
- });
69
- };
70
-
71
- // index.ts
72
- __reExport(index_exports, src_exports);
73
- export {
74
- create
1
+ import { create as create$1, wrapStore } from "coaction";
2
+ export * from "coaction";
3
+ //#endregion
4
+ //#region packages/coaction-svelte/src/index.ts
5
+ const createReadable = (store, selector, subscribeStore = store.subscribe.bind(store)) => ({ subscribe(run, invalidate) {
6
+ run(selector(store.getState()));
7
+ return subscribeStore(() => {
8
+ const value = selector(store.getState());
9
+ invalidate?.(value);
10
+ run(value);
11
+ });
12
+ } });
13
+ const create = (createState, options) => {
14
+ const store = create$1(createState, options);
15
+ const baseSubscribe = store.subscribe.bind(store);
16
+ function select(selector) {
17
+ return createReadable(store, selector, baseSubscribe);
18
+ }
19
+ const subscribe = ((run, invalidate) => {
20
+ run(store.getState());
21
+ return baseSubscribe(() => {
22
+ const state = store.getState();
23
+ invalidate?.(state);
24
+ run(state);
25
+ });
26
+ });
27
+ Object.assign(store, {
28
+ subscribe,
29
+ select
30
+ });
31
+ return wrapStore(store, (selector) => {
32
+ if (typeof selector === "function") return select(selector);
33
+ return store.getState();
34
+ });
75
35
  };
36
+ //#endregion
37
+ export { create };
package/package.json CHANGED
@@ -1,67 +1,69 @@
1
1
  {
2
2
  "name": "@coaction/svelte",
3
- "version": "1.5.0",
3
+ "version": "2.1.0",
4
4
  "description": "A Coaction integration tool for Svelte",
5
5
  "keywords": [
6
- "state",
7
6
  "coaction",
8
- "svelte",
9
- "store"
10
- ],
11
- "authors": [
12
- "Michael Lin <unadlib@gmail.com> (https://github.com/unadlib)"
7
+ "state",
8
+ "store",
9
+ "svelte"
13
10
  ],
14
- "homepage": "https://github.com/unadlib/coaction/tree/main/packages/coaction-svelte#readme",
11
+ "homepage": "https://github.com/coactionjs/coaction/tree/main/packages/coaction-svelte#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/coactionjs/coaction/issues"
14
+ },
15
15
  "license": "MIT",
16
+ "author": "unadlib",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/coactionjs/coaction.git",
20
+ "directory": "packages/coaction-svelte"
21
+ },
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "sideEffects": false,
16
26
  "main": "dist/index.js",
17
27
  "module": "dist/index.mjs",
28
+ "types": "dist/index.d.ts",
18
29
  "exports": {
19
30
  ".": {
20
- "types": "./dist/index.d.ts",
21
- "import": "./dist/index.mjs",
22
- "require": "./dist/index.js",
31
+ "import": {
32
+ "types": "./dist/index.d.mts",
33
+ "default": "./dist/index.mjs"
34
+ },
35
+ "require": {
36
+ "types": "./dist/index.d.ts",
37
+ "default": "./dist/index.js"
38
+ },
23
39
  "default": "./dist/index.mjs"
24
40
  },
25
41
  "./package.json": "./package.json"
26
42
  },
27
- "types": "dist/index.d.ts",
28
- "sideEffects": false,
29
- "files": [
30
- "dist"
31
- ],
32
- "repository": {
33
- "type": "git",
34
- "url": "https://github.com/unadlib/coaction.git",
35
- "directory": "packages/coaction-svelte"
43
+ "publishConfig": {
44
+ "access": "public",
45
+ "provenance": true
36
46
  },
37
- "bugs": {
38
- "url": "https://github.com/unadlib/coaction/issues"
47
+ "devDependencies": {
48
+ "svelte": "^5.53.11",
49
+ "coaction": "2.1.0"
39
50
  },
40
51
  "peerDependencies": {
41
- "coaction": "^1.5.0",
52
+ "coaction": ">=2.1.0 <3",
42
53
  "svelte": "^4.0.0 || ^5.0.0"
43
54
  },
44
55
  "peerDependenciesMeta": {
45
- "coaction": {
46
- "optional": true
47
- },
48
56
  "svelte": {
49
57
  "optional": true
50
58
  }
51
59
  },
52
- "devDependencies": {
53
- "svelte": "^5.53.11",
54
- "coaction": "1.5.0"
55
- },
56
- "publishConfig": {
57
- "access": "public",
58
- "provenance": true
59
- },
60
- "author": "unadlib",
60
+ "authors": [
61
+ "Michael Lin <unadlib@gmail.com> (https://github.com/unadlib)"
62
+ ],
61
63
  "scripts": {
62
64
  "clean": "rm -rf dist",
63
65
  "test": "vitest run test",
64
- "build": "tsup index.ts --format cjs,esm --dts --clean --out-dir dist",
65
- "dev": "tsup index.ts --format cjs,esm --dts --watch --out-dir dist"
66
+ "build": "node ../../scripts/build-package.mjs",
67
+ "dev": "node ../../scripts/build-package.mjs --watch"
66
68
  }
67
69
  }