Skip to content
This repository has been archived by the owner on Feb 4, 2018. It is now read-only.

feat: add toJSON method for good stringify #51

Closed
wants to merge 1 commit into from
Closed

Conversation

qfox
Copy link
Contributor

@qfox qfox commented Oct 6, 2016

*
* @returns {*}
*/
toJSON() {
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Contributor Author

@qfox qfox Oct 7, 2016

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.

Copy link
Member

@blond blond left a 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 {*}
Copy link
Member

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;
Copy link
Member

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();

@blond
Copy link
Member

blond commented Nov 25, 2016

@zxqfox I think you need to use the valueOf() method. Reopen this PR if you have reason to have toJSON method.

@blond blond closed this Nov 25, 2016
@blond blond added wontfix and removed in progress labels Nov 25, 2016
@blond blond deleted the qfox.feat-tojson branch November 25, 2016 15:15
@qfox qfox restored the qfox.feat-tojson branch December 14, 2016 00:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants