How to use the ix.Enumerable.fromArray function in ix

To help you get started, we’ve selected a few ix examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github marinels / webrx-react / src / Components / Common / TimeSpanInput / TimeSpanInputViewModel.ts View on Github external
let args = text.split(' ', 2);

      if (Number.isNumeric(args[0])) {
        // only process if it's numeric
        if (args.length === 1) {
          // single arg
          // just assume we're using the currently selected units
          value = moment.duration(Number(args[0]), this.unit().shortKey);
        }
        else if (args.length === 2) {
          // two args
          // first determine the units used
          let unitName = moment.normalizeUnits(args[1]);

          if (String.isNullOrEmpty(unitName) === false) {
            let unit = Enumerable
              .fromArray(TimeSpanUnits)
              .filter(x => x.key === unitName)
              .firstOrDefault();

            if (unit != null) {
              // if the unit type is valid process the value
              value = moment.duration(Number(args[0]), unitName);
              // only update the currently selected units if they are parsed
              this.unit(unit);
            }
          }
        }
      }
    }

    this.setValue(value);
github marinels / webrx-react / src / Components / Common / RouteHandler / RouteHandlerViewModel.ts View on Github external
private getActivator(route: Route) {
    // default by just fetching the mapped route directly
    let activator = this.routingMap[route.path];

    // if there is no directly mapped route, check for a parameterized route
    if (activator == null) {
      let result = Enumerable
        .fromArray(Object.keys(this.routingMap))
        .filter(x => x != null && x.length > 0 && x[0] === '^')
        .map(x => ({ key: x, regex: new RegExp(x, 'i') }))
        .map(x => ({ key: x.key, match: x.regex.exec(route.path) }))
        .filter(x => x.match != null)
        .map(x => ({ match: x.match, activator: this.routingMap[x.key] }))
        .firstOrDefault();

      if (result != null) {
        // if we found a parameterized route then set the match properties on the route
        route.match = result.match;

        activator = result.activator;
      }
    }
github marinels / webrx-react / src / Components / Common / TimeSpanInput / TimeSpanInputViewModel.ts View on Github external
public precision = 2,
    public parseDelay = 500
    ) {
    super();

    this.unit(unit.type < minUnit ? TimeSpanUnits[minUnit] : unit);
    this.minValue = this.minValue || moment.duration(1, this.unit().key);

    if (units == null) {
      this.units = Enumerable
        .fromArray(TimeSpanUnits)
        .filter(x => x.type >= minUnit && x.type <= maxUnit)
        .toArray();
    }
    else {
      this.units = Enumerable
        .fromArray(units)
        .map(x => TimeSpanUnits[x])
        .toArray();
    }

    if (this.parseDelay > 0) {
      this.subscribe(this.text.changed
        .debounce(this.parseDelay)
        .invokeCommand(this.parse)
      );
    }

    this.subscribe(this.parse.results
      .invokeCommand(this.validate)
    );
github marinels / webrx-react / src / Components / Common / TimeSpanInput / TimeSpanInputViewModel.ts View on Github external
public required = false,
    units?: TimeSpanUnitType[],
    public minValue?: moment.Duration,
    public maxValue?: moment.Duration,
    public minUnit = TimeSpanUnitType.Days,
    public maxUnit = TimeSpanUnitType.Years,
    public precision = 2,
    public parseDelay = 500
    ) {
    super();

    this.unit(unit.type < minUnit ? TimeSpanUnits[minUnit] : unit);
    this.minValue = this.minValue || moment.duration(1, this.unit().key);

    if (units == null) {
      this.units = Enumerable
        .fromArray(TimeSpanUnits)
        .filter(x => x.type >= minUnit && x.type <= maxUnit)
        .toArray();
    }
    else {
      this.units = Enumerable
        .fromArray(units)
        .map(x => TimeSpanUnits[x])
        .toArray();
    }

    if (this.parseDelay > 0) {
      this.subscribe(this.text.changed
        .debounce(this.parseDelay)
        .invokeCommand(this.parse)
      );
github marinels / webrx-react / src / Extensions / Array.ts View on Github external
function asEnumerable(this: T[]) {
  return Enumerable.fromArray(this);
}
Array.prototype.asEnumerable = asEnumerable;