@herlinus/coloquent
Version:
Library for retrieving model objects from a JSON-API, with a fluent syntax inspired by Laravel Eloquent.
37 lines • 914 B
JavaScript
export class Map {
constructor() {
this.data = {};
this.changed = {};
}
get(key) {
return this.data[key];
}
set(key, value, original) {
if (!original) {
this.changed[key] = this.data[key];
}
this.data[key] = value;
}
toArray() {
return this.data;
}
isDirty() {
for (let key of Object.keys(this.changed)) {
if (this.changed[key] !== this.data[key])
return true;
}
return false;
}
hasChanged(key) {
return this.changed.hasOwnProperty(key) && ((this.data[key] !== this.changed[key]));
}
flushChanged() {
this.changed = {};
}
reset() {
for (let key of Object.keys(this.changed)) {
this.data[key] = this.changed[key];
}
}
}
//# sourceMappingURL=Map.js.map