Made config first constructor arg, no longer necessary to pass any arguments.
This commit is contained in:
parent
51cd15aa4f
commit
a2e698d2f6
3 changed files with 12 additions and 11 deletions
|
@ -90,7 +90,7 @@ interface HitCounterConfig {
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
import { HitCounter, ImageHitCounterRenderer } from "./hit-counter";
|
import { HitCounter } from "./hit-counter";
|
||||||
|
|
||||||
|
|
||||||
// default config
|
// default config
|
||||||
|
@ -113,13 +113,14 @@ defaultHitCounterConfig = {
|
||||||
secondaryTextColorRGB: { r: 0, g: 255, b: 0 },
|
secondaryTextColorRGB: { r: 0, g: 255, b: 0 },
|
||||||
numberColorRGB: { r: 255, g: 255, b: 255 },
|
numberColorRGB: { r: 255, g: 255, b: 255 },
|
||||||
frameColorRGB: { r: 255, g: 0, b: 0 },
|
frameColorRGB: { r: 255, g: 0, b: 0 },
|
||||||
drawFrame: true,
|
drawFrame: true
|
||||||
renderer: ImageHitCounterRenderer
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// the default config will be used, but you can pass a custom config object as
|
// the default config will be used, but you can pass a custom config object as
|
||||||
// the second argument to the HitCounter constructor
|
// the first argument to the HitCounter constructor
|
||||||
const hitCounter = new HitCounter(ImageHitCounterRenderer);
|
// e.g. const hitCounter = new HitCounter(customConfig);
|
||||||
|
// the second argument is reserved for the renderer, but currently only the ImageHitCounterRenderer is implemented
|
||||||
|
const hitCounter = new HitCounter();
|
||||||
|
|
||||||
// increment the hit counter
|
// increment the hit counter
|
||||||
hitCounter.increment(); // async function
|
hitCounter.increment(); // async function
|
||||||
|
|
|
@ -346,12 +346,12 @@ class HitCounter {
|
||||||
/**
|
/**
|
||||||
* Creates an instance of HitCounter.
|
* Creates an instance of HitCounter.
|
||||||
*
|
*
|
||||||
* @param {Type<BaseHitCounterRenderer>} renderer
|
|
||||||
* The hit counter renderer.
|
|
||||||
* @param {HitCounterConfig} [config=defaultHitCounterConfig]
|
* @param {HitCounterConfig} [config=defaultHitCounterConfig]
|
||||||
* The hit counter configuration.
|
* The hit counter configuration. Defaults to defaultHitCounterConfig.
|
||||||
|
* @param {Type<BaseHitCounterRenderer>} renderer
|
||||||
|
* The hit counter renderer. Defaults to ImageHitCounterRenderer.
|
||||||
*/
|
*/
|
||||||
constructor(renderer: Type<BaseHitCounterRenderer>, config: HitCounterConfig = defaultHitCounterConfig) {
|
constructor(config: HitCounterConfig = defaultHitCounterConfig, renderer: Type<BaseHitCounterRenderer> = ImageHitCounterRenderer) {
|
||||||
config = { ...defaultHitCounterConfig, ...config };
|
config = { ...defaultHitCounterConfig, ...config };
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.renderer = new renderer(this, config);
|
this.renderer = new renderer(this, config);
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import express, { Express, Request, Response } from "express";
|
import express, { Express, Request, Response } from "express";
|
||||||
import { HitCounter, ImageHitCounterRenderer } from "./hit-counter";
|
import { HitCounter } from "./hit-counter";
|
||||||
|
|
||||||
const app: Express = express();
|
const app: Express = express();
|
||||||
const PORT: number = 8000;
|
const PORT: number = 8000;
|
||||||
const hitCounter = new HitCounter(ImageHitCounterRenderer);
|
const hitCounter = new HitCounter();
|
||||||
const imageMimeType = hitCounter.getMimeType();
|
const imageMimeType = hitCounter.getMimeType();
|
||||||
|
|
||||||
app.get("/", (req: Request, res: Response) => {
|
app.get("/", (req: Request, res: Response) => {
|
||||||
|
|
Loading…
Reference in a new issue