mirror of
https://github.com/swc-project/swc.git
synced 2024-12-29 16:42:28 +03:00
75 lines
1.2 KiB
TypeScript
75 lines
1.2 KiB
TypeScript
|
// @allowJs: true
|
||
|
// @checkJs: true
|
||
|
// @target: es5
|
||
|
// @outDir: ./out
|
||
|
// @declaration: true
|
||
|
// @filename: timer.js
|
||
|
/**
|
||
|
* @param {number} timeout
|
||
|
*/
|
||
|
function Timer(timeout) {
|
||
|
this.timeout = timeout;
|
||
|
}
|
||
|
module.exports = Timer;
|
||
|
// @filename: hook.js
|
||
|
/**
|
||
|
* @typedef {(arg: import("./context")) => void} HookHandler
|
||
|
*/
|
||
|
/**
|
||
|
* @param {HookHandler} handle
|
||
|
*/
|
||
|
function Hook(handle) {
|
||
|
this.handle = handle;
|
||
|
}
|
||
|
module.exports = Hook;
|
||
|
|
||
|
// @filename: context.js
|
||
|
/**
|
||
|
* Imports
|
||
|
*
|
||
|
* @typedef {import("./timer")} Timer
|
||
|
* @typedef {import("./hook")} Hook
|
||
|
* @typedef {import("./hook").HookHandler} HookHandler
|
||
|
*/
|
||
|
|
||
|
/**
|
||
|
* Input type definition
|
||
|
*
|
||
|
* @typedef {Object} Input
|
||
|
* @prop {Timer} timer
|
||
|
* @prop {Hook} hook
|
||
|
*/
|
||
|
|
||
|
/**
|
||
|
* State type definition
|
||
|
*
|
||
|
* @typedef {Object} State
|
||
|
* @prop {Timer} timer
|
||
|
* @prop {Hook} hook
|
||
|
*/
|
||
|
|
||
|
/**
|
||
|
* New `Context`
|
||
|
*
|
||
|
* @class
|
||
|
* @param {Input} input
|
||
|
*/
|
||
|
|
||
|
function Context(input) {
|
||
|
if (!(this instanceof Context)) {
|
||
|
return new Context(input)
|
||
|
}
|
||
|
this.state = this.construct(input);
|
||
|
}
|
||
|
Context.prototype = {
|
||
|
/**
|
||
|
* @param {Input} input
|
||
|
* @param {HookHandler=} handle
|
||
|
* @returns {State}
|
||
|
*/
|
||
|
construct(input, handle = () => void 0) {
|
||
|
return input;
|
||
|
}
|
||
|
}
|
||
|
module.exports = Context;
|