|
22 | 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
23 | 23 | THE SOFTWARE. |
24 | 24 | */ |
25 | | -import { Platform } from 'ionic-angular'; |
26 | | - |
27 | | -export class PlatformMock extends Platform { |
28 | | - private timeoutIds = 0; |
29 | | - private timeouts: { |
30 | | - callback: Function; |
31 | | - timeout: number; |
32 | | - timeoutId: number; |
33 | | - }[] = []; |
34 | | - private rafIds = 0; |
35 | | - private timeStamps = 0; |
36 | | - private rafs: { callback: Function; rafId: number }[] = []; |
37 | | - |
38 | | - constructor() { |
39 | | - super(); |
40 | | - const doc = document.implementation.createHTMLDocument(''); |
41 | | - this.setWindow(window); |
42 | | - this.setDocument(doc); |
43 | | - this.setCssProps(doc.documentElement); |
44 | | - } |
45 | | - |
46 | | - timeout(callback: Function, timeout: number) { |
47 | | - const timeoutId = ++this.timeoutIds; |
48 | | - |
49 | | - this.timeouts.push({ |
50 | | - callback: callback, |
51 | | - timeout: timeout, |
52 | | - timeoutId: timeoutId |
53 | | - }); |
54 | | - |
55 | | - return timeoutId; |
56 | | - } |
57 | | - |
58 | | - cancelTimeout(timeoutId: number) { |
59 | | - for (let i = 0; i < this.timeouts.length; i++) { |
60 | | - if (timeoutId === this.timeouts[i].timeoutId) { |
61 | | - this.timeouts.splice(i, 1); |
62 | | - break; |
63 | | - } |
64 | | - } |
65 | | - } |
66 | | - |
67 | | - flushTimeouts(done: Function) { |
68 | | - setTimeout(() => { |
69 | | - this.timeouts |
70 | | - .sort((a, b) => { |
71 | | - if (a.timeout < b.timeout) { |
72 | | - return -1; |
73 | | - } |
74 | | - if (a.timeout > b.timeout) { |
75 | | - return 1; |
76 | | - } |
77 | | - return 0; |
78 | | - }) |
79 | | - .forEach(t => { |
80 | | - t.callback(); |
81 | | - }); |
82 | | - this.timeouts.length = 0; |
83 | | - done(); |
84 | | - }); |
85 | | - } |
86 | | - |
87 | | - flushTimeoutsUntil(timeout: number, done: Function) { |
88 | | - setTimeout(() => { |
89 | | - this.timeouts.sort((a, b) => { |
90 | | - if (a.timeout < b.timeout) { |
91 | | - return -1; |
92 | | - } |
93 | | - if (a.timeout > b.timeout) { |
94 | | - return 1; |
95 | | - } |
96 | | - return 0; |
97 | | - }); |
98 | | - |
99 | | - const keepers: any[] = []; |
100 | | - this.timeouts.forEach(t => { |
101 | | - if (t.timeout < timeout) { |
102 | | - t.callback(); |
103 | | - } else { |
104 | | - keepers.push(t); |
105 | | - } |
106 | | - }); |
107 | | - |
108 | | - this.timeouts = keepers; |
109 | | - done(); |
110 | | - }); |
111 | | - } |
112 | | - |
113 | | - raf(callback: ((timeStamp?: number) => void) | Function): number { |
114 | | - const rafId = ++this.rafIds; |
115 | | - this.rafs.push({ |
116 | | - callback: callback, |
117 | | - rafId: rafId |
118 | | - }); |
119 | | - return rafId; |
120 | | - } |
121 | | - |
122 | | - cancelRaf(rafId: number) { |
123 | | - for (let i = 0; i < this.rafs.length; i++) { |
124 | | - if (rafId === this.rafs[i].rafId) { |
125 | | - this.rafs.splice(i, 1); |
126 | | - break; |
127 | | - } |
128 | | - } |
129 | | - } |
130 | | - |
131 | | - flushRafs(done: Function) { |
132 | | - const timestamp = ++this.timeStamps; |
133 | | - setTimeout(() => { |
134 | | - this.rafs.forEach(raf => { |
135 | | - raf.callback(timestamp); |
136 | | - }); |
137 | | - this.rafs.length = 0; |
138 | | - done(timestamp); |
139 | | - }); |
140 | | - } |
141 | | -} |
| 25 | +// import { Platform } from 'ionic-angular'; |
| 26 | +// |
| 27 | +// export class PlatformMock extends Platform { |
| 28 | +// private timeoutIds = 0; |
| 29 | +// private timeouts: { |
| 30 | +// callback: Function; |
| 31 | +// timeout: number; |
| 32 | +// timeoutId: number; |
| 33 | +// }[] = []; |
| 34 | +// private rafIds = 0; |
| 35 | +// private timeStamps = 0; |
| 36 | +// private rafs: { callback: Function; rafId: number }[] = []; |
| 37 | +// |
| 38 | +// constructor() { |
| 39 | +// super(); |
| 40 | +// const doc = document.implementation.createHTMLDocument(''); |
| 41 | +// this.setWindow(window); |
| 42 | +// this.setDocument(doc); |
| 43 | +// this.setCssProps(doc.documentElement); |
| 44 | +// } |
| 45 | +// |
| 46 | +// timeout(callback: Function, timeout: number) { |
| 47 | +// const timeoutId = ++this.timeoutIds; |
| 48 | +// |
| 49 | +// this.timeouts.push({ |
| 50 | +// callback: callback, |
| 51 | +// timeout: timeout, |
| 52 | +// timeoutId: timeoutId |
| 53 | +// }); |
| 54 | +// |
| 55 | +// return timeoutId; |
| 56 | +// } |
| 57 | +// |
| 58 | +// cancelTimeout(timeoutId: number) { |
| 59 | +// for (let i = 0; i < this.timeouts.length; i++) { |
| 60 | +// if (timeoutId === this.timeouts[i].timeoutId) { |
| 61 | +// this.timeouts.splice(i, 1); |
| 62 | +// break; |
| 63 | +// } |
| 64 | +// } |
| 65 | +// } |
| 66 | +// |
| 67 | +// flushTimeouts(done: Function) { |
| 68 | +// setTimeout(() => { |
| 69 | +// this.timeouts |
| 70 | +// .sort((a, b) => { |
| 71 | +// if (a.timeout < b.timeout) { |
| 72 | +// return -1; |
| 73 | +// } |
| 74 | +// if (a.timeout > b.timeout) { |
| 75 | +// return 1; |
| 76 | +// } |
| 77 | +// return 0; |
| 78 | +// }) |
| 79 | +// .forEach(t => { |
| 80 | +// t.callback(); |
| 81 | +// }); |
| 82 | +// this.timeouts.length = 0; |
| 83 | +// done(); |
| 84 | +// }); |
| 85 | +// } |
| 86 | +// |
| 87 | +// flushTimeoutsUntil(timeout: number, done: Function) { |
| 88 | +// setTimeout(() => { |
| 89 | +// this.timeouts.sort((a, b) => { |
| 90 | +// if (a.timeout < b.timeout) { |
| 91 | +// return -1; |
| 92 | +// } |
| 93 | +// if (a.timeout > b.timeout) { |
| 94 | +// return 1; |
| 95 | +// } |
| 96 | +// return 0; |
| 97 | +// }); |
| 98 | +// |
| 99 | +// const keepers: any[] = []; |
| 100 | +// this.timeouts.forEach(t => { |
| 101 | +// if (t.timeout < timeout) { |
| 102 | +// t.callback(); |
| 103 | +// } else { |
| 104 | +// keepers.push(t); |
| 105 | +// } |
| 106 | +// }); |
| 107 | +// |
| 108 | +// this.timeouts = keepers; |
| 109 | +// done(); |
| 110 | +// }); |
| 111 | +// } |
| 112 | +// |
| 113 | +// raf(callback: ((timeStamp?: number) => void) | Function): number { |
| 114 | +// const rafId = ++this.rafIds; |
| 115 | +// this.rafs.push({ |
| 116 | +// callback: callback, |
| 117 | +// rafId: rafId |
| 118 | +// }); |
| 119 | +// return rafId; |
| 120 | +// } |
| 121 | +// |
| 122 | +// cancelRaf(rafId: number) { |
| 123 | +// for (let i = 0; i < this.rafs.length; i++) { |
| 124 | +// if (rafId === this.rafs[i].rafId) { |
| 125 | +// this.rafs.splice(i, 1); |
| 126 | +// break; |
| 127 | +// } |
| 128 | +// } |
| 129 | +// } |
| 130 | +// |
| 131 | +// flushRafs(done: Function) { |
| 132 | +// const timestamp = ++this.timeStamps; |
| 133 | +// setTimeout(() => { |
| 134 | +// this.rafs.forEach(raf => { |
| 135 | +// raf.callback(timestamp); |
| 136 | +// }); |
| 137 | +// this.rafs.length = 0; |
| 138 | +// done(timestamp); |
| 139 | +// }); |
| 140 | +// } |
| 141 | +// } |
0 commit comments