-
Notifications
You must be signed in to change notification settings - Fork 443
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dfd30c8
commit 69a8c84
Showing
25 changed files
with
418 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { InterfaceType, NodeName } from '../types'; | ||
import { WorkerAnchorElement, WorkerDocumentElementChild, WorkerElement } from './worker-element'; | ||
import { WorkerContentWindow, WorkerIFrameElement } from './worker-iframe'; | ||
import { WorkerDocument } from './worker-document'; | ||
import { WorkerInstance } from './worker-instance'; | ||
import { WorkerNode } from './worker-node'; | ||
import { WorkerScriptElement } from './worker-script'; | ||
|
||
export const constructInstance = ( | ||
interfaceType: InterfaceType, | ||
instanceId: number, | ||
winId?: number, | ||
nodeName?: string | ||
) => { | ||
nodeName = | ||
interfaceType === InterfaceType.Document | ||
? NodeName.Document | ||
: interfaceType === InterfaceType.TextNode | ||
? NodeName.Text | ||
: nodeName; | ||
|
||
const Cstr = getConstructor(interfaceType, nodeName); | ||
return new Cstr(interfaceType, instanceId, winId, nodeName); | ||
}; | ||
|
||
const getConstructor = (interfaceType: InterfaceType, nodeName?: string): typeof WorkerInstance => { | ||
if (interfaceType === InterfaceType.Element) { | ||
return getElementConstructor(nodeName!); | ||
} else if (interfaceType === InterfaceType.Document) { | ||
return WorkerDocument; | ||
} else if (interfaceType === InterfaceType.Window) { | ||
return WorkerContentWindow; | ||
} else if (interfaceType === InterfaceType.TextNode) { | ||
return WorkerNode; | ||
} else { | ||
return WorkerInstance; | ||
} | ||
}; | ||
|
||
export const getElementConstructor = (nodeName: string): typeof WorkerElement => | ||
({ | ||
A: WorkerAnchorElement, | ||
BODY: WorkerDocumentElementChild, | ||
HEAD: WorkerDocumentElementChild, | ||
IFRAME: WorkerIFrameElement, | ||
SCRIPT: WorkerScriptElement, | ||
}[nodeName] || WorkerElement); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
69a8c84
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: