@@ -9,6 +9,7 @@ import { BaseException } from '@angular-devkit/core';
99import { Observable } from 'rxjs/Observable' ;
1010import { _throw } from 'rxjs/observable/throw' ;
1111import { last } from 'rxjs/operators/last' ;
12+ import { mergeMap } from 'rxjs/operators/mergeMap' ;
1213import { tap } from 'rxjs/operators/tap' ;
1314import { Rule , SchematicContext , Source } from '../engine/interface' ;
1415import { Tree , TreeSymbol } from '../tree/interface' ;
@@ -83,29 +84,31 @@ export function callSource(source: Source, context: SchematicContext): Observabl
8384export function callRule ( rule : Rule ,
8485 input : Observable < Tree > ,
8586 context : SchematicContext ) : Observable < Tree > {
86- return input . mergeMap ( inputTree => {
87- const result = rule ( inputTree , context ) as object ;
87+ return input . pipe (
88+ mergeMap ( inputTree => {
89+ const result = rule ( inputTree , context ) as object ;
8890
89- if ( result === undefined ) {
90- return Observable . of ( inputTree ) ;
91- } else if ( TreeSymbol in result ) {
92- return Observable . of ( result as Tree ) ;
93- } else if ( Symbol . observable in result ) {
94- const obs = result as Observable < Tree > ;
91+ if ( result === undefined ) {
92+ return Observable . of ( inputTree ) ;
93+ } else if ( TreeSymbol in result ) {
94+ return Observable . of ( result as Tree ) ;
95+ } else if ( Symbol . observable in result ) {
96+ const obs = result as Observable < Tree > ;
9597
96- // Only return the last Tree, and make sure it's a Tree.
97- return obs . pipe (
98- last ( ) ,
99- tap ( inner => {
100- if ( ! ( TreeSymbol in inner ) ) {
101- throw new InvalidRuleResultException ( inner ) ;
102- }
103- } ) ,
104- ) ;
105- } else if ( result === undefined ) {
106- return Observable . of ( inputTree ) ;
107- } else {
108- return _throw ( new InvalidRuleResultException ( result ) ) ;
109- }
110- } ) ;
98+ // Only return the last Tree, and make sure it's a Tree.
99+ return obs . pipe (
100+ last ( ) ,
101+ tap ( inner => {
102+ if ( ! ( TreeSymbol in inner ) ) {
103+ throw new InvalidRuleResultException ( inner ) ;
104+ }
105+ } ) ,
106+ ) ;
107+ } else if ( result === undefined ) {
108+ return Observable . of ( inputTree ) ;
109+ } else {
110+ return _throw ( new InvalidRuleResultException ( result ) ) ;
111+ }
112+ } ) ,
113+ ) ;
111114}
0 commit comments