Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor multipart/related logic into separate module #1400

Closed
wants to merge 2 commits into from

Conversation

simov
Copy link
Member

@simov simov commented Feb 3, 2015

I just refactored the behavior I proposed here #1283

The isChunked, setHeaders and the build methods can be used outside of this class. The related method just wraps them up, but that logic can be put somewhere else.

The reason why I pass the request instance to each method individually is because I don't think it belongs to that class as a property. I even allow the setHeaders method to modify the instance, so I contradict myself here, I know, but it seemed more logical in this case.

Other than that I really want to see a few more modules out of request before I can decide on the best approach about the instance.

I moved the boundary field into the multipart instance, no idea what was the reason to have it attached on the request instance, since it wasn't used anywhere else.

The related method sets up the self._multipart.chunked and the self._multipart.body properties, and then use them to pipe with request if needed (not the most elegant code, but that will change I guess)

if (self._multipart && self._multipart.chunked) {
  self._multipart.body.pipe(self)
}

@nylen
Copy link
Member

nylen commented Feb 3, 2015

Nice work.

Looks like you can get rid of uuid = require('node-uuid') in request.js now, right? Any others?

Other than that I really want to see a few more modules out of request before I can decide on the best approach about the instance.

I'm definitely in favor of attaching the Request instance to these "feature" classes. Logically I think it is a property of the class: each instance of a feature object has a Request that it is acting on, and they're all going to be doing things that require modifying the request state. Passing the instance in to each method is more awkward and I think you'll end up repeating that pattern in a lot of other places.

What's the reason for avoiding this? If you're worried about having lots of places where the request state is modified, it would help to have some well-defined hooks that feature modules can use.

@simov
Copy link
Member Author

simov commented Feb 3, 2015

I was left with the impression that the uuid module is used somewhere else. Just pushed a version that caches the request instance. Right now the only reliable way to find out all interactions with the request instance in this module is by searching for self.request

@simov simov mentioned this pull request Feb 5, 2015
@seanstrom
Copy link
Contributor

My comments on #1406 would apply here as well.
Good job 👍

@simov simov mentioned this pull request Feb 8, 2015
@nylen nylen closed this in #1413 Feb 11, 2015
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.

None yet

3 participants