-
-
Notifications
You must be signed in to change notification settings - Fork 105
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
path get/set for recording path change #24
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,12 +11,13 @@ var cloneBuffer = require('./lib/cloneBuffer'); | |
function File(file) { | ||
if (!file) file = {}; | ||
|
||
// record path change | ||
this.history = file.path ? [file.path] : []; | ||
|
||
// TODO: should this be moved to vinyl-fs? | ||
this.cwd = file.cwd || process.cwd(); | ||
this.base = file.base || this.cwd; | ||
|
||
this.path = file.path || null; | ||
|
||
// stat = fs stats object | ||
// TODO: should this be moved to vinyl-fs? | ||
this.stat = file.stat || null; | ||
|
@@ -123,4 +124,18 @@ Object.defineProperty(File.prototype, 'relative', { | |
} | ||
}); | ||
|
||
Object.defineProperty(File.prototype, 'path', { | ||
get: function() { | ||
return this.history[this.history.length - 1]; | ||
}, | ||
set: function(path) { | ||
if (typeof path !== 'string') throw new Error('path should be string'); | ||
|
||
// record history only when path changed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check for typeof string on path and throw if its not? this would make the most sense IMO vs. doing null checks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should I check empty string? The condition is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Empty string will be ignore when set the path, needn't check. Now updated |
||
if (path && path !== this.path) { | ||
this.history.push(path); | ||
} | ||
} | ||
}); | ||
|
||
module.exports = File; |
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.
Only noticed this because of the clone issue... I think this line should be
this.history = file.path ? (Array.isArray(file.path) ? file.path : [file.path]) : [];
This allows using clone like it is below.
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.
@doowb file.path will never be an array though, file.history will though
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.
That's right. I was wondering how history would be cloned when I was looking at this and I think it messed up how I was thinking of
this.path
.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.
@doowb clone will have to be rewritten for custom properties and history support