Posts

Showing posts from September, 2017

Using an Async Iterator in Typescript

I have been experimenting with async iterators in Typescript. One area these could be useful is in simplifying the code for forms, specifically handling button presses. Currently, I create forms programmatically using my form class, which creates Bootstrap modal forms. "Action buttons" are the buttons that sit in the modal-footer area. When creating "ActionButton"s to add to the form an onClick handler is specified and the form takes care of calling onClick() when the button is clicked. Here's a trivial example - an About box with an Ok button and second button just for testing. export function about(): void {   let aboutBox = new forms.Form( `About ${app.productName}` );   aboutBox.addButton(   {     name: 'Ok',     onClick: ()=>     {       aboutBox.close();     }   } );   aboutBox.addButton(   {     name: 'Test',     tooltip: 'Test some stuff',     onClick: ()=>     {       // do some stuff     }   });   aboutBox.show(); }