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

feat(clone): option to not clone buffer, support custom properties #16

Closed
wants to merge 1 commit into from
Closed

feat(clone): option to not clone buffer, support custom properties #16

wants to merge 1 commit into from

Conversation

laurelnaiad
Copy link
Contributor

option { contents: false } causes the clone to reference-copy buffer contents.

Custom properties that exist in the original file are deep-cloned to the new File.

option `{ contents: false }` causes the clone to reference-copy buffer contents.

Custom properties that exist in the original file are deep-cloned to the new File.
var clone = new File();

Object.keys(this).forEach(function(key) {
if (key !== '_contents' && key !== 'stat' && this.hasOwnProperty(key)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

hasOwnProperty is unnecessary as Object.keys() doesn't include properties of the prototype chain.

Copy link
Member

Choose a reason for hiding this comment

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

hasOwnProperty is redundant, where does _contents come from? That isn't a standard attribute

Copy link
Contributor

Choose a reason for hiding this comment

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

@contra _contents is an internal property (L113-L123) because contents is virtual.

@yocontra
Copy link
Member

Sorry for letting this sit for so long, I was traveling. I will look at this now

clone.contents = this.contents;
}

clone.stat = this.stat ? cloneStats(this.stat) : null;
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't all attributes follow the same code path? If opt[k] === false then reference, else clone?

@popomore
Copy link
Contributor

popomore commented Jul 4, 2014

How about this PR? I want this feature.

@yocontra
Copy link
Member

yocontra commented Jul 5, 2014

In the woods with bad internet connection right now. I will review when I'm back in town

@popomore
Copy link
Contributor

popomore commented Jul 5, 2014

All right, have a good travel—
Sent from Mailbox for iPhone

On Sat, Jul 5, 2014 at 1:31 PM, Eric Schoffstall notifications@github.com
wrote:

In the woods with bad internet connection right now. I will review when I'm back in town

Reply to this email directly or view it on GitHub:
#16 (comment)

@popomore
Copy link
Contributor

@contra Are you coming back, do you have time to review this pr?

@yocontra
Copy link
Member

I never got a response to the code comments I left :/

@popomore
Copy link
Contributor

Or you can review my pr #26 as you like, I just want to support this feature.

@vweevers
Copy link
Contributor

How about a PR for just the custom properties feature? Because the holdup here is about reference-copying and @stu-salsbury not responding.

@vweevers
Copy link
Contributor

@contra If you agree, I'll create that PR from stu-salsbury's code (without the reference options). (@popomore: yours doesn't do a deep clone)

@yocontra
Copy link
Member

I'll take a wholesome PR - code style matches, tests, etc. any day and merge it quickly as long as it looks good

@vweevers Send that PR

@popomore
Copy link
Contributor

Good, thx @vweevers . If you have no time, I will update my PR.

@popomore
Copy link
Contributor

deep clone has been implemented, need contents option?

@yocontra
Copy link
Member

@popomore Yep - btw could you try to use a lower level clone (like the node-v8-clone module) instead of lodash

@popomore
Copy link
Contributor

Have a try, but I just want pure javascript, especially for Windows.

@yocontra
Copy link
Member

@popomore Native modules should work fine on windows, you can make it an optionalDependency in the package.json and fallback to lodash if it fails to install

popomore added a commit to popomore/vinyl that referenced this pull request Aug 28, 2014
popomore added a commit to popomore/vinyl that referenced this pull request Aug 28, 2014
@yocontra
Copy link
Member

Fixed by #32

@yocontra yocontra closed this Aug 29, 2014
phated pushed a commit that referenced this pull request Sep 27, 2016
phated pushed a commit that referenced this pull request Sep 27, 2016
phated pushed a commit that referenced this pull request Sep 27, 2016
phated pushed a commit that referenced this pull request Sep 27, 2016
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.

4 participants