Skip to content

Commit bdbba03

Browse files
committed
#7076 manager.VDomUpdate WIP
1 parent c7582b2 commit bdbba03

1 file changed

Lines changed: 109 additions & 0 deletions

File tree

src/manager/VDomUpdate.mjs

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import Collection from '../collection/Base.mjs';
2+
3+
/**
4+
* @class Neo.manager.VDomUpdate
5+
* @extends Neo.collection.Base
6+
* @singleton
7+
*/
8+
class VDomUpdate extends Collection {
9+
static config = {
10+
/**
11+
* @member {String} className='Neo.manager.VDomUpdate'
12+
* @protected
13+
*/
14+
className: 'Neo.manager.VDomUpdate',
15+
/**
16+
* @member {Boolean} singleton=true
17+
* @protected
18+
*/
19+
singleton: true,
20+
/**
21+
* @member {Neo.collection.Base|null} mergedCallbackMap=null
22+
* @protected
23+
*/
24+
mergedCallbackMap: null,
25+
/**
26+
* @member {Neo.collection.Base|null} postUpdateQueueMap=null
27+
* @protected
28+
*/
29+
postUpdateQueueMap: null
30+
}
31+
32+
/**
33+
* @param {Object} config
34+
*/
35+
construct(config) {
36+
super.construct(config);
37+
38+
let me = this;
39+
40+
me.mergedCallbackMap = Neo.create(Collection, {keyProperty: 'ownerId'});
41+
me.postUpdateQueueMap = Neo.create(Collection, {keyProperty: 'ownerId'});
42+
}
43+
44+
/**
45+
* @param {String} ownerId
46+
* @param {String} childId
47+
* @param {Array} callbacks
48+
*/
49+
registerMerged(ownerId, childId, callbacks) {
50+
let me = this,
51+
item = me.mergedCallbackMap.get(ownerId);
52+
53+
if (!item) {
54+
item = {ownerId, callbacks: [], childIds: []};
55+
me.mergedCallbackMap.add(item);
56+
}
57+
58+
item.callbacks.push(...callbacks);
59+
item.childIds.push(childId);
60+
}
61+
62+
/**
63+
* @param {String} ownerId
64+
* @param {String} childId
65+
*/
66+
registerPostUpdate(ownerId, childId) {
67+
let me = this,
68+
item = me.postUpdateQueueMap.get(ownerId);
69+
70+
if (!item) {
71+
item = {ownerId, childIds: []};
72+
me.postUpdateQueueMap.add(item);
73+
}
74+
75+
item.childIds.push(childId);
76+
}
77+
78+
/**
79+
* @param {String} ownerId
80+
*/
81+
executeCallbacks(ownerId) {
82+
let me = this,
83+
item = me.mergedCallbackMap.get(ownerId);
84+
85+
if (item) {
86+
item.callbacks.forEach(callback => callback());
87+
me.mergedCallbackMap.remove(item);
88+
}
89+
}
90+
91+
/**
92+
* @param {String} ownerId
93+
*/
94+
triggerPostUpdates(ownerId) {
95+
let me = this,
96+
item = me.postUpdateQueueMap.get(ownerId);
97+
98+
if (item) {
99+
item.childIds.forEach(childId => {
100+
let component = Neo.getComponent(childId);
101+
component?.update();
102+
});
103+
104+
me.postUpdateQueueMap.remove(item);
105+
}
106+
}
107+
}
108+
109+
export default Neo.setupClass(VDomUpdate);

0 commit comments

Comments
 (0)