Skip to content

Commit

Permalink
Fixed a some bugs about the persistence
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienCastex committed May 21, 2017
1 parent 4526ad7 commit 0d1c7c1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
15 changes: 15 additions & 0 deletions lib/manager/ISerializer.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { IResource, ResourceType } from '../resource/IResource';
import { FSManager } from './FSManager';
export declare class SerializedObject {
data: any;
type: ResourceType;
children: SerializedObject[];
managerUID: string;
constructor(managerUID: string, type: ResourceType);
}
export interface ISerializer {
serialize(resource: IResource, obj: SerializedObject): object;
unserialize(data: any, obj: SerializedObject): IResource;
}
export declare function unserialize(obj: SerializedObject, managers: FSManager[], callback: (error: Error, rootResource: IResource) => void): void;
export declare function serialize(resource: IResource, callback: (error: Error, obj: SerializedObject) => void): void;
3 changes: 1 addition & 2 deletions lib/manager/ISerializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ function unserialize(obj, managers, callback) {
}
exports.unserialize = unserialize;
function serialize(resource, callback) {
var _this = this;
resource.type(function (e, type) {
var obj = new SerializedObject(resource.fsManager.uid, type);
obj.data = resource.fsManager.serialize(resource, obj);
Expand Down Expand Up @@ -80,7 +79,7 @@ function serialize(resource, callback) {
if (nb === 0)
callback(null, obj);
}
children.forEach(function (c) { return _this.serialize(c, go); });
children.forEach(function (c) { return serialize(c, go); });
});
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/manager/ISerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface ISerializer
unserialize(data : any, obj : SerializedObject) : IResource;
}

export function unserialize(obj : SerializedObject, managers : FSManager[], callback : (error : Error, rootResource : IResource))
export function unserialize(obj : SerializedObject, managers : FSManager[], callback : (error : Error, rootResource : IResource) => void)
{
for(const m of managers)
if(m.uid === obj.managerUID)
Expand Down Expand Up @@ -102,7 +102,7 @@ export function serialize(resource : IResource, callback : (error : Error, obj :
if(nb === 0)
callback(null, obj);
}
children.forEach((c) => this.serialize(c, go));
children.forEach((c) => serialize(c, go));
})
})
}

0 comments on commit 0d1c7c1

Please sign in to comment.