#102 Computed Macro

Update: I made some corrections based on comments.

Let’s say you want to create a computed property to upper case another property, for example:

Let’s say you want to use this “upper” function in multiple places, you can convert it into a “computed macro”.

Create a macro in a subfolder e.g. utils or macros:

Create the helper:

Now, you can use that computed macro like this:

Don’t forget to import it:

This tip was inspired by the ember-awesome-macros addon.


Also published on Medium.

Published by

Emad Ibrahim

Author of asp .net MVC & TDD, entrepreneur, passionate technologist, programmer and productivity nut. more at http://t.co/oSJXPvzu

  • So if this is also a helper is it supposed to work both as an imported function and also in template? I always created macros just as simple function and kept them in macros or util folder.

    • good point. I will test it out and get back to you but I don’t think so.

    • I looked into it. Technically, you CAN use the helper in your template BUT it will display [object Object] instead of the actual string. That make sense, since the helper function is returning a computed object.

      So my code does work but it is probably not a good idea to generate it as a helper and would probably do it in a sub folder like you mentioned.

      Thanks @martinmalinda:disqus , I will update the tip.

  • But then I am really not sure if helper should be returning a computed..