Skip to content

Commit 03e4e56

Browse files
committed
feat(framework): add Angular and Svelte support ⚡
- Add Angular service and composable integration with signals - Add Svelte store integration with reactive updates - Remove centralized middleware re-export file - Update package exports for Angular and Svelte modules - Bump version to 0.4.0 with new framework dependencies - Expand keywords for better discoverability
1 parent f8425bf commit 03e4e56

File tree

11 files changed

+632
-45
lines changed

11 files changed

+632
-45
lines changed

ARCHITECTURE.md

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Stateless-JS Architecture
22

3-
A universal state management library with **NO wrappers, NO actions, NO reducers, NO complexcity**.
3+
A universal state management library with **NO wrappers, NO actions, NO reducers, NO complexity**.
44

55
## 🎯 Core Philosophy
66

@@ -21,11 +21,15 @@ graph TB
2121
SS[State Setters]
2222
SV[State Values]
2323
24+
AA[Angular Adapter]
2425
RA[React Adapter]
26+
SA[Svelte Adapter]
2527
VA[Vue Adapter]
2628
UA[Universal Adapter]
2729
30+
AC[Angular Components]
2831
RC[React Components]
32+
SC[Svelte Components]
2933
VC[Vue Components]
3034
VJ[Vanilla JS]
3135
@@ -35,10 +39,14 @@ graph TB
3539
3640
RA --> CR
3741
VA --> CR
42+
SA --> CR
43+
AA --> CR
3844
UA --> CR
3945
4046
RC --> RA
4147
VC --> VA
48+
SC --> SA
49+
AC --> AA
4250
VJ --> UA
4351
4452
style CR fill:#e1f5fe,color:#000
@@ -83,6 +91,16 @@ graph LR
8391
VC2[Component D]
8492
end
8593
94+
subgraph "Svelte App"
95+
SC1[Component E]
96+
SC2[Component F]
97+
end
98+
99+
subgraph "Angular App"
100+
AC1[Component G]
101+
AC2[Component H]
102+
end
103+
86104
subgraph "Vanilla JS"
87105
VJ1[Module X]
88106
VJ2[Module Y]
@@ -97,6 +115,10 @@ graph LR
97115
RC2 --> S2
98116
VC1 --> S1
99117
VC2 --> S2
118+
SC1 --> S1
119+
SC2 --> S2
120+
AC1 --> S1
121+
AC2 --> S2
100122
VJ1 --> S1
101123
VJ2 --> S2
102124
@@ -109,6 +131,46 @@ graph LR
109131
style CR fill:#e1f5fe,color:#000
110132
```
111133

134+
## 🔷 Angular Integration
135+
136+
```mermaid
137+
graph TB
138+
subgraph "Angular Component"
139+
AC[useAngularStateless]
140+
AS[Angular Signal]
141+
AI[Injectable Service]
142+
end
143+
144+
subgraph "Angular Adapter"
145+
AAS[Angular Subscribers Map]
146+
NS[notifyAngularSubscribers]
147+
end
148+
149+
subgraph "Core Registry"
150+
CR[Core Registry]
151+
SM[State Map]
152+
end
153+
154+
AC --> AS
155+
AC --> AI
156+
AC --> CR
157+
CR --> SM
158+
159+
AC --> NS
160+
NS --> AAS
161+
AAS --> AS
162+
163+
style AC fill:#dd0031,color:#fff
164+
style AAS fill:#dd0031,color:#fff
165+
style CR fill:#e1f5fe,color:#000
166+
```
167+
168+
**How it works:**
169+
1. `useAngularStateless` calls `useStateless` (core)
170+
2. Creates Angular `WritableSignal` for reactivity
171+
3. Sets up subscriber to update signal value
172+
4. Supports both service injection and standalone function approaches
173+
112174
## ⚛️ React Integration
113175

114176
```mermaid
@@ -149,6 +211,45 @@ graph TB
149211
2. Sets up `useEffect` to subscribe to state changes
150212
3. Uses `forceUpdate` to trigger React re-renders
151213

214+
## 🟠 Svelte Integration
215+
216+
```mermaid
217+
graph TB
218+
subgraph "Svelte Component"
219+
SC[useSvelteStateless]
220+
SW[Svelte Writable Store]
221+
SU[Store Subscription]
222+
end
223+
224+
subgraph "Svelte Adapter"
225+
SS[Svelte Subscribers Map]
226+
NS[notifySvelteSubscribers]
227+
end
228+
229+
subgraph "Core Registry"
230+
CR[Core Registry]
231+
SM[State Map]
232+
end
233+
234+
SC --> SW
235+
SC --> SU
236+
SC --> CR
237+
CR --> SM
238+
239+
SC --> NS
240+
NS --> SS
241+
SS --> SW
242+
243+
style SC fill:#ff3e00,color:#fff
244+
style SS fill:#ff3e00,color:#fff
245+
style CR fill:#e1f5fe,color:#000
246+
```
247+
248+
**How it works:**
249+
1. `useSvelteStateless` calls `useStateless` (core)
250+
2. Creates Svelte `writable` store for reactivity
251+
3. Sets up subscriber to update store value
252+
152253
## 🟢 Vue Integration
153254

154255
```mermaid

README.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@ A universal and lightweight state management library with a clean, stateless API
88
# Universal
99
npm install @neabyte/stateless-js
1010

11+
# Angular (Automatic Reactivity)
12+
npm install @neabyte/stateless-js @angular/core
13+
1114
# React (Automatic Re-renders)
1215
npm install @neabyte/stateless-js react
1316

17+
# Svelte (Automatic Reactivity)
18+
npm install @neabyte/stateless-js svelte
19+
1420
# Vue (Automatic Reactivity)
1521
npm install @neabyte/stateless-js vue
1622
```
@@ -25,9 +31,15 @@ const { createStateless, useStateless } = require('@neabyte/stateless-js')
2531
// ESM (ES Modules)
2632
import { createStateless, useStateless } from '@neabyte/stateless-js'
2733

34+
// Angular (Automatic Reactivity)
35+
import { StatelessService, useAngularStateless } from '@neabyte/stateless-js/angular'
36+
2837
// React (Automatic Re-renders)
2938
import { useReactStateless } from '@neabyte/stateless-js/react'
3039

40+
// Svelte (Automatic Reactivity)
41+
import { useSvelteStateless } from '@neabyte/stateless-js/svelte'
42+
3143
// Vue (Automatic Reactivity)
3244
import { useVueStateless } from '@neabyte/stateless-js/vue'
3345

@@ -64,6 +76,47 @@ setCount(current => current + 1)
6476
console.log(count.value) // 1
6577
```
6678

79+
### 🔷 Angular Usage
80+
81+
```typescript
82+
import { StatelessService, useAngularStateless } from '@neabyte/stateless-js/angular'
83+
84+
// Using the service approach
85+
@Injectable({ providedIn: 'root' })
86+
export class MyService {
87+
constructor(private stateless: StatelessService) {}
88+
counterState = this.stateless.useAngularStateless('counter', 0)
89+
count = this.counterState[1]
90+
setCount = this.counterState[0]
91+
}
92+
93+
// Using the standalone function approach
94+
export class MyComponent {
95+
counterState = useAngularStateless('counter', 0)
96+
count = this.counterState[1]
97+
setCount = this.counterState[0]
98+
increment = () => this.setCount(current => current + 1)
99+
}
100+
```
101+
102+
```typescript
103+
// In your Angular component
104+
@Component({
105+
template: `
106+
<div>
107+
<p>Count: {{ count() }}</p>
108+
<button (click)="increment()">Increment</button>
109+
</div>
110+
`
111+
})
112+
export class CounterComponent {
113+
counterState = useAngularStateless('counter', 0)
114+
count = this.counterState[1]
115+
setCount = this.counterState[0]
116+
increment = () => this.setCount(current => current + 1)
117+
}
118+
```
119+
67120
### ⚛️ React Usage
68121

69122
```typescript
@@ -82,6 +135,30 @@ function Counter() {
82135
}
83136
```
84137

138+
139+
### 🟠 Svelte Usage
140+
141+
```typescript
142+
import { useSvelteStateless } from '@neabyte/stateless-js/svelte'
143+
144+
// In your Svelte component
145+
const [setCount, count] = useSvelteStateless('counter', 0)
146+
const increment = () => setCount(current => current + 1)
147+
```
148+
149+
```svelte
150+
<!-- In your .svelte file -->
151+
<script>
152+
import { useSvelteStateless } from '@neabyte/stateless-js/svelte'
153+
const [setCount, count] = useSvelteStateless('counter', 0)
154+
const increment = () => setCount(current => current + 1)
155+
</script>
156+
<div>
157+
<p>Count: {$count}</p>
158+
<button on:click={increment}>Increment</button>
159+
</div>
160+
```
161+
85162
### 🟢 Vue Usage
86163

87164
```typescript
@@ -228,6 +305,24 @@ Uses existing state if it exists, otherwise creates a new one.
228305
- `fallbackState`: Value to use if state doesn't exist
229306
- Returns: Tuple `[StateSetter<T>, StateValue<T>]`
230307

308+
### Angular Functions
309+
310+
#### `StatelessService.useAngularStateless<T>(id: StateId, initialValue: T): [StateSetter<T>, Signal<T>]`
311+
312+
Angular service method that provides automatic reactivity using Angular signals.
313+
314+
- `id`: Unique identifier (string or number)
315+
- `initialValue`: Initial value for the state
316+
- Returns: Tuple `[StateSetter<T>, Signal<T>]` (Angular signal for reactivity)
317+
318+
#### `useAngularStateless<T>(id: StateId, initialValue: T): [StateSetter<T>, Signal<T>]`
319+
320+
Standalone Angular function that provides automatic reactivity using Angular signals.
321+
322+
- `id`: Unique identifier (string or number)
323+
- `initialValue`: Initial value for the state
324+
- Returns: Tuple `[StateSetter<T>, Signal<T>]` (Angular signal for reactivity)
325+
231326
### React Functions
232327

233328
#### `useReactStateless<T>(id: StateId, initialValue: T): [StateSetter<T>, T]`
@@ -238,6 +333,16 @@ React hook that provides automatic re-renders when state changes.
238333
- `initialValue`: Initial value for the state
239334
- Returns: Tuple `[StateSetter<T>, T]` (direct value, not StateValue object)
240335

336+
### Svelte Functions
337+
338+
#### `useSvelteStateless<T>(id: StateId, initialValue: T): [StateSetter<T>, Writable<T>]`
339+
340+
Svelte function that provides automatic reactivity using Svelte stores.
341+
342+
- `id`: Unique identifier (string or number)
343+
- `initialValue`: Initial value for the state
344+
- Returns: Tuple `[StateSetter<T>, Writable<T>]` (Svelte writable store for reactivity)
345+
241346
### Vue Functions
242347

243348
#### `useVueStateless<T>(id: StateId, initialValue: T): [StateSetter<T>, Ref<T>]`

build.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { resolve } from 'path'
1313
*/
1414
export default defineBuildConfig({
1515
/** @type {string[]} Entry points for the build process */
16-
entries: ['src/index', 'src/react', 'src/vue'],
16+
entries: ['src/index', 'src/react', 'src/svelte', 'src/vue', 'src/angular'],
1717
/** @type {boolean} Whether to generate TypeScript declaration files */
1818
declaration: true,
1919
/** @type {boolean} Whether to clean the output directory before building */

0 commit comments

Comments
 (0)