Skip to content

Commit 9dae51c

Browse files
committed
feat: initial
1 parent 2b3e1cb commit 9dae51c

25 files changed

+7496
-0
lines changed

.eslintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/dist/
2+
/coverage/
3+
/reports/
4+
/stryker-tmp/

.eslintrc.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
root: true,
3+
extends: ['@djaler/typescript'],
4+
parserOptions: {
5+
project: './tsconfig.lint.json',
6+
},
7+
settings: {
8+
'import/resolver': {
9+
typescript: {},
10+
},
11+
},
12+
};

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.js text eol=lf
2+
*.ts text eol=lf

.github/workflows/checks.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Checks
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Check out Git repository
15+
uses: actions/checkout@v2
16+
- name: Set up Node.js
17+
uses: actions/setup-node@v2
18+
with:
19+
node-version: 12
20+
- name: Install dependencies
21+
uses: pnpm/[email protected]
22+
with:
23+
version: 5
24+
run_install: true
25+
- name: Run build
26+
run: npm run build
27+
28+
lint:
29+
runs-on: ubuntu-latest
30+
31+
steps:
32+
- name: Check out Git repository
33+
uses: actions/checkout@v2
34+
- name: Set up Node.js
35+
uses: actions/setup-node@v2
36+
with:
37+
node-version: 12
38+
- name: Install dependencies
39+
uses: pnpm/[email protected]
40+
with:
41+
version: 5
42+
run_install: true
43+
- name: Run linter
44+
uses: samuelmeuli/lint-action@v1
45+
with:
46+
github_token: ${{ secrets.GITHUB_TOKEN }}
47+
eslint: true
48+
49+
test:
50+
runs-on: ubuntu-latest
51+
52+
steps:
53+
- name: Check out Git repository
54+
uses: actions/checkout@v2
55+
- name: Set up Node.js
56+
uses: actions/setup-node@v2
57+
with:
58+
node-version: 12
59+
- name: Install dependencies
60+
uses: pnpm/[email protected]
61+
with:
62+
version: 5
63+
run_install: true
64+
- name: Run tests
65+
uses: mattallty/[email protected]
66+
env:
67+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
68+
with:
69+
test-command: "npm run test"
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Mutation Test
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
7+
jobs:
8+
mutation-test:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Check out Git repository
13+
uses: actions/checkout@v2
14+
- name: Set up Node.js
15+
uses: actions/setup-node@v2
16+
with:
17+
node-version: 12
18+
- name: Install dependencies
19+
uses: pnpm/[email protected]
20+
with:
21+
version: 5
22+
run_install: true
23+
- name: Run Stryker
24+
run: npm run stryker -- --reporters dashboard --dashboard.reportType full
25+
env:
26+
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}

.github/workflows/release.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Check out Git repository
14+
uses: actions/checkout@v2
15+
- name: Set up Node.js
16+
uses: actions/setup-node@v2
17+
with:
18+
node-version: 12
19+
- name: Install dependencies
20+
uses: pnpm/[email protected]
21+
with:
22+
version: 5
23+
run_install: true
24+
- name: Publish package
25+
uses: JS-DevTools/npm-publish@v1
26+
with:
27+
token: ${{ secrets.NPM_TOKEN }}

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules/
2+
coverage/
3+
reports/
4+
dist/
5+
stryker-tmp/
6+
.idea/

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
shamefully-hoist=true

README.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
[![Mutation testing badge](https://img.shields.io/endpoint?style=for-the-badge&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2FDjaler%2Fvue-promise-dialogs%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/Djaler/vue-promise-dialogs/master)
2+
3+
# Vue Promise Dialogs
4+
5+
> A tiny & modern library that allows you to work with dialogs as with asynchronous functions.
6+
7+
## Why?
8+
9+
Because many dialogs work exactly as promises.
10+
They are opened (called) and then closed with some result (resolved) or canceled (rejected).
11+
12+
## Install
13+
14+
```sh
15+
npm install --save vue-promise-dialogs
16+
```
17+
18+
Or for a CDN version, you can use it on [unpkg.com](https://unpkg.com/vue-promise-dialogs)
19+
20+
## Usage
21+
22+
Main requirements:
23+
24+
1. You should mount exactly one `PromiseDialogsWrapper` somewhere in your application root.
25+
2. The dialog component should accept `params` props.
26+
3. The dialog component should emit `resolve` or `reject` events when the user makes a decision.
27+
28+
```ts
29+
import { createPromiseDialog } from "vue-promise-dialogs"
30+
31+
const BooleanDialog = Vue.extend({
32+
template: `
33+
<div class="dialog">
34+
<p>{{ params.text }}</p>
35+
<button name="true" @click="$emit('resolve', true)">True</button>
36+
<button name="false" @click="$emit('resolve', false)">False</button>
37+
<button name="cancel" @click="$emit('reject', 'cancel')">Cancel</button>
38+
</div>
39+
`,
40+
props: {
41+
params: {
42+
type: Object,
43+
required: true,
44+
},
45+
},
46+
});
47+
48+
// First type argument is the type of params prop that will be passed to component
49+
// Second type argument is the type of value with which the promise will be fulfilled
50+
const openDialog = createPromiseDialog<{ text: string }, boolean>(BooleanDialog);
51+
52+
// When you call this function, dialog will be mounted to `PromiseDialogsWrapper`.
53+
// When user press any button and resolve/reject event emitted, promise will be settled and dialog will be destroyed.
54+
const result: boolean = await openDialog({ text: 'Some text' });
55+
```
56+
57+
### Vue Class Component Example
58+
59+
If you're using Vue Class Component to define your dialog components, you can extend them from `BasePromiseDialog`.
60+
This will allow you to avoid defining type arguments in `createPromiseDialog`.
61+
`BasePromiseDialog` already defines `params` prop and methods `resolve`/`reject`, so you don't have to.
62+
63+
```ts
64+
import { Component } from "vue-class-component"
65+
import { BasePromiseDialog, createPromiseDialog } from "vue-promise-dialogs"
66+
67+
@Component({
68+
template: `
69+
<div class="dialog">
70+
<p>{{ params.text }}</p>
71+
<button name="true" @click="onTrue">True</button>
72+
<button name="false" @click="onFalse">False</button>
73+
<button name="cancel" @click="onCancel">Cancel</button>
74+
</div>
75+
`,
76+
})
77+
// You need to extend your component from BasePromiseDialog with correct type arguments
78+
class BooleanDialog extends BasePromiseDialog<{ text: string }, boolean> {
79+
onTrue() {
80+
this.resolve(true);
81+
}
82+
83+
onFalse() {
84+
this.resolve(true);
85+
}
86+
87+
onCancel() {
88+
this.reject('cancel');
89+
}
90+
}
91+
92+
// You don't have to specify type arguments because they are inferenced from BooleanDialog
93+
const openDialog = createPromiseDialog(BooleanDialog);
94+
95+
const result: boolean = await openDialog({ text: 'Some text' });
96+
```

jest.config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const { pathsToModuleNameMapper } = require('ts-jest/utils');
2+
const { compilerOptions } = require('./tsconfig');
3+
4+
module.exports = {
5+
preset: 'ts-jest/presets/js-with-ts',
6+
collectCoverageFrom: ['src/**'],
7+
moduleNameMapper: {
8+
...pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/' }),
9+
vue$: require.resolve('vue/dist/vue.common.js'),
10+
},
11+
testMatch: [
12+
'<rootDir>/tests/**/*.spec.ts',
13+
],
14+
};

0 commit comments

Comments
 (0)