Skip to content

Commit

Permalink
fix(trace): Support tracing of object-parameters with circular refere…
Browse files Browse the repository at this point in the history
…nces

Closes #75
  • Loading branch information
christopherthielen committed Sep 16, 2017
1 parent ada9ca2 commit 2f1ae9a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
13 changes: 6 additions & 7 deletions src/params/paramTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,15 +286,15 @@ 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({
encode: function(val: any) {
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) {
Expand All @@ -305,18 +305,18 @@ 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({
encode: toJson,
decode: fromJson,
is: is(Object),
equals: equals,
pattern: /[^/]*/
pattern: /[^/]*/,
}),

// does not encode/decode
Expand All @@ -326,8 +326,7 @@ function initDefaultTypes() {
is: () => true,
equals: equals,
}),
})

});
}

initDefaultTypes();
Expand Down
4 changes: 2 additions & 2 deletions src/state/targetState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]].
Expand Down Expand Up @@ -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 */
Expand Down
9 changes: 4 additions & 5 deletions src/transition/transition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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} )`;
}
Expand Down

0 comments on commit 2f1ae9a

Please sign in to comment.