Sending change signal on delete
This commit is contained in:
parent
15df0351a4
commit
a78e98a0c8
@ -139,48 +139,49 @@ export default class Query {
|
||||
}
|
||||
|
||||
async set(value: any) {
|
||||
if (value === null || value === undefined)
|
||||
return this.delete(value);
|
||||
|
||||
const lock = await this.database.locks.lock(this.path);
|
||||
let batch = this.database.level.batch();
|
||||
try {
|
||||
let field = await this.getField(this.path);
|
||||
if (field) {
|
||||
await this.delete(batch);
|
||||
if (value === null || value === undefined) {
|
||||
this.delete(value);
|
||||
} else {
|
||||
for (let i = 0; i < this.path.length; i++) {
|
||||
let subpath = this.path.slice(0, i);
|
||||
let field = await this.getField(subpath);
|
||||
if (!field) {
|
||||
batch.put(this.pathToKey(subpath), FieldEncoder.encode({
|
||||
type: FieldTypes.OBJECT
|
||||
}));
|
||||
} else if (field.type !== FieldTypes.OBJECT) {
|
||||
throw new Error("Parent elements not all Object. Cannot set value!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const saveValue = (path: string[], value: any) => {
|
||||
if (typeof value === "object") {
|
||||
//TODO: Handle case array!
|
||||
// Field type array?
|
||||
batch.put(this.pathToKey(path), FieldEncoder.encode({
|
||||
type: FieldTypes.OBJECT
|
||||
}))
|
||||
for (let field in value) {
|
||||
saveValue([...path, field], value[field]);
|
||||
}
|
||||
let field = await this.getField(this.path);
|
||||
if (field) {
|
||||
await this.delete(batch);
|
||||
} else {
|
||||
batch.put(this.pathToKey(path), FieldEncoder.encode({
|
||||
type: FieldTypes.VALUE,
|
||||
value
|
||||
}));
|
||||
for (let i = 0; i < this.path.length; i++) {
|
||||
let subpath = this.path.slice(0, i);
|
||||
let field = await this.getField(subpath);
|
||||
if (!field) {
|
||||
batch.put(this.pathToKey(subpath), FieldEncoder.encode({
|
||||
type: FieldTypes.OBJECT
|
||||
}));
|
||||
} else if (field.type !== FieldTypes.OBJECT) {
|
||||
throw new Error("Parent elements not all Object. Cannot set value!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
saveValue(this.path, value);
|
||||
const saveValue = (path: string[], value: any) => {
|
||||
if (typeof value === "object") {
|
||||
//TODO: Handle case array!
|
||||
// Field type array?
|
||||
batch.put(this.pathToKey(path), FieldEncoder.encode({
|
||||
type: FieldTypes.OBJECT
|
||||
}))
|
||||
for (let field in value) {
|
||||
saveValue([...path, field], value[field]);
|
||||
}
|
||||
} else {
|
||||
batch.put(this.pathToKey(path), FieldEncoder.encode({
|
||||
type: FieldTypes.VALUE,
|
||||
value
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
saveValue(this.path, value);
|
||||
}
|
||||
|
||||
await batch.write();
|
||||
this.database.changeObservable.send({
|
||||
|
@ -36,8 +36,6 @@ Handlebars.registerHelper('ifCond', function (v1, operator, v2, options) {
|
||||
});
|
||||
|
||||
|
||||
const formsTemplate = Handlebars.compile(readFileSync("./views/forms.hbs").toString());
|
||||
|
||||
const cache = new Map<string, Handlebars.TemplateDelegate>();
|
||||
|
||||
export default function getTemplate(name: string) {
|
||||
|
Reference in New Issue
Block a user