totaljs / Tangular

A simple JavaScript template engine like Angular.js for websites or node.js
MIT License
61 stars 21 forks source link

Feature(Service): add asynchronous feature #12

Closed dobobaie closed 5 years ago

dobobaie commented 5 years ago

Add asynchronous for handlers

petersirka commented 5 years ago

Nice and thank you. Currently I don't see any benefits of this change (can you create a better example of usage for me?) and I need to keep a backward compatibility to IE 10 and 11 because Tangular is used in web applications in most cases. For example there is no support for template literals (but this can be rewritten).

dobobaie commented 5 years ago

Oh I didn't see your compatibility to IE. In this case async/await is not possible. I'm using renderAsync for each asynchronous action. For example:

Tangular.register("toBase64", async url => {
 // async code
 return base64Stream;
});
await Tangular.renderAsync("Hello <img src='{{ img | toBase64 }}'", { img: "http://myUrl.com/logo.png" });
dobobaie commented 5 years ago

I created a new package to keep Tangular compatible with IE => https://www.npmjs.com/package/tangular-async

petersirka commented 5 years ago

Great! :-)

petersirka commented 5 years ago

We can merge packages in the future.

dobobaie commented 5 years ago

Sure! Thank u for your package :)