All Projects → Djaler → vue-promise-dialogs

Djaler / vue-promise-dialogs

Licence: other
A tiny & modern library that allows you to work with dialogs as with asynchronous functions.

Programming Languages

typescript
32286 projects
Vue
7211 projects
javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to vue-promise-dialogs

promiviz
Visualize JavaScript Promises on the browser. Visualize the JavaScript Promise APIs and learn. It is a playground to learn about promises faster, ever!
Stars: ✭ 79 (+83.72%)
Mutual labels:  promises
Fetch
Asynchronous HTTP client with promises.
Stars: ✭ 29 (-32.56%)
Mutual labels:  promises
node-pg-large-object
Large object support for PostgreSQL clients using the node-postgres library.
Stars: ✭ 31 (-27.91%)
Mutual labels:  promises
bluff
🙏 Promise A+ implementation
Stars: ✭ 14 (-67.44%)
Mutual labels:  promises
alls
Just another library with the sole purpose of waiting till all promises to complete. Nothing more, Nothing less.
Stars: ✭ 13 (-69.77%)
Mutual labels:  promises
SimpleDialogs
💬 A simple framework to help displaying dialogs on a WPF app
Stars: ✭ 24 (-44.19%)
Mutual labels:  dialogs
ReactiveUI.Dialogs
ReactiveUI wrapper for Acr.UserDialogs
Stars: ✭ 13 (-69.77%)
Mutual labels:  dialogs
silly-android
Android plugins for Java, making core Android APIs easy to use
Stars: ✭ 40 (-6.98%)
Mutual labels:  dialogs
promisify-child-process
seriously like the best async child process library
Stars: ✭ 54 (+25.58%)
Mutual labels:  promises
Dam
Delphi and Lazarus Message Dialogs with Formatted Text
Stars: ✭ 85 (+97.67%)
Mutual labels:  dialogs
typescript-async
Creating Asynchronous Code with TypeScript
Stars: ✭ 44 (+2.33%)
Mutual labels:  promises
DialogHost.Avalonia
AvaloniaUI control that provides a simple way to display a dialog with information or prompt the user when information is needed
Stars: ✭ 92 (+113.95%)
Mutual labels:  dialogs
storage
Extend the Chrome Extension Storage API with Promises and great TypeScript support.
Stars: ✭ 48 (+11.63%)
Mutual labels:  promises
node-express-reddit-clone
Build a Node, Express and MySQL-based clone of Reddit for DecodeMTL web development bootcamp
Stars: ✭ 28 (-34.88%)
Mutual labels:  promises
aestheticDialogs
📱 Flutter Plugin for 💫fluid, 😍beautiful, 🎨custom Dialogs
Stars: ✭ 19 (-55.81%)
Mutual labels:  dialogs
Futures
Lightweight promises for iOS, macOS, tvOS, watchOS, and Linux
Stars: ✭ 59 (+37.21%)
Mutual labels:  promises
redux-reducer-async
Create redux reducers for async behaviors of multiple actions.
Stars: ✭ 14 (-67.44%)
Mutual labels:  promises
tsubaki
💮 Promisify with native promises
Stars: ✭ 18 (-58.14%)
Mutual labels:  promises
node-pagerduty
⛔️ DEPRECATED - PagerDuty v2 API Wrapper for Node
Stars: ✭ 19 (-55.81%)
Mutual labels:  promises
whatisnewdialog
An Android library for displaying a dialog where it presents new features in the app.
Stars: ✭ 22 (-48.84%)
Mutual labels:  dialogs

npm npm bundle size demo

Vue Promise Dialogs

A tiny & modern library that allows you to work with dialogs as with asynchronous functions.

Why?

Because many dialogs work exactly as promises. They are opened (called) and then closed with some result (resolved) or canceled (rejected).

Install

From version 2.0.0 it works for Vue 2 and Vue 3 within a single package by the power of vue-demi 🔥

Vue 3

npm install vue-promise-dialogs

Vue 2

npm install vue-promise-dialogs @vue/composition-api

Usage

Main requirements:

  1. You should mount exactly one PromiseDialogsWrapper somewhere in your application root.
  2. The dialog component should accept params props.
  3. The dialog component should emit resolve or reject events when the user makes a decision.
import { createPromiseDialog } from "vue-promise-dialogs"

interface BooleanDialogParams {
    text: string;
}

const BooleanDialog = defineComponent({
    template: `
      <div class="dialog">
          <p>{{ params.text }}</p>
          <button name="true" @click="$emit('resolve', true)">True</button>
          <button name="false" @click="$emit('resolve', false)">False</button>
          <button name="cancel" @click="$emit('reject', 'cancel')">Cancel</button>
      </div>
    `,
    props: {
        params: {
            type: Object as PropType<BooleanDialogParams>,
            required: true,
        },
    },
});

// First type argument is the type of params prop that will be passed to component
// Second type argument is the type of value with which the promise will be fulfilled
const openDialog = createPromiseDialog<BooleanDialogParams, boolean>(BooleanDialog);

// When you call this function, dialog will be mounted to `PromiseDialogsWrapper`.
// When user press any button and resolve/reject event emitted, promise will be settled and dialog will be destroyed.
const result: boolean = await openDialog({ text: 'Some text' });

Unmount delay

By default, a dialog is unmounted immediately right after resolve/reject, but maybe you want to change this behaviour, for example, to play the close animation.

You have two options here:

  1. Specify the unmount delay (in ms) using unmountDelay prop in PromiseDialogsWrapper.
  2. Specify the unmount delay (in ms) as a second argument when emitting resolve/reject event. This option will override unmountDelay prop if both are provided.

Close all

In some cases you may want to close all opened dialogs. For example, on route change.

You can use closeAllDialogs for this. All you need is to set a reason, which will be used in promises reject.

TODO

  • Fallback to mount dialogs without PromiseDialogsWrapper
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].