mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-19 02:56:23 +08:00
fix(editor): onChange notification for flat model (#10589)
The primary purpose of this PR appears to be: 1. Simplifying the change notification API by removing the redundant value parameter from callbacks 2. Improving the reactive system's handling of specialized types (Text and Boxed) in flat data 3. Adding better test coverage for text handling in the flat data model
This commit is contained in:
@@ -43,11 +43,11 @@ export class Block {
|
||||
) {
|
||||
const onChange = !options.onChange
|
||||
? undefined
|
||||
: (key: string, value: unknown) => {
|
||||
: (key: string) => {
|
||||
if (!this._syncController || !this.model) {
|
||||
return;
|
||||
}
|
||||
options.onChange?.(this, key, value);
|
||||
options.onChange?.(this, key);
|
||||
};
|
||||
const flavour = yBlock.get('sys:flavour') as string;
|
||||
const blockSchema = this.schema.get(flavour);
|
||||
|
||||
@@ -25,7 +25,7 @@ export class FlatSyncController {
|
||||
readonly schema: Schema,
|
||||
readonly yBlock: YBlock,
|
||||
readonly doc?: Store,
|
||||
readonly onChange?: (key: string, value: unknown) => void
|
||||
readonly onChange?: (key: string) => void
|
||||
) {
|
||||
const { id, flavour, version, yChildren, props } = this._parseYBlock();
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ export class SyncController {
|
||||
}
|
||||
});
|
||||
});
|
||||
this.onChange?.(keyName, value);
|
||||
this.onChange?.(keyName);
|
||||
return;
|
||||
}
|
||||
if (type.action === 'delete') {
|
||||
@@ -70,7 +70,7 @@ export class SyncController {
|
||||
this.model[`${keyName}$`].value = undefined;
|
||||
}
|
||||
});
|
||||
this.onChange?.(keyName, undefined);
|
||||
this.onChange?.(keyName);
|
||||
return;
|
||||
}
|
||||
});
|
||||
@@ -105,7 +105,7 @@ export class SyncController {
|
||||
readonly schema: Schema,
|
||||
readonly yBlock: YBlock,
|
||||
readonly doc?: Store,
|
||||
readonly onChange?: (key: string, value: unknown) => void
|
||||
readonly onChange?: (key: string) => void
|
||||
) {
|
||||
const { id, flavour, version, yChildren, props } = this._parseYBlock();
|
||||
|
||||
@@ -175,7 +175,7 @@ export class SyncController {
|
||||
if (this._stashed.has(p)) {
|
||||
setValue(target, p, value);
|
||||
const result = Reflect.set(target, p, value, receiver);
|
||||
this.onChange?.(p, value);
|
||||
this.onChange?.(p);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ export class SyncController {
|
||||
private _getPropsProxy(name: string, value: unknown) {
|
||||
return createYProxy(value, {
|
||||
onChange: () => {
|
||||
this.onChange?.(name, value);
|
||||
this.onChange?.(name);
|
||||
const signalKey = `${name}$`;
|
||||
if (signalKey in this.model) {
|
||||
this._mutex(() => {
|
||||
@@ -339,12 +339,12 @@ export class SyncController {
|
||||
},
|
||||
set: (target, p, value, receiver) => {
|
||||
const result = Reflect.set(target, p, value, receiver);
|
||||
this.onChange?.(prop, value);
|
||||
this.onChange?.(prop);
|
||||
return result;
|
||||
},
|
||||
deleteProperty: (target, p) => {
|
||||
const result = Reflect.deleteProperty(target, p);
|
||||
this.onChange?.(prop, undefined);
|
||||
this.onChange?.(prop);
|
||||
return result;
|
||||
},
|
||||
});
|
||||
@@ -360,12 +360,12 @@ export class SyncController {
|
||||
return Reflect.set(target, p, value, receiver);
|
||||
}
|
||||
const result = Reflect.set(target, p, value, receiver);
|
||||
this.onChange?.(prop, value);
|
||||
this.onChange?.(prop);
|
||||
return result;
|
||||
},
|
||||
deleteProperty: (target, p) => {
|
||||
const result = Reflect.deleteProperty(target, p);
|
||||
this.onChange?.(p as string, undefined);
|
||||
this.onChange?.(p as string);
|
||||
return result;
|
||||
},
|
||||
});
|
||||
|
||||
@@ -10,7 +10,7 @@ export type YBlock = Y.Map<unknown> & {
|
||||
};
|
||||
|
||||
export type BlockOptions = {
|
||||
onChange?: (block: Block, key: string, value: unknown) => void;
|
||||
onChange?: (block: Block, key: string) => void;
|
||||
};
|
||||
|
||||
export type BlockSysProps = {
|
||||
|
||||
Reference in New Issue
Block a user