Skip to content

Commit

Permalink
feat(bindings): Apply explicit bindings even when no @Input() found.
Browse files Browse the repository at this point in the history
Closes #45
  • Loading branch information
christopherthielen committed Feb 11, 2017
1 parent a21c479 commit 4351c53
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/directives/uiView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import {ReflectorReader, reflector} from '../private_import_core';

import {
UIRouter, isFunction, Transition, parse, HookResult, TransitionHookFn, State, prop, StateDeclaration
UIRouter, isFunction, Transition, parse, HookResult, TransitionHookFn, State, prop, StateDeclaration, inArray
} from "ui-router-core";
import {trace} from "ui-router-core";
import {ViewContext, ViewConfig, ActiveUIView} from "ui-router-core";
Expand Down Expand Up @@ -283,15 +283,22 @@ export class UIView {
*/
applyInputBindings(ref: ComponentRef<any>, context: ResolveContext, componentClass) {
let bindings = this.uiViewData.config.viewDecl['bindings'] || {};
let explicitBoundProps = Object.keys(bindings);

var addResolvable = (tuple: InputMapping) => ({
// Supply resolve data to matching @Input('prop') or inputs: ['prop']
let explicitInputTuples = explicitBoundProps
.reduce((acc, key) => acc.concat([{ prop: key, token: bindings[key] }]), []);
let implicitInputTuples = ng2ComponentInputs(componentClass)
.filter(tuple => !inArray(explicitBoundProps, tuple.prop));


const addResolvable = (tuple: InputMapping) => ({
prop: tuple.prop,
resolvable: context.getResolvable(bindings[tuple.prop] || tuple.token)
resolvable: context.getResolvable(tuple.token),
});

// Supply resolve data to matching @Input('prop') or inputs: ['prop']
let inputTuples = ng2ComponentInputs(componentClass);
inputTuples.map(addResolvable)
explicitInputTuples.concat(implicitInputTuples)
.map(addResolvable)
.filter(tuple => tuple.resolvable && tuple.resolvable.resolved)
.forEach(tuple => { ref.instance[tuple.prop] = tuple.resolvable.data });

Expand Down

0 comments on commit 4351c53

Please sign in to comment.