Skip to content

Commit a90ce95

Browse files
committed
feat(middleware): add Vue.js support and refactor middleware structure 💎
- Add Vue composable with automatic reactivity support - Refactor React middleware to uppercase naming convention - Update package configuration for Vue dependencies and exports - Update documentation with Vue usage examples - Bump version to 0.3.0 for new feature release
1 parent 3db16a9 commit a90ce95

File tree

8 files changed

+335
-12
lines changed

8 files changed

+335
-12
lines changed

README.md

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ npm install @neabyte/stateless-js
1010

1111
# React (Automatic Re-renders)
1212
npm install @neabyte/stateless-js react
13+
14+
# Vue (Automatic Reactivity)
15+
npm install @neabyte/stateless-js vue
1316
```
1417

1518
## 🔧 Module Support
@@ -25,6 +28,9 @@ import { createStateless, useStateless } from '@neabyte/stateless-js'
2528
// React (Automatic Re-renders)
2629
import { useReactStateless } from '@neabyte/stateless-js/react'
2730

31+
// Vue (Automatic Reactivity)
32+
import { useVueStateless } from '@neabyte/stateless-js/vue'
33+
2834
// TypeScript types
2935
import type { StateSetter, StateValue } from '@neabyte/stateless-js'
3036
```
@@ -76,7 +82,28 @@ function Counter() {
7682
}
7783
```
7884

79-
### 🔄 State Sharing (Universal & React)
85+
### 🟢 Vue Usage
86+
87+
```typescript
88+
import { useVueStateless } from '@neabyte/stateless-js/vue'
89+
90+
export default {
91+
name: 'Counter',
92+
setup() {
93+
const [setCount, countValue] = useVueStateless('counter', 0)
94+
const count = computed(() => countValue.value)
95+
const increment = () => {
96+
setCount(current => current + 1)
97+
}
98+
return {
99+
count,
100+
increment
101+
}
102+
}
103+
}
104+
```
105+
106+
### 🔄 State Sharing (Universal, React & Vue)
80107

81108
```typescript
82109
// Universal
@@ -96,6 +123,28 @@ function UserEditor() {
96123
Increase Age
97124
</button>
98125
}
126+
127+
// Vue - Multiple components share the same state
128+
export default {
129+
name: 'UserProfile',
130+
setup() {
131+
const [setUser, userValue] = useVueStateless('user', { name: 'John', age: 25 })
132+
const user = computed(() => userValue.value)
133+
return { user }
134+
}
135+
}
136+
137+
export default {
138+
name: 'UserEditor',
139+
setup() {
140+
const [setUser, userValue] = useVueStateless('user', { name: 'Default', age: 0 })
141+
const user = computed(() => userValue.value)
142+
const increaseAge = () => {
143+
setUser(u => ({ ...u, age: u.age + 1 }))
144+
}
145+
return { user, increaseAge }
146+
}
147+
}
99148
```
100149

101150
### 🎯 Different Data Types
@@ -123,9 +172,17 @@ const [setBigInt, big] = createStateless('bigint', BigInt(123))
123172
### 🔧 Object Updates
124173

125174
```typescript
175+
// Universal
126176
const [setData, data] = createStateless('data', { count: 0, items: [] })
127177

128-
// Immutable updates
178+
// React
179+
const [setData, data] = useReactStateless('react-data', { count: 0, items: [] })
180+
181+
// Vue
182+
const [setData, dataRef] = useVueStateless('vue-data', { count: 0, items: [] })
183+
const data = computed(() => dataRef.value)
184+
185+
// Immutable updates work the same way
129186
setData(current => ({ ...current, count: current.count + 1 }))
130187
setData(current => ({ ...current, items: [...current.items, 'new item'] }))
131188
```
@@ -181,6 +238,16 @@ React hook that provides automatic re-renders when state changes.
181238
- `initialValue`: Initial value for the state
182239
- Returns: Tuple `[StateSetter<T>, T]` (direct value, not StateValue object)
183240

241+
### Vue Functions
242+
243+
#### `useVueStateless<T>(id: StateId, initialValue: T): [StateSetter<T>, Ref<T>]`
244+
245+
Vue composable that provides automatic reactivity when state changes.
246+
247+
- `id`: Unique identifier (string or number)
248+
- `initialValue`: Initial value for the state
249+
- Returns: Tuple `[StateSetter<T>, Ref<T>]` (reactive ref for Vue reactivity)
250+
184251
### Types
185252

186253
#### `StateSetter<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'],
16+
entries: ['src/index', 'src/react', 'src/vue'],
1717
/** @type {boolean} Whether to generate TypeScript declaration files */
1818
declaration: true,
1919
/** @type {boolean} Whether to clean the output directory before building */

package-lock.json

Lines changed: 193 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)