Skip to content

Commit

Permalink
Fixed the RootFSManager's 'newResource' method to inherit a VirtualFS…
Browse files Browse the repository at this point in the history
…Manager to created children instead of the RootFSManager itself
  • Loading branch information
AdrienCastex committed May 27, 2017
1 parent 6a7084a commit 84cb9cd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 20 deletions.
7 changes: 4 additions & 3 deletions lib/manager/RootFSManager.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { IResource } from '../resource/IResource';
import { VirtualFSManager } from './VirtualFSManager';
import { IResource, ResourceType } from '../resource/IResource';
import { SerializedObject } from './ISerializer';
export declare class RootFSManager extends VirtualFSManager {
import { FSManager } from './FSManager';
export declare class RootFSManager implements FSManager {
uid: string;
serialize(resource: any, obj: SerializedObject): object;
unserialize(data: any, obj: SerializedObject): IResource;
newResource(fullPath: string, name: string, type: ResourceType, parent: IResource): IResource;
}
30 changes: 14 additions & 16 deletions lib/manager/RootFSManager.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var VirtualFSManager_1 = require("./VirtualFSManager");
var VirtualFolder_1 = require("../resource/virtual/VirtualFolder");
var RootResource_1 = require("../resource/std/RootResource");
var RootFSManager = (function (_super) {
__extends(RootFSManager, _super);
var VirtualFile_1 = require("../resource/virtual/VirtualFile");
var Errors_1 = require("../Errors");
var virtualFSManager = new VirtualFSManager_1.VirtualFSManager();
var RootFSManager = (function () {
function RootFSManager() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.uid = 'RootFSManager_1.0.2';
return _this;
this.uid = 'RootFSManager_1.0.2';
}
RootFSManager.prototype.serialize = function (resource, obj) {
return {
Expand All @@ -35,6 +26,13 @@ var RootFSManager = (function (_super) {
rs.properties = data.properties;
return rs;
};
RootFSManager.prototype.newResource = function (fullPath, name, type, parent) {
if (type.isDirectory)
return new VirtualFolder_1.VirtualFolder(name, parent, virtualFSManager);
if (type.isFile)
return new VirtualFile_1.VirtualFile(name, parent, virtualFSManager);
throw Errors_1.Errors.UnrecognizedResource;
};
return RootFSManager;
}(VirtualFSManager_1.VirtualFSManager));
}());
exports.RootFSManager = RootFSManager;
17 changes: 16 additions & 1 deletion src/manager/RootFSManager.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { IResource, ResourceType } from '../resource/IResource'
import { VirtualFSManager } from './VirtualFSManager'
import { SerializedObject } from './ISerializer'
import { VirtualFolder } from '../resource/virtual/VirtualFolder'
import { RootResource } from '../resource/std/RootResource'
import { VirtualFile } from '../resource/virtual/VirtualFile'
import { FSManager } from './FSManager'
import { Errors } from '../Errors'

export class RootFSManager extends VirtualFSManager
const virtualFSManager = new VirtualFSManager();

export class RootFSManager implements FSManager
{
uid : string = 'RootFSManager_1.0.2';

Expand All @@ -27,4 +32,14 @@ export class RootFSManager extends VirtualFSManager
rs.properties = data.properties;
return rs;
}

newResource(fullPath : string, name : string, type : ResourceType, parent : IResource) : IResource
{
if(type.isDirectory)
return new VirtualFolder(name, parent, virtualFSManager);
if(type.isFile)
return new VirtualFile(name, parent, virtualFSManager);

throw Errors.UnrecognizedResource;
}
}

0 comments on commit 84cb9cd

Please sign in to comment.