| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- import {hooks} from "~/services/dataProvider/provider/hook/_import";
- import {DataProviderArgs} from "~/types/interfaces";
- import {Context} from "@nuxt/types/app";
- class BaseProvider{
- protected arguments!: DataProviderArgs;
- protected ctx!: Context;
- constructor(ctx: Context, args: DataProviderArgs) {
- this.arguments = args
- this.ctx = ctx
- this.sortHook()
- }
- static support(args:DataProviderArgs): boolean{
- throw new Error('Need to be implement into static method')
- }
- async postHook(){
- for(const hook of hooks){
- if(hook.support(this.arguments)){
- await new hook().invoke(this.arguments);
- }
- }
- }
- sortHook(){
- hooks.sort(function(a, b) {
- if (a.priority > b.priority) {
- return 1;
- }
- if (a.priority < b.priority) {
- return -1;
- }
- return 0;
- });
- }
- }
- export default BaseProvider
|