Skip to content

Commit

Permalink
version 3.0.2 fix 92
Browse files Browse the repository at this point in the history
  • Loading branch information
Алексей Пивкин committed Feb 18, 2020
1 parent 0176451 commit f7f6fb3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-sweetalert2",
"version": "3.0.1",
"version": "3.0.2",
"description": "Simple Vue sweetalert2 package",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
28 changes: 10 additions & 18 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Vue from 'vue';

import {SweetAlertOptions} from 'sweetalert2';
import Swal from 'sweetalert2/dist/sweetalert2.js';
import Swal, {SweetAlertOptions} from 'sweetalert2';
import swalLocalInstance from 'sweetalert2/dist/sweetalert2.js';

type VueSwalInstance = typeof Swal.fire;

Expand All @@ -15,32 +15,24 @@ declare module 'vue/types/vue' {
}
}

interface VueSweetalert2Options extends SweetAlertOptions {
// includeCss?: boolean;
}

class VueSweetalert2 {
static install(vue: Vue | any, options?: VueSweetalert2Options): void {
const swalFunction = (...args: [SweetAlertOptions]) => {
if (options) {
const mixed = Swal.mixin(options);
static install(vue: Vue | any, options?: SweetAlertOptions): void {
const swalLocalInstance = options ? Swal.mixin(options) : Swal;

return mixed.fire.apply(mixed, args);
}

return Swal.fire.apply(Swal, args);
const swalFunction = (...args: [SweetAlertOptions]) => {
return swalLocalInstance.fire.apply(swalLocalInstance, args);
};

let methodName: string | number | symbol;

for (methodName in Swal) {
for (methodName in swalLocalInstance) {
if (
Object.prototype.hasOwnProperty.call(Swal, methodName) &&
typeof Swal[methodName] === 'function'
Object.prototype.hasOwnProperty.call(swalLocalInstance, methodName) &&
typeof swalLocalInstance[methodName] === 'function'
) {
swalFunction[methodName] = (method => {
return (...args: any[]) => {
return Swal[method].apply(Swal, args);
return swalLocalInstance[method].apply(swalLocalInstance, args);
};
})(methodName);
}
Expand Down

0 comments on commit f7f6fb3

Please sign in to comment.