Skip to content

Commit

Permalink
chore(#4): shared composable extending (#5)
Browse files Browse the repository at this point in the history
* chore(#4): initial implementation of composable extending

* chore(#4): ci node version update

* chore(#4): lock files updated

* chore(#4): dependencies update

* chore(#4): rollup config update

* docs(#4): corrects, updates

* chore(#4): types redefined
  • Loading branch information
lukasborawski authored Jan 8, 2025
1 parent f2a3edb commit 5561106
Show file tree
Hide file tree
Showing 45 changed files with 14,243 additions and 13,905 deletions.
216 changes: 126 additions & 90 deletions .github/README.md

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions .github/issue_template.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
**Description**:
---
Some issue description.
Issue description should be here.

**Tasks**:
---
- [ ] task name

**Research**:
---
None
*None*

**Screenshots**:
---
None
*None*
7 changes: 4 additions & 3 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<!--- Please crate an issue if this PR is not connected with anyone. --->

<!--- Example - Closing: #10 --->
Closing: #[issue number]

**Tasks**:
**Todo**:
---
* [ ] issue connected
* [ ] summary
* [ ] self review
* [ ] issue todos
* [ ] issue todos done

**Summary**:
---
*Write here some summary.*
*Write here summary of changes.*
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node: [14]
node: [20]

steps:
- name: Checkout 🛎
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ dist

# IDE / Editor
.idea
.vscode
.history

# Service worker
sw.*
Expand All @@ -95,8 +97,10 @@ sw.*
.reify-cache
**/**/.reify-cache

# Dist
lib
.husky/_

# Test generations
package
vue-use-state-effect/
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20.17.0
2 changes: 2 additions & 0 deletions BACKLOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
### Missing features, things to do:

- [ ] history tracking
- [ ] state reset
- [ ] cached multi-state / threads
- [ ] docs on Nuxt Content
- [ ] Q&A section

### Done:

- [x] extending - `0.1.5`
- [x] destroying destination - `0.1.2`
- [x] unit tests - `0.1.0`
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
### 0.1.5 (10.01.2025)

- [**feature**] addons/extending ([#5](https://github.com/lukasborawski/vue-use-state-effect/pull/5))
- updated dependencies
- removed Vue demo, **Nuxt** demo became default
- Nuxt demo update
- fresh version of the framework
- composables updated to showcase extending
- docs update
- Typescript version bump to `^5`
- Node version bump to `^20`

### 0.1.4 (25.10.2022)

- removed unnecessary lib build
- removed doubled `getCurrentInstanc` check
- removed doubled `getCurrentInstance` check

### 0.1.2 (09.06.2022)

Expand Down
38 changes: 9 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
## Vue Use State Effect

**CAUTION**: Built and tested for/with **Vue 3** and/or **Nuxt 3** (RC-12).
**CAUTION**: Built and tested with **Nuxt 3.15**.

Fast and small library, built on top of the native `scopeEffect` **Vue 3 API** that will provide safe and sharable (across the app) state for your local composables and functions. It might be a good replacement for **Vuex** or **Pinia** state management, if you need smaller and less extensive solution.
Fast and lightweight library (composable) that utilizes the native `EffectScope` **Vue 3 API**. It is designed to offer secure and shareable (across the app) state for your local composables and functions. It can serve as a viable replacement or alternative to **Vuex** or **Pinia** state management, particularly if you require a smaller and less extensive solution.

**Check out the Stackblitz Nuxt 3 demo [here](https://stackblitz.com/edit/vue-use-state-effect-demo).** 🚀
**Check out the Stackblitz Nuxt demo [here](https://stackblitz.com/edit/vue-use-state-effect-demo).** 🚀

### Motivation / Story

Expand Down Expand Up @@ -35,32 +35,12 @@ Create local composable with some state and pass it to the `useStateEffect`.
```javascript
import { useStateEffect } from 'vue-use-state-effect'

const composable = () => {
/* your composable logic here */
}

export const useSharedComposable = useStateEffect(composable, { ...config })
```

Interface (**TypeScript**).

```typescript
interface UseStateEffectConfig {
readonly name?: string | null
readonly destroy?: boolean | 'custom'
readonly debug?: boolean
}
export type UseStateEffectOptions<T = any> = {
readonly destroyLabels: string[]
readonly props: ExtractPropTypes<{ stateEffectDestroyLabel: string } | T>
}

export function useStateEffect<T extends (...args: any[]) => ReturnType<T>>(
composable: T,
config?: UseStateEffectConfig,
): (opts?: UseStateEffectOptions<opts.props>) => {
[keyof in string | 'state']: ReturnType<T>
}
export const sharedComposable = useStateEffect(
(...args) => {
/* your composable logic here */
},
{ ...config },
)
```

Please check the configuration, all the details and examples [here](https://github.com/lukasborawski/vue-use-state-effect).
Expand Down
11 changes: 10 additions & 1 deletion __tests__/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useStateEffect } from '~/lib/index.cjs'
import { useStateEffect } from '~/lib/index.js'
import { ref, getCurrentInstance } from 'vue'

const config = {
Expand Down Expand Up @@ -75,6 +75,15 @@ describe('vue-use-state-effect', () => {
const receivedState = useStateEffect(composableMock)()
expect(JSON.stringify(receivedState)).toMatch('_syg')
})
it('returns state with addons', () => {
const receivedState = useStateEffect((...args) => {
const [options] = args
return {
state: { test: options.addons.test },
}
})({ addons: { test: 'test' } })
expect(receivedState).toEqual({ state: { _syg: 'StateEffect', _uid: 1, state: { test: 'test' } } })
})
})

describe('was invoked with config and', () => {
Expand Down
23 changes: 0 additions & 23 deletions demo-nuxt/composables/useSharedFetch.ts

This file was deleted.

19 changes: 0 additions & 19 deletions demo-nuxt/composables/useSharedState.ts

This file was deleted.

8 changes: 0 additions & 8 deletions demo-nuxt/nuxt.config.ts

This file was deleted.

Loading

0 comments on commit 5561106

Please sign in to comment.