docs(tests): explain projection cache invalidation and frame notifications
This commit is contained in:
@@ -18,6 +18,7 @@ test('session presentation coalesces preview bursts but live reads and final can
|
||||
test('root presentation batches a burst while commands, history and authoritative reads advance immediately',async()=>{
|
||||
const {createDocument,createEditor,createRegistry,builtinComponents}=await import('../../src/lib/canvas-core/index.ts');let id=0;
|
||||
const editor=createEditor({document:createDocument('p',[{id:'canvas',parent:null}],[{id:'a',incarnation:1,ownerCanvasId:'canvas',componentId:'text',dataVersion:1,structure:'node',data:{title:'before',text:''},geometry:{x:0,y:0,width:100,height:100,rotation:0}}]),registry:createRegistry(builtinComponents()),createId:()=>`op-${++id}`}),c=clock(),commits=[],source={getSnapshot:editor.getSnapshot,subscribe:notify=>editor.subscribe((commit,next)=>{commits.push(next.rootRevision);notify();})},framed=createFrameSource(source,c),painted=[],stop=framed.subscribe(()=>painted.push(framed.getSnapshot()));
|
||||
// 三次命令同步推进权威根与历史;c.step 前没有呈现回调,但 getSnapshot 仍必须立即读到 third。
|
||||
for(const title of ['first','second','third'])assert.equal(editor.dispatch({type:'element.data',target:{id:'a',incarnation:1},patch:{title}}).status,'applied');
|
||||
assert.equal(commits.length,3);assert.equal(painted.length,0);assert.equal(c.size,1);assert.strictEqual(framed.getSnapshot(),editor.getSnapshot());assert.equal(framed.getSnapshot().document.elements.get('a').data.title,'third');assert.equal(editor.getSnapshot().history.undo.length,3);c.step();assert.equal(painted.length,1);assert.strictEqual(painted[0],editor.getSnapshot());stop();editor.dispose();
|
||||
});
|
||||
@@ -33,6 +34,7 @@ test('eager failed subscriptions cancel presentation work and reentrant changes
|
||||
});
|
||||
|
||||
// 后台值1尚待帧时输入值2以immediate通知,直接发布2并取消旧帧;随后值3仍按普通帧更新。
|
||||
// listener(true) 只让订阅通知立即执行,不另建文档提交;待帧取消后 c.step 不能再次通知旧值。
|
||||
test('an immediate input invalidation publishes the newest Root and consumes any pending background frame',()=>{
|
||||
const c=clock();let value=0,listener;const source={getSnapshot:()=>value,subscribe(fn){listener=fn;return()=>{listener=undefined;};}},framed=createFrameSource(source,c),seen=[],stop=framed.subscribe(()=>seen.push(framed.getSnapshot()));value=1;listener();assert.equal(c.size,1);value=2;listener(true);assert.deepEqual(seen,[2]);assert.equal(c.size,0);c.step();assert.deepEqual(seen,[2]);value=3;listener();c.step();assert.deepEqual(seen,[2,3]);stop();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user