@goldfishjs/plugins
Advanced tools
Comparing version 0.0.9 to 0.0.10
@@ -0,7 +1,101 @@ | ||
import _observable from "@goldfishjs/reactive-connect/lib/decorators/observable"; | ||
import _state from "@goldfishjs/reactive-connect/lib/decorators/state"; | ||
import _regeneratorRuntime from "@babel/runtime/regenerator"; | ||
import _watch from "@goldfishjs/reactive/lib/watch"; | ||
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/createClass"; | ||
import _typeof from "@babel/runtime/helpers/typeof"; | ||
var Plugin = function Plugin() { | ||
_classCallCheck(this, Plugin); | ||
var __decorate = this && this.__decorate || function (decorators, target, key, desc) { | ||
var c = arguments.length, | ||
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, | ||
d; | ||
if ((typeof Reflect === "undefined" ? "undefined" : _typeof(Reflect)) === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) { | ||
if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
} | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
}; | ||
export { Plugin as default }; | ||
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { | ||
return value instanceof P ? value : new P(function (resolve) { | ||
resolve(value); | ||
}); | ||
} | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { | ||
try { | ||
step(generator.next(value)); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
} | ||
function rejected(value) { | ||
try { | ||
step(generator["throw"](value)); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
} | ||
function step(result) { | ||
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); | ||
} | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var Plugin = | ||
/*#__PURE__*/ | ||
function () { | ||
function Plugin() { | ||
_classCallCheck(this, Plugin); | ||
this.isInitCompleted = false; | ||
} | ||
_createClass(Plugin, [{ | ||
key: "waitForEverythingReady", | ||
value: function waitForEverythingReady() { | ||
return __awaiter(this, void 0, void 0, | ||
/*#__PURE__*/ | ||
_regeneratorRuntime.mark(function _callee() { | ||
var _this = this; | ||
return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
return _context.abrupt("return", new Promise(function (resolve) { | ||
var stop = _watch(function () { | ||
return _this.isInitCompleted; | ||
}, function (v) { | ||
if (v) { | ||
resolve(); | ||
stop(); | ||
} | ||
}, { | ||
immediate: true | ||
}); | ||
})); | ||
case 1: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
} | ||
}]); | ||
return Plugin; | ||
}(); | ||
__decorate([_state], Plugin.prototype, "isInitCompleted", void 0); | ||
Plugin = __decorate([_observable], Plugin); | ||
export default Plugin; |
@@ -67,2 +67,20 @@ import _observable from "@goldfishjs/reactive-connect/lib/decorators/observable"; | ||
}, { | ||
key: "waitForReady", | ||
value: function waitForReady() { | ||
var _this = this; | ||
return new Promise(function (resolve) { | ||
var stop = _watch(function () { | ||
return _this.isReady(); | ||
}, function (newVal) { | ||
if (newVal) { | ||
resolve(); | ||
stop(); | ||
} | ||
}, { | ||
immediate: true | ||
}); | ||
}); | ||
} | ||
}, { | ||
key: "register", | ||
@@ -73,4 +91,2 @@ value: function register(pluginClass) { | ||
_regeneratorRuntime.mark(function _callee() { | ||
var _this = this; | ||
var plugin; | ||
@@ -93,29 +109,21 @@ return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
if (!(this.state === 'init_start')) { | ||
_context.next = 6; | ||
_context.next = 10; | ||
break; | ||
} | ||
return _context.abrupt("return", new Promise(function (resolve, reject) { | ||
var stop = _watch(function () { | ||
return _this.state; | ||
}, function (newVal) { | ||
if (newVal === 'ready') { | ||
try { | ||
plugin.init(_this.get.bind(_this)); | ||
resolve(); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
_context.next = 7; | ||
return this.waitForReady(); | ||
stop(); | ||
} | ||
}); | ||
})); | ||
case 7: | ||
plugin.init(this.get.bind(this)); | ||
plugin.isInitCompleted = true; | ||
return _context.abrupt("return"); | ||
case 6: | ||
case 10: | ||
if (this.state === 'ready') { | ||
plugin.init(this.get.bind(this)); | ||
plugin.isInitCompleted = true; | ||
} | ||
case 7: | ||
case 11: | ||
case "end": | ||
@@ -167,3 +175,3 @@ return _context.stop(); | ||
if ((_context2.t1 = _context2.t0()).done) { | ||
_context2.next = 9; | ||
_context2.next = 10; | ||
break; | ||
@@ -178,9 +186,10 @@ } | ||
case 7: | ||
plugin.isInitCompleted = true; | ||
_context2.next = 2; | ||
break; | ||
case 9: | ||
case 10: | ||
this.state = 'ready'; | ||
case 10: | ||
case 11: | ||
case "end": | ||
@@ -187,0 +196,0 @@ return _context2.stop(); |
@@ -81,7 +81,30 @@ import _regeneratorRuntime from "@babel/runtime/regenerator"; | ||
value: function request(url, data, options) { | ||
if (!this.requester) { | ||
throw new Error('The requester is not ready.'); | ||
} | ||
return __awaiter(this, void 0, void 0, | ||
/*#__PURE__*/ | ||
_regeneratorRuntime.mark(function _callee2() { | ||
return _regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
_context2.next = 2; | ||
return this.waitForEverythingReady(); | ||
return this.requester.request(url, data, options); | ||
case 2: | ||
if (this.requester) { | ||
_context2.next = 4; | ||
break; | ||
} | ||
throw new Error('The requester is not ready.'); | ||
case 4: | ||
return _context2.abrupt("return", this.requester.request(url, data, options)); | ||
case 5: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2, this); | ||
})); | ||
} | ||
@@ -88,0 +111,0 @@ }, { |
{ | ||
"name": "@goldfishjs/plugins", | ||
"version": "0.0.9", | ||
"version": "0.0.10", | ||
"description": "goldfish-plugins", | ||
@@ -19,8 +19,8 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@goldfishjs/bridge": "^0.0.9", | ||
"@goldfishjs/reactive": "^0.0.9", | ||
"@goldfishjs/reactive-connect": "^0.0.9", | ||
"@goldfishjs/requester": "^0.0.9", | ||
"@goldfishjs/route": "^0.0.9", | ||
"@goldfishjs/utils": "^0.0.9", | ||
"@goldfishjs/bridge": "^0.0.10", | ||
"@goldfishjs/reactive": "^0.0.10", | ||
"@goldfishjs/reactive-connect": "^0.0.10", | ||
"@goldfishjs/requester": "^0.0.10", | ||
"@goldfishjs/route": "^0.0.10", | ||
"@goldfishjs/utils": "^0.0.10", | ||
"mini-types": "^0.0.4" | ||
@@ -27,0 +27,0 @@ }, |
@@ -0,1 +1,4 @@ | ||
import { watch } from '@goldfishjs/reactive'; | ||
import { observable, state } from '@goldfishjs/reactive-connect'; | ||
export type PluginClass<P extends Plugin = Plugin> = { | ||
@@ -8,7 +11,28 @@ new (): P; | ||
@observable | ||
export default abstract class Plugin { | ||
public static readonly type: string; | ||
@state | ||
public isInitCompleted: boolean = false; | ||
public async waitForEverythingReady() { | ||
return new Promise((resolve) => { | ||
const stop = watch( | ||
() => this.isInitCompleted, | ||
(v) => { | ||
if (v) { | ||
resolve(); | ||
stop(); | ||
} | ||
}, | ||
{ | ||
immediate: true, | ||
}, | ||
); | ||
}); | ||
} | ||
public abstract async init(getPlugin: GetPlugin): Promise<void>; | ||
public abstract destroy(): void; | ||
} |
@@ -16,2 +16,19 @@ import { state, observable } from '@goldfishjs/reactive-connect'; | ||
public waitForReady() { | ||
return new Promise((resolve) => { | ||
const stop = watch( | ||
() => this.isReady(), | ||
(newVal) => { | ||
if (newVal) { | ||
resolve(); | ||
stop(); | ||
} | ||
}, | ||
{ | ||
immediate: true, | ||
}, | ||
); | ||
}); | ||
} | ||
public async register(pluginClass: PluginClass) { | ||
@@ -26,18 +43,6 @@ if (!pluginClass.type) { | ||
if (this.state === 'init_start') { | ||
return new Promise((resolve, reject) => { | ||
const stop = watch( | ||
() => this.state, | ||
(newVal) => { | ||
if (newVal === 'ready') { | ||
try { | ||
plugin.init(this.get.bind(this)); | ||
resolve(); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
stop(); | ||
} | ||
}, | ||
); | ||
}); | ||
await this.waitForReady(); | ||
plugin.init(this.get.bind(this)); | ||
plugin.isInitCompleted = true; | ||
return; | ||
} | ||
@@ -47,2 +52,3 @@ | ||
plugin.init(this.get.bind(this)); | ||
plugin.isInitCompleted = true; | ||
} | ||
@@ -76,2 +82,3 @@ } | ||
await plugin.init(this.get.bind(this)); | ||
plugin.isInitCompleted = true; | ||
} | ||
@@ -78,0 +85,0 @@ this.state = 'ready'; |
@@ -16,3 +16,3 @@ import Plugin, { GetPlugin } from './Plugin'; | ||
public request<R>( | ||
public async request<R>( | ||
url: IRequestOptions['url'], | ||
@@ -22,2 +22,3 @@ data?: IRequestOptions['data'], | ||
) { | ||
await this.waitForEverythingReady(); | ||
if (!this.requester) { | ||
@@ -24,0 +25,0 @@ throw new Error('The requester is not ready.'); |
@@ -8,4 +8,6 @@ export declare type PluginClass<P extends Plugin = Plugin> = { | ||
static readonly type: string; | ||
isInitCompleted: boolean; | ||
waitForEverythingReady(): Promise<unknown>; | ||
abstract init(getPlugin: GetPlugin): Promise<void>; | ||
abstract destroy(): void; | ||
} |
@@ -6,3 +6,4 @@ import Plugin, { PluginClass } from './Plugin'; | ||
isReady(): boolean; | ||
register(pluginClass: PluginClass): Promise<unknown>; | ||
waitForReady(): Promise<unknown>; | ||
register(pluginClass: PluginClass): Promise<void>; | ||
get<R extends Plugin>(pluginClass: PluginClass<R> | string): R; | ||
@@ -9,0 +10,0 @@ init(): Promise<void>; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
63366
1823
+ Added@goldfishjs/bridge@0.0.10(transitive)
+ Added@goldfishjs/reactive@0.0.10(transitive)
+ Added@goldfishjs/reactive-connect@0.0.10(transitive)
+ Added@goldfishjs/requester@0.0.10(transitive)
+ Added@goldfishjs/route@0.0.10(transitive)
+ Added@goldfishjs/utils@0.0.10(transitive)
- Removed@goldfishjs/bridge@0.0.9(transitive)
- Removed@goldfishjs/reactive@0.0.9(transitive)
- Removed@goldfishjs/reactive-connect@0.0.9(transitive)
- Removed@goldfishjs/requester@0.0.9(transitive)
- Removed@goldfishjs/route@0.0.9(transitive)
- Removed@goldfishjs/utils@0.0.9(transitive)
Updated@goldfishjs/bridge@^0.0.10
Updated@goldfishjs/reactive@^0.0.10
Updated@goldfishjs/route@^0.0.10
Updated@goldfishjs/utils@^0.0.10