mirror of
https://github.com/wassname/talk.git
synced 2026-06-28 17:51:53 +08:00
Refactor
This commit is contained in:
@@ -1,30 +1,4 @@
|
||||
class SortedWindowHandler {
|
||||
|
||||
constructor(client) {
|
||||
this.client = client;
|
||||
this.client.windowHandles((result) => {
|
||||
this.handles = result.value;
|
||||
if (this.handles.length > 2) {
|
||||
throw new Error('SortedWindowHandler must be created before new windows were created.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
windowHandles(callback) {
|
||||
this.client.windowHandles((result) => {
|
||||
console.log(result);
|
||||
this.handles = this.handles.filter((handle) => result.value.includes(handle));
|
||||
const remaining = result.value.filter((handle) => !this.handles.includes(handle));
|
||||
if (remaining.length === 1) {
|
||||
this.handles.push(remaining[0]);
|
||||
}
|
||||
if (remaining.length > 1) {
|
||||
throw new Error('Cannot detect new window handle, because more than one windows was created.');
|
||||
}
|
||||
callback(this.handles);
|
||||
});
|
||||
}
|
||||
}
|
||||
const SortedWindowHandler = require('../utils/SortedWindowHandler');
|
||||
|
||||
module.exports = {
|
||||
'@tags': ['embedStream', 'login'],
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
class SortedWindowHandler {
|
||||
|
||||
constructor(client) {
|
||||
this.client = client;
|
||||
this.client.windowHandles((result) => {
|
||||
this.handles = result.value;
|
||||
if (this.handles.length > 2) {
|
||||
throw new Error('SortedWindowHandler must be created before new windows were created.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
windowHandles(callback) {
|
||||
this.client.windowHandles((result) => {
|
||||
this.handles = this.handles.filter((handle) => result.value.includes(handle));
|
||||
const remaining = result.value.filter((handle) => !this.handles.includes(handle));
|
||||
if (remaining.length === 1) {
|
||||
this.handles.push(remaining[0]);
|
||||
}
|
||||
if (remaining.length > 1) {
|
||||
throw new Error('Cannot detect new window handle, because more than one windows was created.');
|
||||
}
|
||||
callback(this.handles);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = SortedWindowHandler;
|
||||
Reference in New Issue
Block a user