Skip to content

Commit

Permalink
allow using a detached MapSchema. #62
Browse files Browse the repository at this point in the history
  • Loading branch information
endel committed Jun 9, 2020
1 parent d73711b commit 46dbaf4
Showing 1 changed file with 11 additions and 25 deletions.
36 changes: 11 additions & 25 deletions src/types/MapSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,7 @@ export class MapSchema<V=any> {
return type['map'] !== undefined;
}

constructor (obj: Map<string, V> | any = {}) {
if (obj instanceof Map) {
obj.forEach((v, k) => this.set(k, v));

} else {
for (const k in obj) {
this.set(k, obj[k]);
}
}

constructor (initialValues?: Map<string, V> | any) {
Object.defineProperties(this, {
$changes: {
value: new ChangeTree(this, {}),
Expand Down Expand Up @@ -84,21 +75,19 @@ export class MapSchema<V=any> {
return map;
}
},
});

_indexes: { value: new Map<string, number>(), enumerable: false, writable: true },
_updateIndexes: {
value: (allKeys) => {
let index: number = 0;

let indexes = new Map<string, number>();
for (let key of allKeys) {
indexes.set(key, index++);
}
if (initialValues) {
if (initialValues instanceof Map) {
initialValues.forEach((v, k) => this.set(k, v));

this._indexes = indexes;
} else {
for (const k in initialValues) {
this.set(k, initialValues[k]);
}
},
});
}
}

}

set(key: K, value: V) {
Expand Down Expand Up @@ -177,7 +166,4 @@ export class MapSchema<V=any> {
onChange: (item: V, key: string) => void;

triggerAll: () => void;

_indexes: Map<string, number>;
_updateIndexes: (keys: string[]) => void;
}

0 comments on commit 46dbaf4

Please sign in to comment.