TxMixin update modify (#2103)

Signed-off-by: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com>
This commit is contained in:
Denis Bykhov 2022-06-19 22:26:05 +06:00 committed by GitHub
parent d0f68cc87f
commit df727de184
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 12 additions and 14 deletions

View File

@ -175,7 +175,7 @@ export class Hierarchy {
private txMixin (tx: TxMixin<Doc, Doc>): void {
if (this.isDerived(tx.objectClass, core.class.Class)) {
const obj = this.getClass(tx.objectId as Ref<Class<Obj>>) as any
TxProcessor.updateMixin4Doc(obj, tx.mixin, tx.attributes)
TxProcessor.updateMixin4Doc(obj, tx)
}
}

View File

@ -252,7 +252,7 @@ export class ModelDb extends MemDb implements Storage {
// TODO: process ancessor mixins
protected async txMixin (tx: TxMixin<Doc, Doc>): Promise<TxResult> {
const obj = this.getObject(tx.objectId) as any
TxProcessor.updateMixin4Doc(obj, tx.mixin, tx.attributes)
TxProcessor.updateMixin4Doc(obj, tx)
return {}
}
}

View File

@ -274,14 +274,10 @@ export abstract class TxProcessor implements WithTx {
return rawDoc
}
static updateMixin4Doc<D extends Doc, M extends D>(
rawDoc: D,
mixinClass: Ref<Class<M>>,
operations: MixinUpdate<D, M>
): D {
const ops = operations as any
static updateMixin4Doc<D extends Doc, M extends D>(rawDoc: D, tx: TxMixin<D, M>): D {
const ops = tx.attributes as any
const doc = _toDoc(rawDoc)
const mixin = (doc as any)[mixinClass] ?? {}
const mixin = (doc as any)[tx.mixin] ?? {}
for (const key in ops) {
if (key.startsWith('$')) {
const operator = _getOperator(key)
@ -290,7 +286,9 @@ export abstract class TxProcessor implements WithTx {
mixin[key] = ops[key]
}
}
;(doc as any)[mixinClass] = mixin
rawDoc.modifiedBy = tx.modifiedBy
rawDoc.modifiedOn = tx.modifiedOn
;(doc as any)[tx.mixin] = mixin
return rawDoc
}

View File

@ -270,7 +270,7 @@ export class LiveQuery extends TxProcessor implements Client {
let updatedDoc = q.result.find((p) => p._id === tx.objectId)
if (updatedDoc !== undefined) {
// Create or apply mixin value
updatedDoc = TxProcessor.updateMixin4Doc(updatedDoc, tx.mixin, tx.attributes)
updatedDoc = TxProcessor.updateMixin4Doc(updatedDoc, tx)
await this.updatedDocCallback(updatedDoc, q)
} else if (isMixin) {
// Mixin potentially added to object we doesn't have in out results

View File

@ -310,7 +310,7 @@ class ActivityImpl implements Activity {
checkMixinState (result: DisplayTx, firstTx: DisplayTx): boolean {
if (this.client.getHierarchy().isDerived(result.tx._class, core.class.TxMixin) && result.doc !== undefined) {
const mix = result.tx as TxMixin<Doc, Doc>
firstTx.doc = TxProcessor.updateMixin4Doc(result.doc, mix.mixin, mix.attributes)
firstTx.doc = TxProcessor.updateMixin4Doc(result.doc, mix)
firstTx.mixin = true
result.mixin = true
return true

View File

@ -209,7 +209,7 @@ async function buildRemovedDoc (client: TxOperations, objectId: Ref<Doc>): Promi
doc = TxProcessor.updateDoc2Doc(doc, tx as TxUpdateDoc<Doc>)
} else if (tx._class === core.class.TxMixin) {
const mixinTx = tx as TxMixin<Doc, Doc>
doc = TxProcessor.updateMixin4Doc(doc, mixinTx.mixin, mixinTx.attributes)
doc = TxProcessor.updateMixin4Doc(doc, mixinTx)
}
}
return doc

View File

@ -290,7 +290,7 @@ class TServerStorage implements ServerStorage {
doc = TxProcessor.updateDoc2Doc(doc, tx as TxUpdateDoc<Doc>)
} else if (tx._class === core.class.TxMixin) {
const mixinTx = tx as TxMixin<Doc, Doc>
doc = TxProcessor.updateMixin4Doc(doc, mixinTx.mixin, mixinTx.attributes)
doc = TxProcessor.updateMixin4Doc(doc, mixinTx)
}
}