@slimlib/store 1.3.5 → 1.4.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.
@@ -0,0 +1,5 @@
1
+ {
2
+ "type": "module",
3
+ "types": "../dist/angular.d.ts",
4
+ "main": "../dist/angular.mjs"
5
+ }
@@ -0,0 +1,35 @@
1
+ 'use strict';
2
+
3
+ var core$1 = require('@angular/core');
4
+ var core = require('./core.cjs');
5
+
6
+ const createStore = core.createStoreFactory(false);
7
+ const toSignal = (store, injector) => {
8
+ const cleanupRef = (injector ? injector.get : core$1.inject)(core$1.DestroyRef);
9
+ const state = core$1.signal(store());
10
+ const stateRef = new WeakRef(state);
11
+ const unsubscribe = store((value) => {
12
+ const stateSignal = stateRef.deref();
13
+ if (stateSignal) {
14
+ stateSignal.set(value);
15
+ }
16
+ else {
17
+ unsubscribe();
18
+ }
19
+ });
20
+ cleanupRef?.onDestroy(unsubscribe);
21
+ return state.asReadonly();
22
+ };
23
+ class SlimlibStore {
24
+ store;
25
+ state;
26
+ signal;
27
+ constructor(initialState) {
28
+ [this.state, this.store] = createStore(initialState);
29
+ this.signal = toSignal(this.store);
30
+ }
31
+ }
32
+
33
+ exports.SlimlibStore = SlimlibStore;
34
+ exports.createStore = createStore;
35
+ exports.toSignal = toSignal;
@@ -0,0 +1,15 @@
1
+ import { type ProviderToken, type Signal } from '@angular/core';
2
+ import { type Store } from './core';
3
+ export type InjectorLike = {
4
+ get: {
5
+ <T>(token: ProviderToken<T>): T;
6
+ };
7
+ };
8
+ export declare const createStore: <T extends object>(object?: T) => [T, Store<T>, () => void];
9
+ export declare const toSignal: <T>(store: Store<T>, injector?: InjectorLike) => Signal<T>;
10
+ export declare class SlimlibStore<T extends object> {
11
+ private readonly store;
12
+ protected readonly state: T;
13
+ readonly signal: Signal<T>;
14
+ constructor(initialState: T);
15
+ }
@@ -0,0 +1,31 @@
1
+ import { inject, DestroyRef, signal } from '@angular/core';
2
+ import { createStoreFactory } from './core.mjs';
3
+
4
+ const createStore = createStoreFactory(false);
5
+ const toSignal = (store, injector) => {
6
+ const cleanupRef = (injector ? injector.get : inject)(DestroyRef);
7
+ const state = signal(store());
8
+ const stateRef = new WeakRef(state);
9
+ const unsubscribe = store((value) => {
10
+ const stateSignal = stateRef.deref();
11
+ if (stateSignal) {
12
+ stateSignal.set(value);
13
+ }
14
+ else {
15
+ unsubscribe();
16
+ }
17
+ });
18
+ cleanupRef?.onDestroy(unsubscribe);
19
+ return state.asReadonly();
20
+ };
21
+ class SlimlibStore {
22
+ store;
23
+ state;
24
+ signal;
25
+ constructor(initialState) {
26
+ [this.state, this.store] = createStore(initialState);
27
+ this.signal = toSignal(this.store);
28
+ }
29
+ }
30
+
31
+ export { SlimlibStore, createStore, toSignal };
@@ -0,0 +1,2 @@
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("./core")):"function"==typeof define&&define.amd?define(["exports","@angular/core","./core"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).slimlibStoreAngular={},e.angularCore,e.slimlibStoreCore)}(this,(function(e,t,o){"use strict";const n=o.createStoreFactory(!1),s=(e,o)=>{const n=(o?o.get:t.inject)(t.DestroyRef),s=t.signal(e()),i=new WeakRef(s),r=e((e=>{const t=i.deref();t?t.set(e):r()}));return n?.onDestroy(r),s.asReadonly()};e.SlimlibStore=class{store;state;signal;constructor(e){[this.state,this.store]=n(e),this.signal=s(this.store)}},e.createStore=n,e.toSignal=s}));
2
+ //# sourceMappingURL=angular.umd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"angular.umd.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,9 +1,13 @@
1
1
  {
2
- "version": "1.3.5",
3
- "license": "MIT",
2
+ "type": "module",
3
+ "version": "1.4.0",
4
4
  "name": "@slimlib/store",
5
+ "description": "Simple Proxy-based store for SPA",
6
+ "license": "MIT",
5
7
  "author": "Konstantin Shutkin",
6
- "type": "module",
8
+ "main": "./dist/index.cjs",
9
+ "module": "./dist/index.mjs",
10
+ "unpkg": "./dist/index.umd.js",
7
11
  "exports": {
8
12
  ".": {
9
13
  "require": "./dist/index.cjs",
@@ -25,46 +29,40 @@
25
29
  "require": "./dist/svelte.cjs",
26
30
  "default": "./dist/svelte.mjs"
27
31
  },
32
+ "./angular": {
33
+ "require": "./dist/angular.cjs",
34
+ "default": "./dist/angular.mjs"
35
+ },
28
36
  "./package.json": "./package.json"
29
37
  },
30
- "main": "./dist/index.cjs",
31
- "module": "./dist/index.mjs",
32
- "typings": "./dist/index.d.ts",
33
- "unpkg": "./dist/index.umd.js",
38
+ "types": "./dist/index.d.ts",
34
39
  "files": [
35
40
  "dist",
36
41
  "react",
37
42
  "preact",
38
43
  "core",
39
44
  "svelte",
40
- "LICENSE"
45
+ "angular"
41
46
  ],
42
47
  "repository": {
43
48
  "type": "git",
44
- "url": "git+https://github.com/kshutkin/slimlib.git"
45
- },
46
- "bugs": {
47
- "url": "https://github.com/kshutkin/slimlib/issues"
49
+ "url": "git+https://github.com/kshutkin/slimlib.git",
50
+ "directory": "store"
48
51
  },
52
+ "bugs": "https://github.com/kshutkin/slimlib/issues",
49
53
  "homepage": "https://github.com/kshutkin/slimlib/blob/main/store/README.md",
50
- "peerDependencies": {
51
- "preact": ">=10.0.0",
52
- "react": ">=17.0.0"
53
- },
54
- "peerDependenciesMeta": {
55
- "react": {
56
- "optional": true
57
- },
58
- "preact": {
59
- "optional": true
60
- }
61
- },
54
+ "keywords": [
55
+ "@slimlib",
56
+ "store",
57
+ "proxy"
58
+ ],
62
59
  "devDependencies": {
63
60
  "@types/react": "^18.0.0",
64
61
  "preact": ">=10.0.0",
65
62
  "react": ">=17.0.0",
66
63
  "react-dom": ">=17.0.0",
67
64
  "@testing-library/react": "^14.0.0",
65
+ "@testing-library/angular": "^14.0.0",
68
66
  "@types/react-dom": ">=17.0.0",
69
67
  "jest-environment-jsdom": "^29.4.3",
70
68
  "@testing-library/svelte": "^3.2.2",
@@ -72,14 +70,24 @@
72
70
  "svelte-jester": "^2.3.2",
73
71
  "tslib": "^2.5.0"
74
72
  },
75
- "description": "Simple Proxy-based store for SPA",
76
- "keywords": [
77
- "@slimlib",
78
- "store",
79
- "proxy"
80
- ],
73
+ "peerDependencies": {
74
+ "preact": ">=10.0.0",
75
+ "react": ">=17.0.0",
76
+ "@angular/core": ">=16.0.0"
77
+ },
78
+ "peerDependenciesMeta": {
79
+ "react": {
80
+ "optional": true
81
+ },
82
+ "preact": {
83
+ "optional": true
84
+ },
85
+ "@angular/core": {
86
+ "optional": true
87
+ }
88
+ },
81
89
  "scripts": {
82
- "build": "pkgbld-internal --umd=index,preact,react,svelte",
90
+ "build": "pkgbld-internal --umd=index,preact,react,svelte,angular",
83
91
  "test": "jest --collectCoverage",
84
92
  "lint": "eslint ./src"
85
93
  }