Example #1
0
QUnit.test("item controllers can be used to provide properties for array computed macros", function() {
  createArrayController();

  ok(compare(guidFor(cersei), guidFor(jaime)) < 0, "precond - guid tiebreaker would fail test");

  arrayController.reopen({
    sortProperties: Ngular.A(['title']),
    sorted: sort('@this', 'sortProperties')
  });

  deepEqual(arrayController.get('sorted').mapProperty('model.name'), ['Jaime', 'Cersei'], "ArrayController items can be sorted on itemController properties");
});
Example #2
0
      instanceMeta.order = function (itemA, itemB) {
        var sortProperty, result, asc;
        var keyA = this.keyFor(itemA);
        var keyB = this.keyFor(itemB);

        for (var i = 0; i < this.sortProperties.length; ++i) {
          sortProperty = this.sortProperties[i];

          result = compare(keyA[sortProperty], keyB[sortProperty]);

          if (result !== 0) {
            asc = this.sortPropertyAscending[sortProperty];
            return asc ? result : (-1 * result);
          }
        }

        return 0;
      };
Example #3
0
QUnit.test("should be comparable and return the correct result", function() {
  equal(Comparable.detect(r1), true);
  equal(compare(r1, r1), 0);
  equal(compare(r1, r2), -1);
  equal(compare(r2, r1), 1);
});
Example #4
0
import {get} from 'ngular-metal/property_get';
import NgularObject from 'ngular-runtime/system/object';
import compare from "ngular-runtime/compare";
import Comparable from 'ngular-runtime/mixins/comparable';

var Rectangle = NgularObject.extend(Comparable, {
  length: 0,
  width: 0,

  area() {
    return get(this, 'length') * get(this, 'width');
  },

  compare(a, b) {
    return compare(a.area(), b.area());
  }

});

var r1, r2;

QUnit.module("Comparable", {

  setup() {
    r1 = Rectangle.create({ length: 6, width: 12 });
    r2 = Rectangle.create({ length: 6, width: 13 });
  },

  teardown() {
  }