From 2f1ae9a2884fc8e0279383d96cfd071235cbe480 Mon Sep 17 00:00:00 2001 From: Chris Thielen Date: Sat, 16 Sep 2017 15:53:07 -0700 Subject: [PATCH] fix(trace): Support tracing of object-parameters with circular references Closes https://github.com/ui-router/core/issues/75 --- src/params/paramTypes.ts | 13 ++++++------- src/state/targetState.ts | 4 ++-- src/transition/transition.ts | 9 ++++----- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/params/paramTypes.ts b/src/params/paramTypes.ts index 6452efc9..622c5c5d 100644 --- a/src/params/paramTypes.ts +++ b/src/params/paramTypes.ts @@ -286,7 +286,7 @@ function initDefaultTypes() { encode: (val: any) => val && 1 || 0, decode: (val: string) => parseInt(val, 10) !== 0, is: is(Boolean), - pattern: /0|1/ + pattern: /0|1/, }), date: makeDefaultType({ @@ -294,7 +294,7 @@ function initDefaultTypes() { return !this.is(val) ? undefined : [ val.getFullYear(), ('0' + (val.getMonth() + 1)).slice(-2), - ('0' + val.getDate()).slice(-2) + ('0' + val.getDate()).slice(-2), ].join("-"); }, decode: function(val: string) { @@ -305,10 +305,10 @@ function initDefaultTypes() { is: (val: any) => val instanceof Date && !isNaN(val.valueOf()), equals(l: any, r: any) { return ['getFullYear', 'getMonth', 'getDate'] - .reduce((acc, fn) => acc && l[fn]() === r[fn](), true) + .reduce((acc, fn) => acc && l[fn]() === r[fn](), true); }, pattern: /[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/, - capture: /([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/ + capture: /([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/, }), json: makeDefaultType({ @@ -316,7 +316,7 @@ function initDefaultTypes() { decode: fromJson, is: is(Object), equals: equals, - pattern: /[^/]*/ + pattern: /[^/]*/, }), // does not encode/decode @@ -326,8 +326,7 @@ function initDefaultTypes() { is: () => true, equals: equals, }), - }) - + }); } initDefaultTypes(); diff --git a/src/state/targetState.ts b/src/state/targetState.ts index 04774f10..f0ec8174 100644 --- a/src/state/targetState.ts +++ b/src/state/targetState.ts @@ -7,8 +7,8 @@ import { StateDeclaration, StateOrName, TargetStateDef } from "./interface"; import { ParamsOrArray } from "../params/interface"; import { TransitionOptions } from "../transition/interface"; import { StateObject } from "./stateObject"; -import { toJson } from "../common/common"; import { isString } from "../common/predicates"; +import { stringify } from '../common/strings'; /** * Encapsulate the target (destination) state/params/options of a [[Transition]]. @@ -119,7 +119,7 @@ export class TargetState { } toString() { - return `'${this.name()}'${toJson(this.params())}`; + return `'${this.name()}'${stringify(this.params())}`; } /** Returns true if the object has a state property that might be a state or state name */ diff --git a/src/transition/transition.ts b/src/transition/transition.ts index eb5ed12c..a3a5c5fb 100644 --- a/src/transition/transition.ts +++ b/src/transition/transition.ts @@ -5,9 +5,8 @@ /** for typedoc */ import { trace } from '../common/trace'; import { services } from '../common/coreservices'; -import { - map, find, extend, mergeR, tail, omit, toJson, arrayTuples, unnestR, identity, anyTrueR, -} from '../common/common'; +import { stringify } from '../common/strings'; +import { map, find, extend, mergeR, tail, omit, arrayTuples, unnestR, identity, anyTrueR } from '../common/common'; import {isObject, isUndefined} from '../common/predicates'; import { prop, propEq, val, not, is } from '../common/hof'; import { StateDeclaration, StateOrName } from '../state/interface'; @@ -753,10 +752,10 @@ export class Transition implements IHookRegistry { // (X) means the to state is invalid. let id = this.$id, from = isObject(fromStateOrName) ? fromStateOrName.name : fromStateOrName, - fromParams = toJson(avoidEmptyHash(this._treeChanges.from.map(prop('paramValues')).reduce(mergeR, {}))), + fromParams = stringify(avoidEmptyHash(this._treeChanges.from.map(prop('paramValues')).reduce(mergeR, {}))), toValid = this.valid() ? "" : "(X) ", to = isObject(toStateOrName) ? toStateOrName.name : toStateOrName, - toParams = toJson(avoidEmptyHash(this.params())); + toParams = stringify(avoidEmptyHash(this.params())); return `Transition#${id}( '${from}'${fromParams} -> ${toValid}'${to}'${toParams} )`; }