@@ -21,8 +21,8 @@ export function main() {
2121 return parser . parseBinding ( exp ) ;
2222 }
2323
24- function createChangeDetector ( memo :string , exp :string , context = null ) {
25- var pwg = new ProtoWatchGroup ( ) ;
24+ function createChangeDetector ( memo :string , exp :string , context = null , formatters = null ) {
25+ var pwg = new ProtoWatchGroup ( formatters ) ;
2626 pwg . watch ( ast ( exp ) , memo , false ) ;
2727
2828 var dispatcher = new LoggingDispatcher ( ) ;
@@ -34,8 +34,8 @@ export function main() {
3434 return { "changeDetector" : cd , "dispatcher" : dispatcher } ;
3535 }
3636
37- function executeWatch ( memo :string , exp :string , context = null ) {
38- var res = createChangeDetector ( memo , exp , context ) ;
37+ function executeWatch ( memo :string , exp :string , context = null , formatters = null ) {
38+ var res = createChangeDetector ( memo , exp , context , formatters ) ;
3939 res [ "changeDetector" ] . detectChanges ( ) ;
4040 return res [ "dispatcher" ] . log ;
4141 }
@@ -61,19 +61,19 @@ export function main() {
6161 expect ( dispatcher . log ) . toEqual ( [ 'name=Misko' ] ) ;
6262 } ) ;
6363
64- it ( 'should watch chained properties' , ( ) => {
64+ it ( 'should support chained properties' , ( ) => {
6565 var address = new Address ( 'Grenoble' ) ;
6666 var person = new Person ( 'Victor' , address ) ;
6767
6868 expect ( executeWatch ( 'address.city' , 'address.city' , person ) )
6969 . toEqual ( [ 'address.city=Grenoble' ] ) ;
7070 } ) ;
7171
72- it ( "should watch literals" , ( ) => {
72+ it ( "should support literals" , ( ) => {
7373 expect ( executeWatch ( 'const' , '10' ) ) . toEqual ( [ 'const=10' ] ) ;
7474 } ) ;
7575
76- it ( "should watch binary operations" , ( ) => {
76+ it ( "should support binary operations" , ( ) => {
7777 expect ( executeWatch ( 'exp' , '10 + 2' ) ) . toEqual ( [ 'exp=12' ] ) ;
7878 expect ( executeWatch ( 'exp' , '10 - 2' ) ) . toEqual ( [ 'exp=8' ] ) ;
7979
@@ -104,6 +104,15 @@ export function main() {
104104 expect ( executeWatch ( 'exp' , 'true || false' ) ) . toEqual ( [ 'exp=true' ] ) ;
105105 expect ( executeWatch ( 'exp' , 'false || false' ) ) . toEqual ( [ 'exp=false' ] ) ;
106106 } ) ;
107+
108+ it ( "should support formatters" , ( ) => {
109+ var formatters = {
110+ "uppercase" : ( v ) => v . toUpperCase ( ) ,
111+ "wrap" : ( v , before , after ) => `${ before } ${ v } ${ after } `
112+ } ;
113+ expect ( executeWatch ( 'str' , '"aBc" | uppercase' , null , formatters ) ) . toEqual ( [ 'str=ABC' ] ) ;
114+ expect ( executeWatch ( 'str' , '"b" | wrap:"a":"c"' , null , formatters ) ) . toEqual ( [ 'str=abc' ] ) ;
115+ } ) ;
107116 } ) ;
108117 } ) ;
109118}
0 commit comments