Skip to content

Commit 2f1ae9a

Browse files
fix(trace): Support tracing of object-parameters with circular references
Closes #75
1 parent ada9ca2 commit 2f1ae9a

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

src/params/paramTypes.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -286,15 +286,15 @@ function initDefaultTypes() {
286286
encode: (val: any) => val && 1 || 0,
287287
decode: (val: string) => parseInt(val, 10) !== 0,
288288
is: is(Boolean),
289-
pattern: /0|1/
289+
pattern: /0|1/,
290290
}),
291291

292292
date: makeDefaultType({
293293
encode: function(val: any) {
294294
return !this.is(val) ? undefined : [
295295
val.getFullYear(),
296296
('0' + (val.getMonth() + 1)).slice(-2),
297-
('0' + val.getDate()).slice(-2)
297+
('0' + val.getDate()).slice(-2),
298298
].join("-");
299299
},
300300
decode: function(val: string) {
@@ -305,18 +305,18 @@ function initDefaultTypes() {
305305
is: (val: any) => val instanceof Date && !isNaN(val.valueOf()),
306306
equals(l: any, r: any) {
307307
return ['getFullYear', 'getMonth', 'getDate']
308-
.reduce((acc, fn) => acc && l[fn]() === r[fn](), true)
308+
.reduce((acc, fn) => acc && l[fn]() === r[fn](), true);
309309
},
310310
pattern: /[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,
311-
capture: /([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/
311+
capture: /([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/,
312312
}),
313313

314314
json: makeDefaultType({
315315
encode: toJson,
316316
decode: fromJson,
317317
is: is(Object),
318318
equals: equals,
319-
pattern: /[^/]*/
319+
pattern: /[^/]*/,
320320
}),
321321

322322
// does not encode/decode
@@ -326,8 +326,7 @@ function initDefaultTypes() {
326326
is: () => true,
327327
equals: equals,
328328
}),
329-
})
330-
329+
});
331330
}
332331

333332
initDefaultTypes();

src/state/targetState.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { StateDeclaration, StateOrName, TargetStateDef } from "./interface";
77
import { ParamsOrArray } from "../params/interface";
88
import { TransitionOptions } from "../transition/interface";
99
import { StateObject } from "./stateObject";
10-
import { toJson } from "../common/common";
1110
import { isString } from "../common/predicates";
11+
import { stringify } from '../common/strings';
1212

1313
/**
1414
* Encapsulate the target (destination) state/params/options of a [[Transition]].
@@ -119,7 +119,7 @@ export class TargetState {
119119
}
120120

121121
toString() {
122-
return `'${this.name()}'${toJson(this.params())}`;
122+
return `'${this.name()}'${stringify(this.params())}`;
123123
}
124124

125125
/** Returns true if the object has a state property that might be a state or state name */

src/transition/transition.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
/** for typedoc */
66
import { trace } from '../common/trace';
77
import { services } from '../common/coreservices';
8-
import {
9-
map, find, extend, mergeR, tail, omit, toJson, arrayTuples, unnestR, identity, anyTrueR,
10-
} from '../common/common';
8+
import { stringify } from '../common/strings';
9+
import { map, find, extend, mergeR, tail, omit, arrayTuples, unnestR, identity, anyTrueR } from '../common/common';
1110
import {isObject, isUndefined} from '../common/predicates';
1211
import { prop, propEq, val, not, is } from '../common/hof';
1312
import { StateDeclaration, StateOrName } from '../state/interface';
@@ -753,10 +752,10 @@ export class Transition implements IHookRegistry {
753752
// (X) means the to state is invalid.
754753
let id = this.$id,
755754
from = isObject(fromStateOrName) ? fromStateOrName.name : fromStateOrName,
756-
fromParams = toJson(avoidEmptyHash(this._treeChanges.from.map(prop('paramValues')).reduce(mergeR, {}))),
755+
fromParams = stringify(avoidEmptyHash(this._treeChanges.from.map(prop('paramValues')).reduce(mergeR, {}))),
757756
toValid = this.valid() ? "" : "(X) ",
758757
to = isObject(toStateOrName) ? toStateOrName.name : toStateOrName,
759-
toParams = toJson(avoidEmptyHash(this.params()));
758+
toParams = stringify(avoidEmptyHash(this.params()));
760759

761760
return `Transition#${id}( '${from}'${fromParams} -> ${toValid}'${to}'${toParams} )`;
762761
}

0 commit comments

Comments
 (0)