-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add toJSON method for good stringify #51
Conversation
* | ||
* @returns {*} | ||
*/ | ||
toJSON() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I call method toJSON
I expect to have a json here. This method should be getData
maybe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's for JSON.stringify
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not to call JSON.stringify here if this is only for such purpose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't use this class with JSON.stringify without this method, sorry. It should return raw data, not string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Than this method differs from the valueOf method?
@@ -222,6 +222,14 @@ module.exports = class BemEntityName { | |||
return `BemEntityName ${stringRepresentation}`; | |||
} | |||
/** | |||
* Return raw data for JSON.stringify. | |||
* | |||
* @returns {*} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why *
?
this._data
has the schema:
/**
* @returns {{block: string, elem: ?string, mod: ?{name: ?string, val: *}}}
*/
* @returns {*} | ||
*/ | ||
toJSON() { | ||
return this._data; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You want add alias? Then it is better to specify it explicitly:
return this.valueOf();
@zxqfox I think you need to use the |
cc @blond @kriant