@frui.ts/helpers
Helper functions for various use cases.
@bound
A function decorator that binds context of the function to the parent class. This is useful for direct use of the function as event handler <Xxx onClick={vm.decoratedFunction} />
so that new anonymous functions are not allocated for each render (compare to <Xxx onClick={() => vm.decoratedFunction()} />
).
Usage
class MyViewModel {
@bound someAction() {
}
}
<button onClick={vm.someAction} />
createMap
Helper function for easily creating Maps.
Usage
const items = [
{ id: 1, name: "One" },
{ id: 2, name: "Two" },
{ id: 3, name: "Three" },
];
const itemsById = createMap(items, x => x.id);
const namesById = createMap(items, x => x.id, x => x.name);
nameof
Syntactic sugar for creating strings that are also a key of a type.
Usage
this.pagingFilter.sortColumn = nameof<User>("login");