make new folder for reuse ngLib add new features for datatree like change add remove rename datapoints improve pingpong
This commit is contained in:
50
src/vueLib/models/Publish.ts
Normal file
50
src/vueLib/models/Publish.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
export type Publish = {
|
||||
event: string;
|
||||
uuid: string;
|
||||
path: string;
|
||||
type: string;
|
||||
value: string | number | boolean | null;
|
||||
hasChild: boolean;
|
||||
};
|
||||
export type Pubs = Publish[];
|
||||
|
||||
import { updateSubscriptionValue, removeRawSubscriptions } from './Subscriptions';
|
||||
import { buildTree, buildTreeWithRawSubs, removeNodes } from '../dbm/dbmTree';
|
||||
import type { RawSubs, RawSubscribe } from '../models/Subscribe';
|
||||
import { ref } from 'vue';
|
||||
import { UpdateTable } from '../dbm/updateTable';
|
||||
import { pathIsExpanded } from '../dbm/dbmTree';
|
||||
|
||||
export function publishToSubscriptions(pubs: Pubs) {
|
||||
let event = '';
|
||||
const rawSubs = ref<RawSubs>([]);
|
||||
pubs.forEach((pub) => {
|
||||
switch (pub.event) {
|
||||
case 'onCreate':
|
||||
event = 'onCreate';
|
||||
if (!pathIsExpanded(pub.path)) break;
|
||||
pub.hasChild = pubs.length > 0;
|
||||
rawSubs.value.push(pub as RawSubscribe);
|
||||
break;
|
||||
case 'onChange':
|
||||
break;
|
||||
case 'onDelete':
|
||||
event = 'onDelete';
|
||||
rawSubs.value.push(pub as RawSubscribe);
|
||||
break;
|
||||
}
|
||||
updateSubscriptionValue(pub.uuid, pub.value);
|
||||
});
|
||||
|
||||
switch (event) {
|
||||
case 'onCreate':
|
||||
buildTreeWithRawSubs(rawSubs.value);
|
||||
break;
|
||||
case 'onDelete':
|
||||
buildTree(null);
|
||||
removeRawSubscriptions(rawSubs.value);
|
||||
UpdateTable();
|
||||
removeNodes(pubs);
|
||||
break;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user