Skip to content

Commit 3f3d0c6

Browse files
author
Vlad Balin
committed
Fixed nodejs logging
1 parent e06e352 commit 3f3d0c6

File tree

11 files changed

+123
-17
lines changed

11 files changed

+123
-17
lines changed

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/object-plus/tools.js

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/object-plus/tools.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "type-r",
3-
"version": "2.0.7",
3+
"version": "2.0.8",
44
"description": "Reactive serializable data layer for modern JS applications",
55
"main": "./dist/index.js",
66
"jsnext:main": "./lib/index.js",

src/object-plus/tools.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,28 @@ log.level = typeof process !== 'undefined' && process.env && process.env.NODE_EN
5757
log.throw = 0;
5858
log.stop = 0;
5959

60+
61+
let toString = typeof window === 'undefined' ?
62+
function toString( something ){
63+
if( something && typeof something === 'object' ){
64+
const value = something.__inner_state__ || something,
65+
isTransactional = Boolean( something.__inner_state__ ),
66+
isArray = Array.isArray( value );
67+
68+
const keys = Object.keys( value ).join( ', ' ),
69+
body = isArray ? `[ length = ${ value.length } ]` : `{ ${ keys } }`;
70+
71+
return something.constructor.name + ' ' + body;
72+
}
73+
74+
return something;
75+
} : function toString( x ){ return x; };
76+
6077
if( typeof console !== 'undefined' ) {
6178
log.logger = function _console( level : LogLevel, error : string, props : object ){
6279
const args = [ error ];
6380
for( let name in props ){
64-
args.push( `\n\t${name}:`, props[ name ] );
81+
args.push( `\n\t${name}:`, toString( props[ name ] ) );
6582
}
6683

6784
console[ level ].apply( console, args );

tests/typescript/dist/index.js

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,20 @@ var log = function (a_level, a_msg, a_props) {
9292
log.level = typeof process !== 'undefined' && process.env && process.env.NODE_ENV === 'production' ? 1 : 2;
9393
log.throw = 0;
9494
log.stop = 0;
95+
var toString = typeof window === 'undefined' ?
96+
function toString(something) {
97+
if (something && typeof something === 'object') {
98+
var value = something.__inner_state__ || something, isTransactional = Boolean(something.__inner_state__), isArray = Array.isArray(value);
99+
var keys_1 = Object.keys(value).join(', '), body = isArray ? "[ length = " + value.length + " ]" : "{ " + keys_1 + " }";
100+
return something.constructor.name + ' ' + body;
101+
}
102+
return something;
103+
} : function toString(x) { return x; };
95104
if (typeof console !== 'undefined') {
96105
log.logger = function _console(level, error, props) {
97106
var args = [error];
98107
for (var name_1 in props) {
99-
args.push("\n\t" + name_1 + ":", props[name_1]);
108+
args.push("\n\t" + name_1 + ":", toString(props[name_1]));
100109
}
101110
console[level].apply(console, args);
102111
};
@@ -4414,7 +4423,7 @@ var getActual$1 = function getActual(obj, args) {
44144423
* @api public
44154424
*/
44164425

4417-
var toString = Function.prototype.toString;
4426+
var toString$1 = Function.prototype.toString;
44184427
var functionNameMatch = /\s*function(?:\s|\s*\/\*[^(?:*\/)]+\*\/\s*)*([^\s\(\/]+)/;
44194428
function getFuncName(aFunc) {
44204429
if (typeof aFunc !== 'function') {
@@ -4424,7 +4433,7 @@ function getFuncName(aFunc) {
44244433
var name = '';
44254434
if (typeof Function.prototype.name === 'undefined' && typeof aFunc.name === 'undefined') {
44264435
// Here we run a polyfill if Function does not support the `name` property and if aFunc.name is not defined
4427-
var match = toString.call(aFunc).match(functionNameMatch);
4436+
var match = toString$1.call(aFunc).match(functionNameMatch);
44284437
if (match) {
44294438
name = match[1];
44304439
}
@@ -16269,7 +16278,6 @@ describe('Bugs from Volicon Observer', function () {
1626916278
var Placeholder = Record.extend({
1627016279
attributes: {
1627116280
subEncoders: SubEncoder.Collection.has.check(function (x) {
16272-
console.log('SubEncoders', this, x);
1627316281
return x.length > 0;
1627416282
}, 'ccccc')
1627516283
}
@@ -16321,7 +16329,38 @@ describe('Bugs from Volicon Observer', function () {
1632116329
chai_1(target.inner).to.be.null;
1632216330
target.assignFrom(source);
1632316331
chai_1(target.inner !== source.inner).to.be.true;
16324-
console.log(target.inner.cid, source.inner.cid);
16332+
});
16333+
it('assign object of similar shape', function () {
16334+
var A = (function (_super) {
16335+
__extends(A, _super);
16336+
function A() {
16337+
return _super !== null && _super.apply(this, arguments) || this;
16338+
}
16339+
__decorate([
16340+
attr,
16341+
__metadata("design:type", String)
16342+
], A.prototype, "a", void 0);
16343+
A = __decorate([
16344+
define
16345+
], A);
16346+
return A;
16347+
}(Record));
16348+
var B = (function (_super) {
16349+
__extends(B, _super);
16350+
function B() {
16351+
return _super !== null && _super.apply(this, arguments) || this;
16352+
}
16353+
__decorate([
16354+
attr,
16355+
__metadata("design:type", String)
16356+
], B.prototype, "b", void 0);
16357+
B = __decorate([
16358+
define
16359+
], B);
16360+
return B;
16361+
}(A));
16362+
var b = new B({ b: "b" }), a = new A({ a: "a" });
16363+
b.assignFrom(a);
1632516364
});
1632616365
});
1632716366
});

tests/typescript/dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/typescript/lib/reported-bugs.js

Lines changed: 32 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)