Improve channel tree children method speed & Creating directories if needed
parent
7b261d6f15
commit
7daa7d2933
|
@ -154,6 +154,7 @@ export class ChannelEntry extends ChannelTreeEntry<ChannelEvents> {
|
||||||
|
|
||||||
channel_previous?: ChannelEntry;
|
channel_previous?: ChannelEntry;
|
||||||
channel_next?: ChannelEntry;
|
channel_next?: ChannelEntry;
|
||||||
|
child_channel_head?: ChannelEntry;
|
||||||
|
|
||||||
readonly events: Registry<ChannelEvents>;
|
readonly events: Registry<ChannelEvents>;
|
||||||
readonly view: React.Ref<ChannelEntryView>;
|
readonly view: React.Ref<ChannelEntryView>;
|
||||||
|
@ -284,25 +285,15 @@ export class ChannelEntry extends ChannelTreeEntry<ChannelEvents> {
|
||||||
getChannelId(){ return this.channelId; }
|
getChannelId(){ return this.channelId; }
|
||||||
|
|
||||||
children(deep = false) : ChannelEntry[] {
|
children(deep = false) : ChannelEntry[] {
|
||||||
//TODO: Speed this up by caching the children!
|
|
||||||
const result: ChannelEntry[] = [];
|
const result: ChannelEntry[] = [];
|
||||||
if(this.channelTree == null) return [];
|
let head = this.child_channel_head;
|
||||||
|
while(head) {
|
||||||
|
result.push(head);
|
||||||
|
head = head.channel_next;
|
||||||
|
}
|
||||||
|
|
||||||
const self = this;
|
if(deep)
|
||||||
this.channelTree.channels.forEach(function (entry) {
|
return result.map(e => e.children(true)).reduce((prv, now) => { prv.push(...now); return prv; }, []);
|
||||||
let current = entry;
|
|
||||||
if(deep) {
|
|
||||||
while(current) {
|
|
||||||
if(current.parent_channel() == self) {
|
|
||||||
result.push(entry);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
current = current.parent_channel();
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
if(current.parent_channel() == self)
|
|
||||||
result.push(entry);
|
|
||||||
});
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -359,9 +359,11 @@ export class ChannelTree {
|
||||||
}
|
}
|
||||||
|
|
||||||
private unregisterChannelFromTree(channel: ChannelEntry) {
|
private unregisterChannelFromTree(channel: ChannelEntry) {
|
||||||
//TODO: Parent/Child reference?
|
if(channel.parent) {
|
||||||
if(channel.parent)
|
if(channel.parent.child_channel_head === channel)
|
||||||
|
channel.parent.child_channel_head = channel.channel_next;
|
||||||
channel.parent.events.fire("notify_children_changed");
|
channel.parent.events.fire("notify_children_changed");
|
||||||
|
}
|
||||||
|
|
||||||
if(channel.channel_previous)
|
if(channel.channel_previous)
|
||||||
channel.channel_previous.channel_next = channel.channel_next;
|
channel.channel_previous.channel_next = channel.channel_next;
|
||||||
|
@ -409,12 +411,13 @@ export class ChannelTree {
|
||||||
} else {
|
} else {
|
||||||
if(parent) {
|
if(parent) {
|
||||||
let children = parent.children();
|
let children = parent.children();
|
||||||
if(children.length <= 1) { //Self should be already in there
|
parent.child_channel_head = channel;
|
||||||
|
if(children.length === 0) { //Self should be already in there
|
||||||
channel.channel_next = undefined;
|
channel.channel_next = undefined;
|
||||||
} else {
|
} else {
|
||||||
channel.channel_previous = undefined;
|
channel.channel_previous = undefined;
|
||||||
|
|
||||||
channel.channel_next = children[1]; /* children 0 shall be the channel itself */
|
channel.channel_next = children[0];
|
||||||
channel.channel_next.channel_previous = channel;
|
channel.channel_next.channel_previous = channel;
|
||||||
}
|
}
|
||||||
parent.events.fire("notify_children_changed");
|
parent.events.fire("notify_children_changed");
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import * as webpack from "webpack";
|
import * as webpack from "webpack";
|
||||||
import * as fs from "fs";
|
import * as fs from "fs-extra";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
|
|
||||||
interface Options {
|
interface Options {
|
||||||
|
@ -79,6 +79,8 @@ class ManifestGenerator {
|
||||||
});
|
});
|
||||||
|
|
||||||
compiler.hooks.done.tap(this.constructor.name, () => {
|
compiler.hooks.done.tap(this.constructor.name, () => {
|
||||||
|
const file = this.options.file || "manifest.json";
|
||||||
|
fs.mkdirpSync(path.dirname(file));
|
||||||
fs.writeFileSync(this.options.file || "manifest.json", JSON.stringify(this.manifest_content));
|
fs.writeFileSync(this.options.file || "manifest.json", JSON.stringify(this.manifest_content));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue