Skip to content

Commit

Permalink
fix lint-staged and slint
Browse files Browse the repository at this point in the history
  • Loading branch information
Frondor committed Dec 14, 2021
1 parent 819e5ac commit b00148d
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 17 deletions.
15 changes: 15 additions & 0 deletions Binding.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { Container, Resolvable } from '.';
interface BindingContract {
resolvable: Resolvable<unknown>;
shared: boolean;
}
declare class Binding implements BindingContract {
resolvable: Resolvable<unknown>;
shared: boolean;
constructor(resolvable: Resolvable<unknown>, shared?: boolean);
resolveInjectables(container: Container): unknown[];
resolve(container: Container, params?: unknown[]): any;
static isResolvable(binding: unknown): boolean;
static once(resolvable: Resolvable<unknown>, container: Container, params: unknown[]): any;
}
export default Binding;
48 changes: 48 additions & 0 deletions Container.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import type { Key, Resolvable } from '.';
export default class Container {
protected bindings: Map<any, any>;
protected instances: Map<any, any>;
protected aliases: Map<any, any>;
/**
* Checks if anything has been bound or aliased into the Container
*/
has(key: Key): boolean;
/**
* Binds a resolvable function into the Container
*
* If it is the only param, the object reference works as the reference key
*/
bind(key: Key | Resolvable<unknown>, resolvable?: unknown | Resolvable<unknown>, shared?: boolean): this;
private resolve;
/**
* Resolves a Binding reference from the Container
*
* If the given key is a Resolvable function,
* it is resolved from the Container on the fly
*/
make(key: unknown, ...params: unknown[]): any;
/**
* Resolves a Binding reference from the Container
*/
get<T extends new (...p: any[]) => InstanceType<T>>(key: T): InstanceType<T>;
get<T>(key: T): T extends new () => infer I ? I : unknown;
/**
* Set an object or primitive value into the Container
*
* When resolved, it returns the same value and reference
*/
instance(key: Key, value: unknown): void;
/**
* Bind a Resolvable function into the Container.
*
* The function is resolved once. Its result is stored
* and returned on subsequent calls to `get` or `make`.
*/
singleton(key: Key, resolvable: unknown): this;
private getInstance;
/**
* Apply an alias to an already-bound binding
*/
alias(alias: unknown, key: Key | Resolvable<unknown>): void;
private getAlias;
}
10 changes: 10 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export { default as Container } from './Container';
export declare type Key = unknown;
export declare type Injectable = {
injects: Array<Resolvable<unknown>>;
};
export declare type Resolvable<T> = {
(...params: unknown[]): T;
} & {
new (...params: unknown[]): T;
} & T & Injectable;
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"module": "dist/binder.module.js",
"unpkg": "dist/binder.umd.js",
"types": "dist/index.d.ts",
"types": "dist/types",
"sideEffects": false,
"files": [
"dist"
Expand All @@ -26,7 +26,7 @@
"node": ">=10.13.0"
},
"scripts": {
"lint": "eslint . --ext .js,.ts --cache --fix",
"lint": "eslint src/**/*.ts --cache --fix",
"prettier:fix": "prettier --write src",
"build": "microbundle src/index.ts",
"test:ci": "jest",
Expand Down Expand Up @@ -67,7 +67,7 @@
},
"homepage": "https://github.com/Frondor/binder#readme",
"lint-staged": {
"*.{js,ts}": [
"src/**/*.{js,ts}": [
"npm run prettier:fix",
"npm run lint"
]
Expand Down
3 changes: 1 addition & 2 deletions src/Binding.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Container } from '.'
import { Resolvable } from './types.d'
import type { Container, Resolvable } from '.'

interface BindingContract {
resolvable: Resolvable<unknown>
Expand Down
2 changes: 1 addition & 1 deletion src/Container.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-dupe-class-members */
import Binding from './Binding'
import { Key, Resolvable } from './types.d'
import type { Key, Resolvable } from '.'

export default class Container {
protected bindings = new Map()
Expand Down
14 changes: 14 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
/* eslint-disable no-use-before-define */
export { default as Container } from './Container'

export const a = 2

export type Key = unknown

export type Injectable = {
injects: Array<Resolvable<unknown>>
}

export type Resolvable<T> = { (...params: unknown[]): T } & {
new (...params: unknown[]): T
} & T &
Injectable
11 changes: 0 additions & 11 deletions src/types.d.ts

This file was deleted.

0 comments on commit b00148d

Please sign in to comment.