|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.9 KB
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | module.exports = class SymbolTreeNode {
|
|---|
| 4 | constructor() {
|
|---|
| 5 | this.parent = null;
|
|---|
| 6 | this.previousSibling = null;
|
|---|
| 7 | this.nextSibling = null;
|
|---|
| 8 |
|
|---|
| 9 | this.firstChild = null;
|
|---|
| 10 | this.lastChild = null;
|
|---|
| 11 |
|
|---|
| 12 | /** This value is incremented anytime a children is added or removed */
|
|---|
| 13 | this.childrenVersion = 0;
|
|---|
| 14 | /** The last child object which has a cached index */
|
|---|
| 15 | this.childIndexCachedUpTo = null;
|
|---|
| 16 |
|
|---|
| 17 | /** This value represents the cached node index, as long as
|
|---|
| 18 | * cachedIndexVersion matches with the childrenVersion of the parent */
|
|---|
| 19 | this.cachedIndex = -1;
|
|---|
| 20 | this.cachedIndexVersion = NaN; // NaN is never equal to anything
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 | get isAttached() {
|
|---|
| 24 | return Boolean(this.parent || this.previousSibling || this.nextSibling);
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | get hasChildren() {
|
|---|
| 28 | return Boolean(this.firstChild);
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | childrenChanged() {
|
|---|
| 32 | /* jshint -W016 */
|
|---|
| 33 | // integer wrap around
|
|---|
| 34 | this.childrenVersion = (this.childrenVersion + 1) & 0xFFFFFFFF;
|
|---|
| 35 | this.childIndexCachedUpTo = null;
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | getCachedIndex(parentNode) {
|
|---|
| 39 | // (assumes parentNode is actually the parent)
|
|---|
| 40 | if (this.cachedIndexVersion !== parentNode.childrenVersion) {
|
|---|
| 41 | this.cachedIndexVersion = NaN;
|
|---|
| 42 | // cachedIndex is no longer valid
|
|---|
| 43 | return -1;
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | return this.cachedIndex; // -1 if not cached
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | setCachedIndex(parentNode, index) {
|
|---|
| 50 | // (assumes parentNode is actually the parent)
|
|---|
| 51 | this.cachedIndexVersion = parentNode.childrenVersion;
|
|---|
| 52 | this.cachedIndex = index;
|
|---|
| 53 | }
|
|---|
| 54 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.