forked from Fuphoenixes/piniaPluginLoading
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nicholas Marshall
committed
Jun 3, 2022
1 parent
486ee45
commit e0ab9a3
Showing
6 changed files
with
2,104 additions
and
349 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
node_modules | ||
dist | ||
.idea | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { PiniaPluginContext } from 'pinia'; | ||
import { Ref } from 'vue-demi'; | ||
|
||
declare function PiniaLoading({ options, store }: PiniaPluginContext): void; | ||
declare module 'pinia' { | ||
interface PiniaCustomProperties<Id, S, G, A> { | ||
$loading: { | ||
[K in keyof A as A[K] extends () => Promise<any> ? K : never]: Ref<Boolean>; | ||
}; | ||
} | ||
} | ||
|
||
export { PiniaLoading }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
|
||
// src/index.ts | ||
var src_exports = {}; | ||
__export(src_exports, { | ||
PiniaLoading: () => PiniaLoading | ||
}); | ||
module.exports = __toCommonJS(src_exports); | ||
var import_vue_demi = require("vue-demi"); | ||
function PiniaLoading({ options, store }) { | ||
if (options.actions) { | ||
const $loading = {}; | ||
Object.keys(options.actions).forEach((actionKey) => { | ||
const originAction = options.actions[actionKey]; | ||
const action = function(...args) { | ||
const rtn = originAction.apply(this, args); | ||
if (rtn instanceof Promise) { | ||
$loading[actionKey] = (0, import_vue_demi.ref)(false); | ||
return new Promise((resolve, reject) => { | ||
$loading[actionKey].value = true; | ||
rtn.then(resolve).catch(reject).finally(() => { | ||
$loading[actionKey].value = false; | ||
}); | ||
}); | ||
} else { | ||
return rtn; | ||
} | ||
}; | ||
store[actionKey] = action; | ||
}); | ||
store.$loading = $loading; | ||
} | ||
} | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
PiniaLoading | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// src/index.ts | ||
import { ref } from "vue-demi"; | ||
function PiniaLoading({ options, store }) { | ||
if (options.actions) { | ||
const $loading = {}; | ||
Object.keys(options.actions).forEach((actionKey) => { | ||
const originAction = options.actions[actionKey]; | ||
const action = function(...args) { | ||
const rtn = originAction.apply(this, args); | ||
if (rtn instanceof Promise) { | ||
$loading[actionKey] = ref(false); | ||
return new Promise((resolve, reject) => { | ||
$loading[actionKey].value = true; | ||
rtn.then(resolve).catch(reject).finally(() => { | ||
$loading[actionKey].value = false; | ||
}); | ||
}); | ||
} else { | ||
return rtn; | ||
} | ||
}; | ||
store[actionKey] = action; | ||
}); | ||
store.$loading = $loading; | ||
} | ||
} | ||
export { | ||
PiniaLoading | ||
}; |
Oops, something went wrong.