Skip to content

Conversation

muffinresearch
Copy link
Contributor

Fixes #496

@muffinresearch muffinresearch changed the title Separate valdiation from metadata retrieval Separate validation from metadata retrieval Feb 10, 2016
@muffinresearch muffinresearch force-pushed the validation-should-be-separate branch from 0f67bc2 to 2a7a06c Compare February 10, 2016 14:53
@kumar303
Copy link
Contributor

I would be ok with this but a method that depends on another is always a sign of clunkiness to me. The question to ask is: would you ever need to get metadata without validating the manifest first? I think the answer is no. If that's true, you could change the class to this:

export default class ManifestJSONParser {

  constructor(jsonString, collector) {
    this.parsedJSON = JSON.parse(jsonString);
    this.collector = collector;
    this.isValid = this._validate();
  }
  ...
}

The only downside is it conceals the fact that some potentially costly validation is taking place inside the constructor. I think the upside of making the getMetaData() function more easy to work with is worth the trade-off though.

r+wc

@muffinresearch
Copy link
Contributor Author

It's all swings and roundabouts!

I was working on the basis that the constructor shouldn't do too much, but I see what you're saying and I think you're right - it's probably a touch cleaner your way on balance.

@muffinresearch
Copy link
Contributor Author

@kumar303 ok this is ready for another look.

var result = new ManifestJSONParser(
json, this.collector).getMetadata();
return result.metadata;
var manifestParser = new ManifestJSONParser(json, this.collector);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be let manifestParser...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm tending to use let when needed. Inside a function like this there's no difference between var and let.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...and even then I forget to sometimes - old habits die hard.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whatever works. I've been trying to always use let unless var is needed. My rationale is that a code refactor might introduce a new block (a line down from your closure, for example) that could leak the variable.

@kumar303
Copy link
Contributor

r+wc

@muffinresearch muffinresearch force-pushed the validation-should-be-separate branch from 2ad4d5a to 7690dec Compare February 12, 2016 17:41
muffinresearch added a commit that referenced this pull request Feb 12, 2016
…rate

Separate validation from metadata retrieval
@muffinresearch muffinresearch merged commit bd18a4e into mozilla:master Feb 12, 2016
@muffinresearch muffinresearch deleted the validation-should-be-separate branch February 12, 2016 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants