Skip to content

Commit 942f1af

Browse files
committed
npm init, setup boilerplates, gReactive and whenRouteChange
0 parents  commit 942f1af

File tree

9 files changed

+3099
-0
lines changed

9 files changed

+3099
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
dist
3+
.vscode/*
4+
!.vscode/settings.json
5+
!.vscode/extensions.json

.vscode/extensions.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"recommendations": [
3+
"dbaeumer.vscode-eslint",
4+
]
5+
}

.vscode/settings.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"editor.tabSize": 2,
3+
"editor.formatOnSave": false,
4+
"editor.codeActionsOnSave": {
5+
"source.fixAll.eslint": "always",
6+
},
7+
"eslint.validate": [
8+
"javascript",
9+
"typescript"
10+
],
11+
"prettier.enable": false,
12+
"files.eol": "\n"
13+
}

README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# vue-utils
2+
3+
Useful utilities for Vue projects.
4+
5+
[![npm (scoped)](https://img.shields.io/npm/v/@gradin/vue-utils)](https://www.npmjs.com/package/@gradin/vue-utils)
6+
![npm bundle size (scoped)](https://img.shields.io/bundlephobia/min/@gradin/vue-utils)
7+
![npm](https://img.shields.io/npm/dt/@gradin/vue-utils)
8+
9+
## Installation
10+
11+
```sh
12+
# Using npm
13+
npm install @gradin/vue-utils
14+
15+
# Using Yarn
16+
yarn add @gradin/vue-utils
17+
```
18+
19+
## Featurs
20+
21+
### Improved Vue Reactive
22+
23+
The `gReactive` function is a wrapper around Vue's `reactive` function that adds some useful features.
24+
- **Reset**: The `reset` method resets the reactive object to its initial state.
25+
- **Set**: The `set` method sets the reactive object to a new value, merging the new value with the existing value.
26+
27+
Example `reactive` vs `gReactive`
28+
29+
<details>
30+
<summary>Show Codes</summary>
31+
32+
```typescript
33+
// before
34+
import { reactive } from 'vue';
35+
const form = reactive({
36+
name: '',
37+
sku: '',
38+
description: '',
39+
price: 0,
40+
category_id: <number|null> null,
41+
})
42+
43+
const resetForm = () => {
44+
form.name = '';
45+
form.sku = '';
46+
form.description = '';
47+
form.price = 0;
48+
form.category_id = null;
49+
}
50+
51+
const setFormForUpdate = (product: Product) => {
52+
form.name = product.name;
53+
form.sku = product.sku;
54+
form.description = product.description;
55+
form.price = product.price;
56+
form.category_id = product.category_id;
57+
}
58+
59+
const submitForm = () => {
60+
axios.post('/api/products', form)
61+
.then(response => {
62+
// handle success
63+
})
64+
}
65+
66+
// after
67+
import { gReactive } from '@gradin/vue-utils';
68+
const form = gReactive({ // almost the same as vue reactive
69+
name: '',
70+
sku: '',
71+
description: '',
72+
price: 0,
73+
category_id: <number|null> null,
74+
})
75+
form.reset(); // reset the form
76+
form.set(product); // set the form for update
77+
78+
const submitForm = () => { // exactly the same as before
79+
axios.post('/api/products', form)
80+
.then(response => {
81+
// handle success
82+
})
83+
}
84+
```
85+
</details>

eslint.config.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import js from '@eslint/js'
2+
import simpleImportSort from 'eslint-plugin-simple-import-sort'
3+
import ts from 'typescript-eslint'
4+
5+
export default [
6+
{ ignores: ['node_modules', 'dist'] },
7+
8+
// js
9+
js.configs.recommended,
10+
{
11+
rules: {
12+
'no-undef': 'off',
13+
},
14+
},
15+
16+
// ts
17+
...ts.configs.recommended,
18+
{
19+
rules: {
20+
'@typescript-eslint/no-explicit-any': 'error', // https://typescript-eslint.io/rules/no-explicit-any/
21+
'@typescript-eslint/no-unused-vars': 'warn', // https://typescript-eslint.io/rules/no-unused-vars/
22+
},
23+
},
24+
25+
// simple import sort
26+
{
27+
plugins: {
28+
'simple-import-sort': simpleImportSort,
29+
},
30+
rules: {
31+
'simple-import-sort/imports': ['warn', {
32+
'groups': [['^\\u0000', '^node:', '^@?\\w', '^', '^\\.']], // remove blank lines between import group
33+
}],
34+
'simple-import-sort/exports': 'error',
35+
},
36+
},
37+
]

0 commit comments

Comments
 (0)