fable-core
Advanced tools
Comparing version 0.7.5-alpha.7 to 0.7.5-alpha.8
@@ -7,3 +7,3 @@ import { IDisposable } from "./Util"; | ||
export declare class Trampoline { | ||
static maxTrampolineCallCount: number; | ||
static readonly maxTrampolineCallCount: number; | ||
private callCount; | ||
@@ -10,0 +10,0 @@ constructor(); |
@@ -7,6 +7,6 @@ export declare function choice1Of2<T1, T2>(v: T1): Choice<T1, T2>; | ||
constructor(t: "Choice1Of2" | "Choice2Of2", d: T1[] | T2[]); | ||
valueIfChoice1: T1; | ||
valueIfChoice2: T2; | ||
readonly valueIfChoice1: T1; | ||
readonly valueIfChoice2: T2; | ||
Equals(other: Choice<T1, T2>): boolean; | ||
CompareTo(other: Choice<T1, T2>): number; | ||
} |
@@ -130,8 +130,13 @@ var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
List.prototype.Equals = function Equals(x) { | ||
var iter1 = this[Symbol.iterator](), | ||
iter2 = x[Symbol.iterator](); | ||
for (var i = 0;; i++) { | ||
var cur1 = iter1.next(), | ||
cur2 = iter2.next(); | ||
if (cur1.done) return cur2.done ? true : false;else if (cur2.done) return false;else if (!equals(cur1.value, cur2.value)) return false; | ||
// Optimization if they are referencially equal | ||
if (this === x) { | ||
return true; | ||
} else { | ||
var iter1 = this[Symbol.iterator](), | ||
iter2 = x[Symbol.iterator](); | ||
for (;;) { | ||
var cur1 = iter1.next(), | ||
cur2 = iter2.next(); | ||
if (cur1.done) return cur2.done ? true : false;else if (cur2.done) return false;else if (!equals(cur1.value, cur2.value)) return false; | ||
} | ||
} | ||
@@ -141,11 +146,16 @@ }; | ||
List.prototype.CompareTo = function CompareTo(x) { | ||
var acc = 0; | ||
var iter1 = this[Symbol.iterator](), | ||
iter2 = x[Symbol.iterator](); | ||
for (var i = 0;; i++) { | ||
var cur1 = iter1.next(), | ||
cur2 = iter2.next(); | ||
if (cur1.done) return cur2.done ? acc : -1;else if (cur2.done) return 1;else { | ||
acc = compare(cur1.value, cur2.value); | ||
if (acc != 0) return acc; | ||
// Optimization if they are referencially equal | ||
if (this === x) { | ||
return 0; | ||
} else { | ||
var acc = 0; | ||
var iter1 = this[Symbol.iterator](), | ||
iter2 = x[Symbol.iterator](); | ||
for (;;) { | ||
var cur1 = iter1.next(), | ||
cur2 = iter2.next(); | ||
if (cur1.done) return cur2.done ? acc : -1;else if (cur2.done) return 1;else { | ||
acc = compare(cur1.value, cur2.value); | ||
if (acc != 0) return acc; | ||
} | ||
} | ||
@@ -152,0 +162,0 @@ } |
@@ -418,3 +418,3 @@ var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
return seqCompareWith(function (kvp1, kvp2) { | ||
return this === m2 ? 0 : seqCompareWith(function (kvp1, kvp2) { | ||
var c = _this.comparer.Compare(kvp1[0], kvp2[0]); | ||
@@ -421,0 +421,0 @@ return c !== 0 ? c : compare(kvp1[1], kvp2[1]); |
@@ -48,3 +48,3 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
} | ||
export function inflate(val, typ) { | ||
function inflate(val, typ) { | ||
function needsInflate(enclosing) { | ||
@@ -172,5 +172,9 @@ var typ = enclosing.head; | ||
} | ||
export function ofJson(json, typ) { | ||
return inflate(JSON.parse(json), typ); | ||
function inflatePublic(val, genArgs) { | ||
return inflate(val, genArgs ? genArgs.T : null); | ||
} | ||
export { inflatePublic as inflate }; | ||
export function ofJson(json, genArgs) { | ||
return inflate(JSON.parse(json), genArgs ? genArgs.T : null); | ||
} | ||
export function toJsonWithTypeInfo(o) { | ||
@@ -190,3 +194,3 @@ return JSON.stringify(o, function (k, v) { | ||
} else if (v[FSymbol.typeName]) { | ||
if (hasInterface(v, "FSharpUnion", "FSharpRecord")) { | ||
if (hasInterface(v, "FSharpUnion") || hasInterface(v, "FSharpRecord")) { | ||
return Object.assign({ $type: v[FSymbol.typeName]() }, v); | ||
@@ -208,3 +212,3 @@ } else { | ||
} | ||
export function ofJsonWithTypeInfo(json, expected) { | ||
export function ofJsonWithTypeInfo(json, genArgs) { | ||
var parsed = JSON.parse(json, function (k, v) { | ||
@@ -249,2 +253,3 @@ if (v == null) return v;else if ((typeof v === "undefined" ? "undefined" : _typeof(v)) === "object" && typeof v.$type === "string") { | ||
}); | ||
var expected = genArgs ? genArgs.T : null; | ||
if (parsed != null && typeof expected === "function" && !(parsed instanceof getDefinition(expected))) { | ||
@@ -251,0 +256,0 @@ throw "JSON is not of type " + expected.name + ": " + json; |
@@ -654,3 +654,3 @@ var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
FSet.prototype.CompareTo = function CompareTo(s2) { | ||
return tree_compare(this.comparer, this.tree, s2.tree); | ||
return this === s2 ? 0 : tree_compare(this.comparer, this.tree, s2.tree); | ||
}; | ||
@@ -657,0 +657,0 @@ |
@@ -49,10 +49,5 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
} | ||
export function hasInterface(obj) { | ||
for (var _len2 = arguments.length, interfaceNames = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
interfaceNames[_key2 - 1] = arguments[_key2]; | ||
} | ||
return obj[FSymbol.interfaces] && obj[FSymbol.interfaces]().some(function (x) { | ||
return interfaceNames.indexOf(x) >= 0; | ||
}); | ||
export function hasInterface(obj, interfaceName) { | ||
var interfaces = typeof obj[FSymbol.interfaces] === "function" ? obj[FSymbol.interfaces]() : obj[FSymbol.interfaces]; | ||
return Array.isArray(interfaces) ? interfaces.indexOf(interfaceName) > -1 : interfaces === interfaceName; | ||
} | ||
@@ -78,3 +73,4 @@ export function getRestParams(args, idx) { | ||
export function equals(x, y) { | ||
if (x == null) return y == null;else if (y == null) return false;else if (isGeneric(x) && isGeneric(y)) return getDefinition(x) === getDefinition(y) && equalsRecords(x.prototype[FSymbol.generics](), y.prototype[FSymbol.generics]());else if (Object.getPrototypeOf(x) !== Object.getPrototypeOf(y)) return false;else if (Array.isArray(x)) { | ||
// Optimization if they are referencially equal | ||
if (x === y) return true;else if (x == null) return y == null;else if (y == null) return false;else if (isGeneric(x) && isGeneric(y)) return getDefinition(x) === getDefinition(y) && equalsRecords(x.prototype[FSymbol.generics](), y.prototype[FSymbol.generics]());else if (Object.getPrototypeOf(x) !== Object.getPrototypeOf(y)) return false;else if (typeof x.Equals === "function") return x.Equals(y);else if (Array.isArray(x)) { | ||
if (x.length != y.length) return false; | ||
@@ -91,6 +87,8 @@ for (var i = 0; i < x.length; i++) { | ||
}return true; | ||
} else if (x instanceof Date) return x.getTime() == y.getTime();else if (hasInterface(x, "System.IEquatable")) return x.Equals(y);else return x === y; | ||
} else if (x instanceof Date) return x.getTime() == y.getTime();else return false; | ||
} | ||
export function compare(x, y) { | ||
if (x == null) return y == null ? 0 : -1;else if (y == null) return -1;else if (Object.getPrototypeOf(x) !== Object.getPrototypeOf(y)) return -1;else if (Array.isArray(x)) { | ||
// Optimization if they are referencially equal | ||
if (x === y) return 0; | ||
if (x == null) return y == null ? 0 : -1;else if (y == null) return -1;else if (Object.getPrototypeOf(x) !== Object.getPrototypeOf(y)) return -1;else if (hasInterface(x, "System.IComparable")) return x.CompareTo(y);else if (Array.isArray(x)) { | ||
if (x.length != y.length) return x.length < y.length ? -1 : 1; | ||
@@ -110,34 +108,55 @@ for (var i = 0, j = 0; i < x.length; i++) { | ||
return 0; | ||
} else if (hasInterface(x, "System.IComparable")) return x.CompareTo(y);else return x < y ? -1 : x > y ? 1 : 0; | ||
} else if (x instanceof Date) return compare(x.getTime(), y.getTime());else return x < y ? -1 : 1; | ||
} | ||
export function equalsRecords(x, y) { | ||
var keys = Object.getOwnPropertyNames(x); | ||
for (var i = 0; i < keys.length; i++) { | ||
if (!equals(x[keys[i]], y[keys[i]])) return false; | ||
// Optimization if they are referencially equal | ||
if (x === y) { | ||
return true; | ||
} else { | ||
var keys = Object.getOwnPropertyNames(x); | ||
for (var i = 0; i < keys.length; i++) { | ||
if (!equals(x[keys[i]], y[keys[i]])) return false; | ||
} | ||
return true; | ||
} | ||
return true; | ||
} | ||
export function compareRecords(x, y) { | ||
var keys = Object.getOwnPropertyNames(x); | ||
for (var i = 0; i < keys.length; i++) { | ||
var res = compare(x[keys[i]], y[keys[i]]); | ||
if (res !== 0) return res; | ||
// Optimization if they are referencially equal | ||
if (x === y) { | ||
return 0; | ||
} else { | ||
var keys = Object.getOwnPropertyNames(x); | ||
for (var i = 0; i < keys.length; i++) { | ||
var res = compare(x[keys[i]], y[keys[i]]); | ||
if (res !== 0) return res; | ||
} | ||
return 0; | ||
} | ||
return 0; | ||
} | ||
export function equalsUnions(x, y) { | ||
if (x.Case !== y.Case) return false; | ||
for (var i = 0; i < x.Fields.length; i++) { | ||
if (!equals(x.Fields[i], y.Fields[i])) return false; | ||
// Optimization if they are referencially equal | ||
if (x === y) { | ||
return true; | ||
} else if (x.Case !== y.Case) { | ||
return false; | ||
} else { | ||
for (var i = 0; i < x.Fields.length; i++) { | ||
if (!equals(x.Fields[i], y.Fields[i])) return false; | ||
} | ||
return true; | ||
} | ||
return true; | ||
} | ||
export function compareUnions(x, y) { | ||
var res = compare(x.Case, y.Case); | ||
if (res !== 0) return res; | ||
for (var i = 0; i < x.Fields.length; i++) { | ||
res = compare(x.Fields[i], y.Fields[i]); | ||
// Optimization if they are referencially equal | ||
if (x === y) { | ||
return 0; | ||
} else { | ||
var res = compare(x.Case, y.Case); | ||
if (res !== 0) return res; | ||
for (var i = 0; i < x.Fields.length; i++) { | ||
res = compare(x.Fields[i], y.Fields[i]); | ||
if (res !== 0) return res; | ||
} | ||
return 0; | ||
} | ||
return 0; | ||
} | ||
@@ -149,5 +168,3 @@ export function createDisposable(f) { | ||
Dispose: f | ||
}, _ref[FSymbol.interfaces] = function () { | ||
return ["System.IDisposable"]; | ||
}, _ref; | ||
}, _ref[FSymbol.interfaces] = "System.IDisposable", _ref; | ||
} | ||
@@ -154,0 +171,0 @@ export function createObj(fields) { |
@@ -20,3 +20,3 @@ import { IObserver } from "./Observable"; | ||
Add(f: Delegate<T>): void; | ||
Publish: this; | ||
readonly Publish: this; | ||
Trigger(value: T): void; | ||
@@ -23,0 +23,0 @@ private _addHandler(f); |
@@ -7,3 +7,3 @@ export declare function createFromValue<T>(v: T): Lazy<T>; | ||
constructor(factory: () => T); | ||
value: T; | ||
readonly value: T; | ||
} |
@@ -28,4 +28,4 @@ import { IEquatable } from "./Util"; | ||
CompareTo(x: List<T>): number; | ||
length: number; | ||
readonly length: number; | ||
[Symbol.iterator](): Iterator<T>; | ||
} |
40
List.js
@@ -154,8 +154,13 @@ "use strict"; | ||
List.prototype.Equals = function Equals(x) { | ||
var iter1 = this[Symbol.iterator](), | ||
iter2 = x[Symbol.iterator](); | ||
for (var i = 0;; i++) { | ||
var cur1 = iter1.next(), | ||
cur2 = iter2.next(); | ||
if (cur1.done) return cur2.done ? true : false;else if (cur2.done) return false;else if (!(0, _Util.equals)(cur1.value, cur2.value)) return false; | ||
// Optimization if they are referencially equal | ||
if (this === x) { | ||
return true; | ||
} else { | ||
var iter1 = this[Symbol.iterator](), | ||
iter2 = x[Symbol.iterator](); | ||
for (;;) { | ||
var cur1 = iter1.next(), | ||
cur2 = iter2.next(); | ||
if (cur1.done) return cur2.done ? true : false;else if (cur2.done) return false;else if (!(0, _Util.equals)(cur1.value, cur2.value)) return false; | ||
} | ||
} | ||
@@ -165,11 +170,16 @@ }; | ||
List.prototype.CompareTo = function CompareTo(x) { | ||
var acc = 0; | ||
var iter1 = this[Symbol.iterator](), | ||
iter2 = x[Symbol.iterator](); | ||
for (var i = 0;; i++) { | ||
var cur1 = iter1.next(), | ||
cur2 = iter2.next(); | ||
if (cur1.done) return cur2.done ? acc : -1;else if (cur2.done) return 1;else { | ||
acc = (0, _Util.compare)(cur1.value, cur2.value); | ||
if (acc != 0) return acc; | ||
// Optimization if they are referencially equal | ||
if (this === x) { | ||
return 0; | ||
} else { | ||
var acc = 0; | ||
var iter1 = this[Symbol.iterator](), | ||
iter2 = x[Symbol.iterator](); | ||
for (;;) { | ||
var cur1 = iter1.next(), | ||
cur2 = iter2.next(); | ||
if (cur1.done) return cur2.done ? acc : -1;else if (cur2.done) return 1;else { | ||
acc = (0, _Util.compare)(cur1.value, cur2.value); | ||
if (acc != 0) return acc; | ||
} | ||
} | ||
@@ -176,0 +186,0 @@ } |
@@ -29,3 +29,3 @@ import { IComparer } from "./Util"; | ||
clear(): void; | ||
size: number; | ||
readonly size: number; | ||
} | ||
@@ -32,0 +32,0 @@ export declare function create<K, V>(ie?: Iterable<[K, V]>, comparer?: IComparer<K>): FMap<K, V>; |
@@ -451,3 +451,3 @@ "use strict"; | ||
return (0, _Seq.compareWith)(function (kvp1, kvp2) { | ||
return this === m2 ? 0 : (0, _Seq.compareWith)(function (kvp1, kvp2) { | ||
var c = _this.comparer.Compare(kvp1[0], kvp2[0]); | ||
@@ -454,0 +454,0 @@ return c !== 0 ? c : (0, _Util.compare)(kvp1[1], kvp2[1]); |
{ | ||
"name": "fable-core", | ||
"version": "0.7.5-alpha.7", | ||
"version": "0.7.5-alpha.8", | ||
"description": "Fable core lib & bindings for native JS objects, browser and node APIs", | ||
@@ -26,4 +26,4 @@ "main": "Main.js", | ||
"babel-preset-es2015": "^6.9.0", | ||
"typescript": "^1.8.10" | ||
"typescript": "^2.0.3" | ||
} | ||
} |
@@ -9,3 +9,3 @@ import { IDisposable } from "./Util"; | ||
export declare function averageBy(f: (a: number) => number, xs: Iterable<number>): number; | ||
export declare function countBy<T, K>(f: (x: T) => K, xs: Iterable<T>): Iterable<(K | number)[]>; | ||
export declare function countBy<T, K>(f: (x: T) => K, xs: Iterable<T>): Iterable<(number | K)[]>; | ||
export declare function concat<T>(xs: Iterable<Iterable<T>>): Iterable<T>; | ||
@@ -54,4 +54,4 @@ export declare function collect<T, U>(f: (x: T) => Iterable<U>, xs: Iterable<T>): Iterable<U>; | ||
export declare function map3<T1, T2, T3, U>(f: (x: T1, y: T2, z: T3) => U, xs: Iterable<T1>, ys: Iterable<T2>, zs: Iterable<T3>): Iterable<U>; | ||
export declare function mapFold<T, ST, R>(f: (acc: ST, x: T) => [R, ST], acc: ST, xs: Iterable<T>): (Iterable<R> | ST)[]; | ||
export declare function mapFoldBack<T, ST, R>(f: (x: T, acc: ST) => [R, ST], xs: Iterable<T>, acc: ST): (Iterable<R> | ST)[]; | ||
export declare function mapFold<T, ST, R>(f: (acc: ST, x: T) => [R, ST], acc: ST, xs: Iterable<T>): (ST | Iterable<R>)[]; | ||
export declare function mapFoldBack<T, ST, R>(f: (x: T, acc: ST) => [R, ST], xs: Iterable<T>, acc: ST): (ST | Iterable<R>)[]; | ||
export declare function max<T extends number>(xs: Iterable<T>): T; | ||
@@ -58,0 +58,0 @@ export declare function maxBy<T, U extends number>(f: (x: T) => U, xs: Iterable<T>): T; |
export declare function toJson(o: any): string; | ||
export declare function inflate(val: any, typ: any): any; | ||
export declare function ofJson(json: any, typ: any): any; | ||
declare function inflatePublic(val: any, genArgs: any): any; | ||
export { inflatePublic as inflate }; | ||
export declare function ofJson(json: any, genArgs: any): any; | ||
export declare function toJsonWithTypeInfo(o: any): string; | ||
export declare function ofJsonWithTypeInfo(json: any, expected?: Function): any; | ||
export declare function ofJsonWithTypeInfo(json: any, genArgs: any): any; |
"use strict"; | ||
exports.__esModule = true; | ||
exports.inflate = undefined; | ||
@@ -8,3 +9,2 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
exports.toJson = toJson; | ||
exports.inflate = inflate; | ||
exports.ofJson = ofJson; | ||
@@ -195,5 +195,9 @@ exports.toJsonWithTypeInfo = toJsonWithTypeInfo; | ||
} | ||
function ofJson(json, typ) { | ||
return inflate(JSON.parse(json), typ); | ||
function inflatePublic(val, genArgs) { | ||
return inflate(val, genArgs ? genArgs.T : null); | ||
} | ||
exports.inflate = inflatePublic; | ||
function ofJson(json, genArgs) { | ||
return inflate(JSON.parse(json), genArgs ? genArgs.T : null); | ||
} | ||
function toJsonWithTypeInfo(o) { | ||
@@ -213,3 +217,3 @@ return JSON.stringify(o, function (k, v) { | ||
} else if (v[_Symbol2.default.typeName]) { | ||
if ((0, _Util.hasInterface)(v, "FSharpUnion", "FSharpRecord")) { | ||
if ((0, _Util.hasInterface)(v, "FSharpUnion") || (0, _Util.hasInterface)(v, "FSharpRecord")) { | ||
return Object.assign({ $type: v[_Symbol2.default.typeName]() }, v); | ||
@@ -231,3 +235,3 @@ } else { | ||
} | ||
function ofJsonWithTypeInfo(json, expected) { | ||
function ofJsonWithTypeInfo(json, genArgs) { | ||
var parsed = JSON.parse(json, function (k, v) { | ||
@@ -272,2 +276,3 @@ if (v == null) return v;else if ((typeof v === "undefined" ? "undefined" : _typeof(v)) === "object" && typeof v.$type === "string") { | ||
}); | ||
var expected = genArgs ? genArgs.T : null; | ||
if (parsed != null && typeof expected === "function" && !(parsed instanceof (0, _Util.getDefinition)(expected))) { | ||
@@ -274,0 +279,0 @@ throw "JSON is not of type " + expected.name + ": " + json; |
@@ -26,3 +26,3 @@ import { IComparer } from "./Util"; | ||
clear(): void; | ||
size: number; | ||
readonly size: number; | ||
} | ||
@@ -29,0 +29,0 @@ export declare function create<T>(ie?: Iterable<T>, comparer?: IComparer<T>): FSet<T>; |
@@ -706,3 +706,3 @@ "use strict"; | ||
FSet.prototype.CompareTo = function CompareTo(s2) { | ||
return tree_compare(this.comparer, this.tree, s2.tree); | ||
return this === s2 ? 0 : tree_compare(this.comparer, this.tree, s2.tree); | ||
}; | ||
@@ -709,0 +709,0 @@ |
@@ -12,3 +12,3 @@ import { IDisposable } from "./Util"; | ||
constructor(interval?: number); | ||
Elapsed: Event<Date>; | ||
readonly Elapsed: Event<Date>; | ||
Enabled: boolean; | ||
@@ -15,0 +15,0 @@ Dispose(): void; |
@@ -35,3 +35,3 @@ export declare const enum TypeKind { | ||
export declare function extendInfo(cons: FunctionConstructor, symbolName: string, info: any): any; | ||
export declare function hasInterface(obj: any, ...interfaceNames: string[]): any; | ||
export declare function hasInterface(obj: any, interfaceName: string): boolean; | ||
export declare function getRestParams(args: ArrayLike<any>, idx: number): any[]; | ||
@@ -38,0 +38,0 @@ export declare function toString(o: any): any; |
83
Util.js
@@ -75,10 +75,5 @@ "use strict"; | ||
} | ||
function hasInterface(obj) { | ||
for (var _len2 = arguments.length, interfaceNames = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
interfaceNames[_key2 - 1] = arguments[_key2]; | ||
} | ||
return obj[_Symbol2.default.interfaces] && obj[_Symbol2.default.interfaces]().some(function (x) { | ||
return interfaceNames.indexOf(x) >= 0; | ||
}); | ||
function hasInterface(obj, interfaceName) { | ||
var interfaces = typeof obj[_Symbol2.default.interfaces] === "function" ? obj[_Symbol2.default.interfaces]() : obj[_Symbol2.default.interfaces]; | ||
return Array.isArray(interfaces) ? interfaces.indexOf(interfaceName) > -1 : interfaces === interfaceName; | ||
} | ||
@@ -104,3 +99,4 @@ function getRestParams(args, idx) { | ||
function equals(x, y) { | ||
if (x == null) return y == null;else if (y == null) return false;else if (isGeneric(x) && isGeneric(y)) return getDefinition(x) === getDefinition(y) && equalsRecords(x.prototype[_Symbol2.default.generics](), y.prototype[_Symbol2.default.generics]());else if (Object.getPrototypeOf(x) !== Object.getPrototypeOf(y)) return false;else if (Array.isArray(x)) { | ||
// Optimization if they are referencially equal | ||
if (x === y) return true;else if (x == null) return y == null;else if (y == null) return false;else if (isGeneric(x) && isGeneric(y)) return getDefinition(x) === getDefinition(y) && equalsRecords(x.prototype[_Symbol2.default.generics](), y.prototype[_Symbol2.default.generics]());else if (Object.getPrototypeOf(x) !== Object.getPrototypeOf(y)) return false;else if (typeof x.Equals === "function") return x.Equals(y);else if (Array.isArray(x)) { | ||
if (x.length != y.length) return false; | ||
@@ -117,6 +113,8 @@ for (var i = 0; i < x.length; i++) { | ||
}return true; | ||
} else if (x instanceof Date) return x.getTime() == y.getTime();else if (hasInterface(x, "System.IEquatable")) return x.Equals(y);else return x === y; | ||
} else if (x instanceof Date) return x.getTime() == y.getTime();else return false; | ||
} | ||
function compare(x, y) { | ||
if (x == null) return y == null ? 0 : -1;else if (y == null) return -1;else if (Object.getPrototypeOf(x) !== Object.getPrototypeOf(y)) return -1;else if (Array.isArray(x)) { | ||
// Optimization if they are referencially equal | ||
if (x === y) return 0; | ||
if (x == null) return y == null ? 0 : -1;else if (y == null) return -1;else if (Object.getPrototypeOf(x) !== Object.getPrototypeOf(y)) return -1;else if (hasInterface(x, "System.IComparable")) return x.CompareTo(y);else if (Array.isArray(x)) { | ||
if (x.length != y.length) return x.length < y.length ? -1 : 1; | ||
@@ -136,34 +134,55 @@ for (var i = 0, j = 0; i < x.length; i++) { | ||
return 0; | ||
} else if (hasInterface(x, "System.IComparable")) return x.CompareTo(y);else return x < y ? -1 : x > y ? 1 : 0; | ||
} else if (x instanceof Date) return compare(x.getTime(), y.getTime());else return x < y ? -1 : 1; | ||
} | ||
function equalsRecords(x, y) { | ||
var keys = Object.getOwnPropertyNames(x); | ||
for (var i = 0; i < keys.length; i++) { | ||
if (!equals(x[keys[i]], y[keys[i]])) return false; | ||
// Optimization if they are referencially equal | ||
if (x === y) { | ||
return true; | ||
} else { | ||
var keys = Object.getOwnPropertyNames(x); | ||
for (var i = 0; i < keys.length; i++) { | ||
if (!equals(x[keys[i]], y[keys[i]])) return false; | ||
} | ||
return true; | ||
} | ||
return true; | ||
} | ||
function compareRecords(x, y) { | ||
var keys = Object.getOwnPropertyNames(x); | ||
for (var i = 0; i < keys.length; i++) { | ||
var res = compare(x[keys[i]], y[keys[i]]); | ||
if (res !== 0) return res; | ||
// Optimization if they are referencially equal | ||
if (x === y) { | ||
return 0; | ||
} else { | ||
var keys = Object.getOwnPropertyNames(x); | ||
for (var i = 0; i < keys.length; i++) { | ||
var res = compare(x[keys[i]], y[keys[i]]); | ||
if (res !== 0) return res; | ||
} | ||
return 0; | ||
} | ||
return 0; | ||
} | ||
function equalsUnions(x, y) { | ||
if (x.Case !== y.Case) return false; | ||
for (var i = 0; i < x.Fields.length; i++) { | ||
if (!equals(x.Fields[i], y.Fields[i])) return false; | ||
// Optimization if they are referencially equal | ||
if (x === y) { | ||
return true; | ||
} else if (x.Case !== y.Case) { | ||
return false; | ||
} else { | ||
for (var i = 0; i < x.Fields.length; i++) { | ||
if (!equals(x.Fields[i], y.Fields[i])) return false; | ||
} | ||
return true; | ||
} | ||
return true; | ||
} | ||
function compareUnions(x, y) { | ||
var res = compare(x.Case, y.Case); | ||
if (res !== 0) return res; | ||
for (var i = 0; i < x.Fields.length; i++) { | ||
res = compare(x.Fields[i], y.Fields[i]); | ||
// Optimization if they are referencially equal | ||
if (x === y) { | ||
return 0; | ||
} else { | ||
var res = compare(x.Case, y.Case); | ||
if (res !== 0) return res; | ||
for (var i = 0; i < x.Fields.length; i++) { | ||
res = compare(x.Fields[i], y.Fields[i]); | ||
if (res !== 0) return res; | ||
} | ||
return 0; | ||
} | ||
return 0; | ||
} | ||
@@ -175,5 +194,3 @@ function createDisposable(f) { | ||
Dispose: f | ||
}, _ref[_Symbol2.default.interfaces] = function () { | ||
return ["System.IDisposable"]; | ||
}, _ref; | ||
}, _ref[_Symbol2.default.interfaces] = "System.IDisposable", _ref; | ||
} | ||
@@ -180,0 +197,0 @@ function createObj(fields) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
4480436
9769