Skip to content

Commit

Permalink
fix(context): correctly describe ContextView's BindingFilter type
Browse files Browse the repository at this point in the history
  • Loading branch information
bajtos committed Apr 15, 2019
1 parent cb308ad commit 7d1d290
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 9 additions & 0 deletions packages/context/src/binding-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ import {BindingAddress} from './binding-key';
/**
* A function that filters bindings. It returns `true` to select a given
* binding.
*
* Note: originally, we allow filters to be tied with a single value type.
* This actually does not make much sense - the filter function is typically
* invoked on all bindings to find those matching the given criteria,
* therefore filters must be prepared to handle bindings of any value type.
* We learned about this problem after enabling TypeScript's `strictFunctionTypes`
* check, but decided to preserve `ValueType` argument for backwards compatibility.
*
* TODO(semver-major): remove ValueType template argument.
*/
export type BindingFilter<ValueType = unknown> = (
binding: Readonly<Binding<ValueType>>,
Expand Down
6 changes: 3 additions & 3 deletions packages/context/src/context-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class ContextView<T = unknown> extends EventEmitter

constructor(
protected readonly context: Context,
public readonly filter: BindingFilter<T>,
public readonly filter: BindingFilter,
) {
super();
}
Expand Down Expand Up @@ -161,10 +161,10 @@ export class ContextView<T = unknown> extends EventEmitter
*/
export function createViewGetter<T = unknown>(
ctx: Context,
bindingFilter: BindingFilter<T>,
bindingFilter: BindingFilter,
session?: ResolutionSession,
): Getter<T[]> {
const view = new ContextView(ctx, bindingFilter);
const view = new ContextView<T>(ctx, bindingFilter);
view.open();
return view.asGetter(session);
}

0 comments on commit 7d1d290

Please sign in to comment.