Accessing Enum in View

So am trying to clean up magic numbers in my sample AU2 sudoku app, and created a constants.ts file to hold those.

Its easy enough to add the import in the VM to access the enum, but what I am finding is the enum values are not available in the view. What I am guessing is during compilation (since enums don’t exist in js) that the enum constant is not getting replaced with the value and ends up being undefined.

If I assign the enum to a local VM property, it now is available and I get the correct value, but seems to be a code smell and I was wondering if there was a cleaner way to do this.

I have created a dumber gist below show what I am talking about. I have the local property commented out and if you click on any of the lower radio buttons you just get undefined. If you uncomment the local property the values are displayed correctly.

https://gist.dumber.app/?gist=8ba42c7330ca64bcae89d7c9b566b21c

In Au1 you could do that with ViewEngineHooks, see an example here http://www.foursails.co/blog/template-constants/

Now I’m unsure what the status is with Au2 with that. Perhaps @fkleuver or @bigopon can shed some light on this

Thanks! I rediscovered I had bookmarked that some time ago. MJD rocks.

I’ll see if it works for AU2 still.

So tried a few different things, but couldn’t get it to fire the beforeBind().
Experimented moving it into the VM, but can’t find the parameter listing for beforeBind(). The first parameter passed in the VM is not a view object but an integer in AU2.
I wasn’t able to figure out where to look in the AU2 repo to try and figure what those are.

public mySize = mySize; // should make it work.

1 Like

Thanks, I have that in the dumber commented out and it does work.
I was just thinking there would be a cleaner way, but I am now thinking there isn’t anything that would make it any simpler.