@storix-js/svelte 0.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/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function o(e){return e()}function u(e){const t=e();return{subscribe(r){return r(t),t.$subscribe(()=>{r(t)})}}}exports.toSvelteStore=u;exports.useStore=o;
@@ -0,0 +1,7 @@
1
+ import type { StoreInstance } from '@storix-js/core';
2
+ export declare function useStore<T extends (...args: never[]) => StoreInstance>(factory: T): ReturnType<T>;
3
+ export interface SvelteReadableStore<T> {
4
+ subscribe(run: (value: T) => void): () => void;
5
+ }
6
+ export declare function toSvelteStore<T extends (...args: never[]) => StoreInstance>(factory: T): SvelteReadableStore<ReturnType<T>>;
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,aAAa,EAAE,OAAO,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAEjG;AAED,MAAM,WAAW,mBAAmB,CAAC,CAAC;IACpC,SAAS,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;CAChD;AAED,wBAAgB,aAAa,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,aAAa,EAAE,OAAO,EAAE,CAAC,GAAG,mBAAmB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAW3H"}
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ function o(e) {
2
+ return e();
3
+ }
4
+ function n(e) {
5
+ const t = e();
6
+ return {
7
+ subscribe(r) {
8
+ return r(t), t.$subscribe(() => {
9
+ r(t);
10
+ });
11
+ }
12
+ };
13
+ }
14
+ export {
15
+ n as toSvelteStore,
16
+ o as useStore
17
+ };
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@storix-js/svelte",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.cjs"
13
+ }
14
+ },
15
+ "scripts": {
16
+ "build": "vite build && tsc -p tsconfig.build.json --emitDeclarationOnly",
17
+ "dev": "vite build --watch",
18
+ "test": "vitest run",
19
+ "typecheck": "tsc -p tsconfig.json --noEmit"
20
+ },
21
+ "dependencies": {
22
+ "@storix-js/core": "workspace:*"
23
+ }
24
+ }
package/src/index.ts ADDED
@@ -0,0 +1,22 @@
1
+ import type { StoreInstance } from '@storix-js/core';
2
+
3
+ export function useStore<T extends (...args: never[]) => StoreInstance>(factory: T): ReturnType<T> {
4
+ return factory() as ReturnType<T>;
5
+ }
6
+
7
+ export interface SvelteReadableStore<T> {
8
+ subscribe(run: (value: T) => void): () => void;
9
+ }
10
+
11
+ export function toSvelteStore<T extends (...args: never[]) => StoreInstance>(factory: T): SvelteReadableStore<ReturnType<T>> {
12
+ const store = factory() as ReturnType<T>;
13
+
14
+ return {
15
+ subscribe(run) {
16
+ run(store);
17
+ return store.$subscribe(() => {
18
+ run(store);
19
+ });
20
+ }
21
+ };
22
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "dist",
6
+ "paths": {}
7
+ }
8
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "include": ["src"]
4
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { defineConfig } from 'vite';
2
+
3
+ export default defineConfig({
4
+ build: {
5
+ lib: {
6
+ entry: 'src/index.ts',
7
+ name: 'StorixSvelte',
8
+ fileName: 'index',
9
+ formats: ['es', 'cjs']
10
+ }
11
+ },
12
+ test: {
13
+ environment: 'node'
14
+ }
15
+ });