Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on May 14, 2020. It is now read-only.

Commit 906cb65

Browse files
snotrzalmoxisus
snotr
authored andcommitted
Fix function object’s prototype with toStringTag. (#85)
* Fix function object’s prototype with toStringTag. Some projects is implementing objects overriding .prototype[Symbol.toStringTag] for better read in .toString output and emulate something fancy like a type system in javascript. Unfortunately, it'll crash this project since it treat non recognized types as "Custom" and current representation is JsonValue. My patch just check for this case and use object representation instead. * Revert and move convertCustomType to objType
1 parent 8025cb4 commit 906cb65

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

‎examples/src/App.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ const getValueLabelStyle = ({ style }, nodeType, keyPath) => ({
3838
const longString =
3939
'Loremipsumdolorsitamet,consecteturadipiscingelit.Namtempusipsumutfelisdignissimauctor.Maecenasodiolectus,finibusegetultricesvel,aliquamutelit.Loremipsumdolorsitamet,consecteturadipiscingelit.Namtempusipsumutfelisdignissimauctor.Maecenasodiolectus,finibusegetultricesvel,aliquamutelit.Loremipsumdolorsitamet,consecteturadipiscingelit.Namtempusipsumutfelisdignissimauctor.Maecenasodiolectus,finibusegetultricesvel,aliquamutelit.';
4040

41+
var Custom = function(value) { this.value = value; };
42+
Custom.prototype[Symbol.toStringTag] = 'Custom';
43+
4144
const data = {
4245
array: [1, 2, 3],
4346
emptyArray: [],
@@ -83,6 +86,10 @@ const data = {
8386
{ objectKey: 'value2' }
8487
]),
8588
hugeArray: Array.from({ length: 10000 }).map((_, i) => `item #${i}`),
89+
customProfile: {
90+
avatar: new Custom('placehold.it/50x50'),
91+
name: new Custom('Name'),
92+
},
8693
longString
8794
};
8895

‎src/objType.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,10 @@ export default function objType(obj) {
44
return 'Iterable';
55
}
66

7+
if (type === 'Custom' && obj.constructor !== Object && obj instanceof Object) {
8+
// For projects implementing objects overriding `.prototype[Symbol.toStringTag]`
9+
return 'Object';
10+
}
11+
712
return type;
813
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /