So I have this scenario where I choose a filter object to build. The list of filters is stored in an array:
app.constant("filters", () => <IFilterList>[
(value, label) => <IFilterObject>{ value: value, label: label }
]);
interface IFilterList {
[index:number]: (value?:string, label?:string) => IFilterObject
}
interface IFilterObject {
value: string,
label: string
}
This allows the module that sets the filter being used:
// somemodule.js
app.controller("SomeController", (filters, filterService) => {
var filter = filters[0]("this value", "this label");
filterService.change(filter);
});
As you can see doing filters[0] with a magic number is poor to say the least.
In C# I would create a static class which is public so can be used anywhere. Something like:
public static class FilterNames
{
public const int NameFilter = 0;
}
How would you do the same in AngularJs and TypeScript using the CommonJs module system?
In my mind you would need global variables... is really the best way to do this?