baseProvider.ts 886 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import {hooks} from "~/services/dataProvider/provider/hook/_import";
  2. import {DataProviderArgs} from "~/types/interfaces";
  3. import {Context} from "@nuxt/types/app";
  4. class BaseProvider{
  5. protected arguments!: DataProviderArgs;
  6. protected ctx!: Context;
  7. constructor(ctx: Context, args: DataProviderArgs) {
  8. this.arguments = args
  9. this.ctx = ctx
  10. this.sortHook()
  11. }
  12. static support(args:DataProviderArgs): boolean{
  13. throw new Error('Need to be implement into static method')
  14. }
  15. async postHook(){
  16. for(const hook of hooks){
  17. if(hook.support(this.arguments)){
  18. await new hook().invoke(this.arguments);
  19. }
  20. }
  21. }
  22. sortHook(){
  23. hooks.sort(function(a, b) {
  24. if (a.priority > b.priority) {
  25. return 1;
  26. }
  27. if (a.priority < b.priority) {
  28. return -1;
  29. }
  30. return 0;
  31. });
  32. }
  33. }
  34. export default BaseProvider