Skip to content

Commit

Permalink
Rename loader to migrate.
Browse files Browse the repository at this point in the history
  • Loading branch information
Viatorus committed Jun 5, 2018
1 parent cb7c7d7 commit 70f374c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/loki/spec/generic/migration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ describe("load lokijs", () => {
it("test LokiDB with serialization inflation", () => {
let db = new Loki();
db.loadJSONObject(legacyDB as Serialization.Serialized, {
loader: (_1, coll) => {
migrate: (_1, coll) => {
coll.nestedProperties = [{name: "d.msg", path: ["d", "msg"]}];
return false;
}
Expand Down Expand Up @@ -258,7 +258,7 @@ describe("load lokijs", () => {

// Transform and dynamic view will not be deserialized.
db.loadJSONObject(legacyDB as Serialization.Serialized, {
loader: (_1, _2, options) => {
migrate: (_1, _2, options) => {
options.nestedProperties = ["d.msg"];
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/loki/src/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2186,7 +2186,7 @@ export namespace Collection {
export interface DeserializeOptions {
retainDirtyFlags?: boolean;
fullTextSearch?: Dict<Analyzer>;
loader?: (databaseVersion: number, coll: Serialization.Collection, options: Collection.Options<any, any>) => boolean;
migrate?: (databaseVersion: number, coll: Serialization.Collection, options: Collection.Options<any, any>) => boolean;

[collName: string]: any | { proto?: any; inflate?: (src: object, dest?: object) => void };
}
Expand Down
7 changes: 3 additions & 4 deletions packages/loki/src/loki.ts
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ export class Loki extends LokiEventEmitter {
let coll = null;
const dbColl = dbObj.collections[i];

if (options.loader) {
if (options.migrate) {
// Generate options from serialized collection.
const collOptions: Collection.Options<any, any> = {};

Expand Down Expand Up @@ -704,7 +704,7 @@ export class Loki extends LokiEventEmitter {
}
}

if (options.loader(databaseVersion, dbColl, collOptions)) {
if (options.migrate(databaseVersion, dbColl, collOptions)) {
coll = this.addCollection(dbColl.name, collOptions);
for (let j = 0; j < dbColl.data.length; j++) {
delete dbColl.data[j].$loki;
Expand All @@ -716,8 +716,7 @@ export class Loki extends LokiEventEmitter {
if (!coll) {
coll = Collection.fromJSONObject(dbObj.collections[i], options);
}

this._collections.push(Collection.fromJSONObject(dbObj.collections[i], options));
this._collections.push(coll);
}
}

Expand Down

0 comments on commit 70f374c

Please sign in to comment.