Skip to content

Commit

Permalink
Now can inherit fsManager from parent
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienCastex committed May 12, 2017
1 parent 9cf0b9f commit a844417
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
8 changes: 7 additions & 1 deletion lib/resource/PhysicalResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ var fs = require("fs");
var PhysicalResource = (function (_super) {
__extends(PhysicalResource, _super);
function PhysicalResource(realPath, parent, fsManager) {
var _this = _super.call(this, parent, fsManager) || this;
var _this = this;
if (!fsManager)
if (parent && parent.fsManager && parent.fsManager.constructor === PhysicalFSManager)
fsManager = parent.fsManager;
else
fsManager = new PhysicalFSManager();
_this = _super.call(this, parent, fsManager) || this;
_this.realPath = path.resolve(realPath);
return _this;
}
Expand Down
8 changes: 7 additions & 1 deletion lib/resource/VirtualResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ var mimeTypes = require("mime-types");
var VirtualResource = (function (_super) {
__extends(VirtualResource, _super);
function VirtualResource(name, parent, fsManager) {
var _this = _super.call(this, parent, fsManager ? fsManager : new VirtualFSManager_1.VirtualFSManager()) || this;
var _this = this;
if (!fsManager)
if (parent && parent.fsManager && parent.fsManager.constructor === VirtualFSManager_1.VirtualFSManager)
fsManager = parent.fsManager;
else
fsManager = VirtualFSManager_1.VirtualFSManager.Instance();
_this = _super.call(this, parent, fsManager) || this;
_this.name = name;
return _this;
}
Expand Down
6 changes: 6 additions & 0 deletions src/resource/PhysicalResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ export abstract class PhysicalResource extends StandardResource

constructor(realPath : string, parent ?: IResource, fsManager ?: FSManager)
{
if(!fsManager)
if(parent && parent.fsManager && parent.fsManager.constructor === PhysicalFSManager)
fsManager = parent.fsManager;
else
fsManager = new PhysicalFSManager();

super(parent, fsManager);

this.realPath = path.resolve(realPath);
Expand Down
8 changes: 7 additions & 1 deletion src/resource/VirtualResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ export abstract class VirtualResource extends StandardResource

constructor(name : string, parent ?: IResource, fsManager ?: FSManager)
{
super(parent, fsManager ? fsManager : new VirtualFSManager());
if(!fsManager)
if(parent && parent.fsManager && parent.fsManager.constructor === VirtualFSManager)
fsManager = parent.fsManager;
else
fsManager = VirtualFSManager.Instance();

super(parent, fsManager);

this.name = name;
}
Expand Down

0 comments on commit a844417

Please sign in to comment.