Skip to content

Commit ed2e91d

Browse files
authored
Merge pull request #77 from InhiblabCore/dev
feat: add new package use-immer@1.0.0
2 parents 427a18c + cd01466 commit ed2e91d

File tree

14 files changed

+258
-22
lines changed

14 files changed

+258
-22
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ jobs:
2121
- name: Test
2222
run: |
2323
pnpm run test
24+
- name: use-immer Build
25+
run: |
26+
cd packages/use-immer
27+
pnpm build
2428
- name: Docs-Build
2529
run: |
2630
cd packages/hooks

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030
"@types/marked": "^4.0.3",
3131
"@types/node": "^17.0.21",
3232
"@types/qs": "^6.9.7",
33-
"@types/markdown-it": "^12.2.3",
3433
"@vitejs/plugin-vue": "^2.3.1",
3534
"@vue-hooks-plus/vite-plugin-gen-temp": "2.6.2",
3635
"@vue-hooks-plus/md-demo-plugins": "^1.0.0",
3736
"@vue-hooks-plus/vitepress": "1.2.3",
3837
"@vue-hooks-plus/vitepress-demo-block": "^1.3.1",
38+
"@vue-hooks-plus/use-immer":"workspace:^1.0.0",
3939
"@vue/test-utils": "^2.1.0",
4040
"@vitest/coverage-c8":"^0.25.7",
4141
"eslint": "^8.20.0",
@@ -44,7 +44,6 @@
4444
"eslint-plugin-vue": "^9.6.0",
4545
"husky": "^8.0.1",
4646
"lint-staged": "^13.0.3",
47-
"markdown-it": "^13.0.1",
4847
"vue-eslint-parser": "^9.0.3",
4948
"cross-env": "^7.0.3",
5049
"fast-glob": "^3.2.12",

packages/hooks/docs/.vitepress/router.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const Router = [
33
text: 'State',
44
items: [
55
{ text: 'useBoolean', link: '/useBoolean/' },
6+
{ text: 'useImmer', link: '/useImmer/' },
67
{ text: 'useUrlState', link: '/useUrlState/' },
78
{ text: 'useFormatResult', link: '/useFormatResult/' },
89
{ text: 'useDebounce', link: '/useDebounce/' },

packages/hooks/docs/.vitepress/theme/var.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
--vp-font-color: rgba(41, 65, 86, 1);
1515
// --vp-c-text-code: var(--vp-c-brand);
1616

17-
--vhp-func-bg: rgba(0, 0, 0, 0.08);
17+
--vhp-func-bg: rgba(0, 0, 0, 0.03);
1818

1919
--vhp-getstart-bg: linear-gradient(
2020
286deg,
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<template>
2+
<h3>function updater</h3>
3+
<ul>
4+
<li
5+
v-for="({ title, done }, index) in items"
6+
:class="{ done }"
7+
:key="title"
8+
@click="toggleItem(index)"
9+
>
10+
{{ title }}
11+
</li>
12+
</ul>
13+
<h3> no function updater</h3>
14+
<div>
15+
<vhp-button @click="setTitle">Set index 0 title</vhp-button>
16+
<vhp-button @click="reset" style="margin-left:8px">Reset</vhp-button>
17+
</div>
18+
</template>
19+
20+
<script lang="ts" setup>
21+
import { useImmer } from '@vue-hooks-plus/use-immer'
22+
23+
const init = [
24+
{
25+
title: 'Learn Vue',
26+
done: true,
27+
},
28+
{
29+
title: 'Use Vue with Immer',
30+
done: false,
31+
},
32+
]
33+
const [items, updateItems] = useImmer(init)
34+
35+
function toggleItem(index: number) {
36+
updateItems(items => {
37+
items[index].done = !items[index].done
38+
})
39+
}
40+
41+
const setTitle = () => {
42+
updateItems([
43+
{
44+
title: 'Learn Vue 1',
45+
done: false,
46+
},
47+
])
48+
}
49+
50+
const reset = () => {
51+
updateItems(init)
52+
}
53+
</script>
54+
55+
<style>
56+
.done {
57+
text-decoration: line-through;
58+
}
59+
</style>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
map:
3+
# 映射到docs的路径
4+
path: /useImmer
5+
---
6+
7+
# useImmer
8+
9+
A hook to use [immer](https://github.com/mweststrate/immer) as a Vue hook to manipulate state.
10+
11+
## Install
12+
13+
```bash
14+
15+
npm i @vue-hooks-plus/use-immer
16+
17+
```
18+
19+
> The `hook` is based on `immer` management status, `immer` will be installed to ensure normal work in the project
20+
21+
> Independent installation `@vue-hooks-plus/use-immer`
22+
23+
## Basic Usage
24+
25+
<demo src="./demo/demo.vue"
26+
language="vue"
27+
title="basic Usage"
28+
desc=""> </demo>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
map:
3+
# 映射到docs的路径
4+
path: /useImmer
5+
---
6+
7+
# useImmer
8+
9+
一个使用 [immer](https://github.com/mweststrate/immer) 操作状态的 hook。
10+
11+
## 安装
12+
13+
```bash
14+
15+
npm i @vue-hooks-plus/use-immer
16+
17+
```
18+
19+
> `hook` 基于 `immer` 管理状态,会安装 `immer`保证在项目中正常工作
20+
21+
> 独立安装 `@vue-hooks-plus/use-immer`
22+
23+
## 基本用法
24+
25+
<demo src="./demo/demo.vue"
26+
language="vue"
27+
title="基本用法"
28+
desc=""> </demo>

packages/use-immer/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 YongGit
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

packages/use-immer/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# useImmer
2+
3+
A hook to use [immer](https://github.com/mweststrate/immer) as a Vue hook to manipulate state.
4+
5+
## Install
6+
7+
```bash
8+
9+
npm i @vue-hooks-plus/use-immer
10+
11+
```
12+
13+
> The `hook` is based on `immer` management status, `immer` will be installed to ensure normal work in the project
14+
15+
> Independent installation `@vue-hooks-plus/use-immer`

packages/use-immer/package.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "@vue-hooks-plus/use-immer",
3+
"version": "1.0.0",
4+
"description": "Vue use-immer hooks library",
5+
"files": [
6+
"dist",
7+
"LICENSE",
8+
"package.json",
9+
"README.md"
10+
],
11+
"main": "./dist/useImmer.cjs.js",
12+
"module": "./dist/useImmer.es.js",
13+
"types":"./dist/types/index.d.ts" ,
14+
"scripts": {
15+
"build": "vite build"
16+
},
17+
"keywords": [],
18+
"dependencies": {
19+
"immer": "^9.0.17"
20+
},
21+
"repository": "https://github.com/InhiblabCore/vue-hooks-plus",
22+
"homepage": "https://github.com/InhiblabCore/vue-hooks-plus",
23+
"author": "NelsonYong",
24+
"license": "MIT"
25+
}

0 commit comments

Comments
 (0)