Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | 29x 29x 232x 232x 303016x 19x 303016x 29x 13x 13x 13x 13x 13x 47x 6x 6x 6x 6x 3x 30x 18x 1x 1x 1x 1x 5x 19x 19x 19x 19x 18x 18x 18x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 10x 18x 18x 2x 88x | import { ArrayObserverHandler } from './arrayObserverHandler';
let cc1: ArrayObserverHandler;
let cc2: ArrayObserverHandler;
let cc3: ArrayObserverHandler;
let cc4: ArrayObserverHandler;
let cc5: ArrayObserverHandler;
// use prototype
// by doing this instead of object define I only do it once for all arrays
const events = ['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift', 'sort'];
events.forEach((eventX) => {
const eventType = Array.prototype[eventX];
Array.prototype[eventX] = function () {
const result = eventType.apply(this, arguments);
if (this.__array_observer__class) {
this.__array_observer__class.check(arguments, eventX);
}
return result;
};
});
/**
* this is used to set observer on a array on a class/object
*
*/
export class ClassArrayObserver {
private callers: ArrayObserverHandler[];
private c1: ArrayObserverHandler;
private c2: ArrayObserverHandler;
private c3: ArrayObserverHandler;
private c4: ArrayObserverHandler;
private c5: ArrayObserverHandler;
private internalEvents: any[] = [];
private timer: any = null;
constructor(
private _class: Object,
private key: string
) {
if (typeof this._class === 'object') {
this.observe();
}
}
/**
* subscribe
*
*/
public subscribe(caller: ArrayObserverHandler) {
if (this.c1 !== caller && this.c2 !== caller && this.c3 !== caller && this.c4 !== caller && this.c5 !== caller) {
if (!this.c1) {
this.c1 = caller;
} else {
if (!this.c2) {
this.c2 = caller;
} else {
if (!this.c3) {
this.c3 = caller;
} else {
if (!this.c4) {
this.c4 = caller;
} else {
if (!this.c5) {
this.c5 = caller;
} else {
if (!this.callers) {
this.callers = [];
}
if (this.callers.indexOf(caller) === -1) {
this.callers.push(caller);
}
}
}
}
}
}
}
}
/**
* unsubscribe
*
*/
public unsubscribe(caller: ArrayObserverHandler) {
if (this.c1 === caller) {
this.c1 = null;
}
if (this.c2 === caller) {
this.c2 = null;
}
if (this.c3 === caller) {
this.c3 = null;
}
if (this.c4 === caller) {
this.c4 = null;
}
if (this.c5 === caller) {
this.c5 = null;
}
if (this.callers && this.callers.indexOf(caller) !== -1) {
this.callers.splice(this.callers.indexOf(caller), 1);
}
}
public check(args: any, event: any) {
clearTimeout(this.timer);
this.timer = 0;
// push event
this.internalEvents.push({
event: event,
args: args
});
this.timer = setTimeout(() => {
if (this.c1) {
cc1 = this.c1;
this.c1 = undefined;
cc1.update(this.internalEvents);
}
if (this.c2) {
cc2 = this.c2;
this.c2 = undefined;
cc2.update(this.internalEvents);
}
if (this.c3) {
cc3 = this.c3;
this.c3 = undefined;
cc3.update(this.internalEvents);
}
if (this.c4) {
cc4 = this.c4;
this.c4 = undefined;
cc4.update(this.internalEvents);
}
if (this.c5) {
cc5 = this.c5;
this.c5 = undefined;
cc5.update(this.internalEvents);
}
if (this.callers && this.callers.length > 0) {
const calls = this.callers.slice();
this.callers = [];
calls.forEach((call: any) => {
call.update(this.internalEvents);
});
}
this.internalEvents = null;
this.internalEvents = [];
// check for length prop #13
// needs to be tested I dont break something else...
if (this._class[this.key] && this._class[this.key].__observer) {
for (const k in this._class[this.key].__observer) {
if (this._class[this.key].__observer[k] && this._class[this.key].__observer[k].forceUpdate) {
this._class[this.key].__observer[k].forceUpdate();
}
}
}
}, 0);
}
/**
* observe
*
*/
private observe() {
if (this._class[this.key] && Array.isArray(this._class[this.key])) {
Object.defineProperty(this._class[this.key], '__array_observer__class', {
writable: true,
configurable: true,
value: this
});
}
}
}
|