Skip to content

Commit

Permalink
chore(context): add BindingTag type alias
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondfeng committed Dec 12, 2018
1 parent 3999c15 commit 8d9ebcd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
9 changes: 3 additions & 6 deletions packages/context/src/binding-inspector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {MetadataInspector, MetadataAccessor} from '@loopback/metadata';
import {Binding, BindingScope, BindingTemplate, TagMap} from './binding';
import {MetadataAccessor, MetadataInspector} from '@loopback/metadata';
import {Binding, BindingScope, BindingTag, BindingTemplate} from './binding';
import {BindingAddress} from './binding-key';
import {ContextTags} from './keys';
import {Provider} from './provider';
Expand Down Expand Up @@ -37,10 +37,7 @@ export const BINDING_METADATA_KEY = MetadataAccessor.create<
*/
export type BindingScopeAndTags = {
scope?: BindingScope;
tags?:
| string // A simple tag name
| TagMap // An object of tag name/value pairs
| (string | TagMap)[]; // An array of tag names or name/value objects
tags?: BindingTag | BindingTag[];
};

/**
Expand Down
7 changes: 6 additions & 1 deletion packages/context/src/binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ export enum BindingType {
// tslint:disable-next-line:no-any
export type TagMap = MapObject<any>;

/**
* Binding tag can be a simple name or name/value pairs
*/
export type BindingTag = TagMap | string;

/**
* A function as the template to configure bindings
*/
Expand Down Expand Up @@ -274,7 +279,7 @@ export class Binding<T = BoundValue> {
*
* ```
*/
tag(...tags: (string | TagMap)[]): this {
tag(...tags: BindingTag[]): this {
for (const t of tags) {
if (typeof t === 'string') {
this.tagMap[t] = t;
Expand Down
15 changes: 7 additions & 8 deletions packages/context/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {Binding, TagMap} from './binding';
import {BindingKey, BindingAddress} from './binding-key';
import {isPromiseLike, getDeepProperty, BoundValue} from './value-promise';
import {ResolutionOptions, ResolutionSession} from './resolution-session';

import {v1 as uuidv1} from 'uuid';

import * as debugModule from 'debug';
import {v1 as uuidv1} from 'uuid';
import {ValueOrPromise} from '.';
import {Binding, BindingTag} from './binding';
import {BindingAddress, BindingKey} from './binding-key';
import {ResolutionOptions, ResolutionSession} from './resolution-session';
import {BoundValue, getDeepProperty, isPromiseLike} from './value-promise';

const debug = debugModule('loopback:context');

/**
Expand Down Expand Up @@ -207,7 +206,7 @@ export class Context {
* `{name: 'my-controller'}`
*/
findByTag<ValueType = BoundValue>(
tagFilter: string | RegExp | TagMap,
tagFilter: BindingTag | RegExp,
): Readonly<Binding<ValueType>>[] {
if (typeof tagFilter === 'string' || tagFilter instanceof RegExp) {
const regexp =
Expand Down

0 comments on commit 8d9ebcd

Please sign in to comment.