Core jWidget utilities.
import * as jwidget from "jwidget";
Binding: enum
jWidget binding modes. All options have shorthands, i.e. Binding.UPDATE
can be imported
separately as {UPDATE}
.
Bind element attribute to property.
// Bind element value to property bindVal(el, property, UPDATE);
Always used as default binding. Hence, the next code is equivalent:
bindVal(el, property);
Bind property to element attribute.
// Bind property to element value bindVal(el, property, WATCH);
Always supplied with a no-argument method, which creates the property automatically.
// Watch element value const property = bindVal(el);
Bind element attribute and property to each other.
UPDATE-binding is applied first, WATCH is applied last.
// Assign element value to property and setup two-way binding bindVal(el, property, TWOWAY);
(x: any, y: any): number
Universal and sophisticated comparer for array sorting. The same as smartCmp, but without third argument. It comes in handy when a function takes a callback accepting 3 or more arguments - in this case, arguments of smartCmp won't match the callback definition:
const array = new BindableArray(["q", "w", "e"]); array.sortComparing(cmp); // ok array.sortComparing(smartCmp); // compilation error: callback arguments don't match
(x: any, y: any, config?: CmpConfig): number
Universal and sophisticated comparer for array sorting. Broadly speaking, it:
x > y
x < y
x == y
In reality, it supports the next features:
Values of different types are compared as follows: undefined < null < array < boolean < number < string.
Sort by color descending first, and by status ascending last. Both parameters are optional.
rows.sort((x, y) => { return smartCmp(x.color == null, y.color == null) || -smartCmp(x.color, y.color) || smartCmp(x.status == null, y.status == null) || smartCmp(x.status, y.status); });
readonly caseInsensitive?: boolean
Ignore case when comparing strings.
expect(smartCmp("aB", "Ab")).equal(1); expect(smartCmp("aB", "Ab", {caseInsensitive: true})).equal(0);
(obj: any): void
Calls destroy method of obj if available. Can be used in configuration of any mapper.
const views = startMappingArray(models, model => new View(model), {destroy});