Skip to content

Commit

Permalink
Added a constructor to help unserialization in the 'LocalPropertyMana…
Browse files Browse the repository at this point in the history
…ger' class and the 'LocalLockManager' class
  • Loading branch information
AdrienCastex committed Jun 30, 2017
1 parent 0e78d10 commit f8b3b46
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/manager/v2/fileSystem/LockManager.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface ILockManager {
}
export declare class LocalLockManager implements ILockManager {
locks: Lock[];
constructor(serializedData?: any);
getLocks(callback: ReturnCallback<Lock[]>): void;
setLock(lock: Lock, callback: SimpleCallback): void;
removeLock(uuid: string, callback: ReturnCallback<boolean>): void;
Expand Down
4 changes: 3 additions & 1 deletion lib/manager/v2/fileSystem/LockManager.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var LocalLockManager = (function () {
function LocalLockManager() {
function LocalLockManager(serializedData) {
this.locks = [];
if (serializedData)
Object.defineProperties(this, serializedData);
}
LocalLockManager.prototype.getLocks = function (callback) {
this.locks = this.locks.filter(function (lock) { return !lock.expired(); });
Expand Down
1 change: 1 addition & 0 deletions lib/manager/v2/fileSystem/PropertyManager.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface IPropertyManager {
}
export declare class LocalPropertyManager implements IPropertyManager {
properties: PropertyBag;
constructor(serializedData?: any);
setProperty(name: string, value: ResourcePropertyValue, attributes: PropertyAttributes, callback: SimpleCallback): void;
getProperty(name: string, callback: Return2Callback<ResourcePropertyValue, PropertyAttributes>): void;
removeProperty(name: string, callback: SimpleCallback): void;
Expand Down
4 changes: 3 additions & 1 deletion lib/manager/v2/fileSystem/PropertyManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
Object.defineProperty(exports, "__esModule", { value: true });
var Errors_1 = require("../../../Errors");
var LocalPropertyManager = (function () {
function LocalPropertyManager() {
function LocalPropertyManager(serializedData) {
this.properties = {};
if (serializedData)
Object.defineProperties(this, serializedData);
}
LocalPropertyManager.prototype.setProperty = function (name, value, attributes, callback) {
this.properties[name] = {
Expand Down
4 changes: 2 additions & 2 deletions lib/manager/v2/instances/VirtualFileSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ var _VirtualFileSystemResource = (function () {
this.lastModifiedDate = rs.lastModifiedDate ? rs.lastModifiedDate : Date.now();
this.creationDate = rs.creationDate ? rs.creationDate : Date.now();
this.content = rs.content ? rs.content.map(function (o) { return new Buffer(o); }) : [];
this.props = rs.props ? Object.defineProperties(new export_1.LocalPropertyManager(), rs.props) : new export_1.LocalPropertyManager();
this.locks = rs.locks ? Object.defineProperties(new export_1.LocalLockManager(), rs.locks) : new export_1.LocalLockManager();
this.props = new export_1.LocalPropertyManager(rs.props);
this.locks = new export_1.LocalLockManager();
this.size = rs.size ? rs.size : 0;
this.type = rs.type ? rs.type : export_1.ResourceType.File;
}
Expand Down
6 changes: 6 additions & 0 deletions src/manager/v2/fileSystem/LockManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ export interface ILockManager
export class LocalLockManager implements ILockManager
{
locks : Lock[] = [];

constructor(serializedData ?: any)
{
if(serializedData)
Object.defineProperties(this, serializedData as any);
}

getLocks(callback : ReturnCallback<Lock[]>) : void
{
Expand Down
6 changes: 6 additions & 0 deletions src/manager/v2/fileSystem/PropertyManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ export interface IPropertyManager
export class LocalPropertyManager implements IPropertyManager
{
properties : PropertyBag = { };

constructor(serializedData ?: any)
{
if(serializedData)
Object.defineProperties(this, serializedData as any);
}

setProperty(name : string, value : ResourcePropertyValue, attributes : PropertyAttributes, callback : SimpleCallback) : void
{
Expand Down
4 changes: 2 additions & 2 deletions src/manager/v2/instances/VirtualFileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export class _VirtualFileSystemResource
this.lastModifiedDate = rs.lastModifiedDate ? rs.lastModifiedDate : Date.now();
this.creationDate = rs.creationDate ? rs.creationDate : Date.now();
this.content = rs.content ? rs.content.map((o) => new Buffer(o)) : [];
this.props = rs.props ? Object.defineProperties(new LocalPropertyManager(), rs.props as any) : new LocalPropertyManager();
this.locks = rs.locks ? Object.defineProperties(new LocalLockManager(), rs.locks as any) : new LocalLockManager();
this.props = new LocalPropertyManager(rs.props);
this.locks = new LocalLockManager();
this.size = rs.size ? rs.size : 0;
this.type = rs.type ? rs.type : ResourceType.File;
}
Expand Down

0 comments on commit f8b3b46

Please sign in to comment.