-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ng2.uiView): bind resolve data to input[] and @input(), process …
…bindings:
- Loading branch information
1 parent
8a24041
commit f6dae28
Showing
2 changed files
with
41 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import {InputMetadata, ComponentMetadata} from "angular2/core"; | ||
|
||
export const ng2ComponentInputs = (ng2CompClass) => { | ||
/** Get "@Input('foo') _foo" inputs */ | ||
let props = Reflect['getMetadata']('propMetadata', ng2CompClass); | ||
let _props = Object.keys(props || {}) | ||
// -> { string, anno[] } tuples | ||
.map(key => ({ key, annoArr: props[key] })) | ||
// -> to { string, anno } tuples | ||
.reduce((acc, tuple) => acc.concat(tuple.annoArr.map(anno => ({ key: tuple.key, anno }))), []) | ||
// Only Inputs | ||
.filter(tuple => tuple.anno instanceof InputMetadata) | ||
// If they have a bindingPropertyName, i.e. "@Input('foo') _foo", then foo, else _foo | ||
.map(tuple => ({ resolve: tuple.anno.bindingPropertyName || tuple.key, prop: tuple.key })); | ||
|
||
/** Get "inputs: ['foo']" inputs */ | ||
let inputs = Reflect['getMetadata']('annotations', ng2CompClass) | ||
// Find the ComponentMetadata class annotation | ||
.filter(x => x instanceof ComponentMetadata && !!x.inputs) | ||
// Get the .inputs string array | ||
.map(x => x.inputs) | ||
// Flatten | ||
.reduce((acc, arr) => acc.concat(arr), []) | ||
.map(input => ({ resolve: input, prop: input })); | ||
|
||
return _props.concat(inputs); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters