-
Notifications
You must be signed in to change notification settings - Fork 43
Implement clone #672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
anyatokar
wants to merge
12
commits into
sjbarag:main
Choose a base branch
from
anyatokar:implement-clone
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Implement clone #672
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d02af85
add shallow clone method and tests
4ba9b38
tiny: add/remove spaces
ed5facb
add recursive deep clone for fields and children
3df221c
refactor cloneHelper to not be Callable
f9f7f46
test: add e2e testing
480f6b3
tiny: remove copied out code
1d64c93
smaller CR changes
f14ada1
fix: undo an accidental edit in addchildren method
7ba2022
expose .children method per CR suggestion
0505973
add clone method description from brightscript docs
6a6a5de
Revert "expose .children method per CR suggestion"
f434df7
Restart CI/CD
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -372,6 +372,7 @@ export class RoSGNode extends BrsComponent implements BrsValue, BrsIterable { | |
| this.callfunc, | ||
| this.issubtype, | ||
| this.parentsubtype, | ||
| this.clone, | ||
| ], | ||
| ifSGNodeBoundingRect: [this.boundingRect], | ||
| }); | ||
|
|
@@ -1322,7 +1323,7 @@ export class RoSGNode extends BrsComponent implements BrsValue, BrsIterable { | |
| let childNodesElements = child_nodes.getElements(); | ||
| if (childNodesElements.length !== 0) { | ||
| childNodesElements.forEach((childNode) => { | ||
| if (childNode instanceof RoSGNode) { | ||
| { | ||
| // Remove if it exists to reappend | ||
| this.removeChildByReference(childNode); | ||
| this.appendChildToParent(childNode); | ||
|
|
@@ -1695,6 +1696,16 @@ export class RoSGNode extends BrsComponent implements BrsValue, BrsIterable { | |
| }, | ||
| }); | ||
|
|
||
| private clone = new Callable("clone", { | ||
anyatokar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| signature: { | ||
| args: [new StdlibArgument("isDeepCopy", ValueKind.Boolean)], | ||
| returns: ValueKind.Object, | ||
| }, | ||
| impl: (interpreter: Interpreter, isDeepCopy: BrsBoolean) => { | ||
| return cloneNode(interpreter, this, isDeepCopy.toBoolean()); | ||
| }, | ||
| }); | ||
|
|
||
| /* Returns the subtype of this node as specified when it was created */ | ||
| private subtype = new Callable("subtype", { | ||
| signature: { | ||
|
|
@@ -1914,3 +1925,55 @@ function addChildren( | |
| } | ||
| }); | ||
| } | ||
|
|
||
| function cloneNode( | ||
| interpreter: Interpreter, | ||
| toBeCloned: RoSGNode, | ||
| isDeepCopy: Boolean | ||
| ): RoSGNode | BrsInvalid { | ||
| let copy = createNodeByType(interpreter, new BrsString(toBeCloned.nodeSubtype)); | ||
|
|
||
| if (copy instanceof RoSGNode) { | ||
| let originalFields = toBeCloned.getFields(); | ||
| let copiedFields = new RoAssociativeArray([]); | ||
| let addReplace = copiedFields.getMethod("addreplace"); | ||
|
|
||
| // Copy the fields. | ||
| for (let [key, value] of originalFields) { | ||
| if (addReplace) { | ||
| addReplace.call( | ||
| interpreter, | ||
| new BrsString(key), | ||
| getBrsValueFromFieldType(value.getType(), value.toString()) | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| let update = copy.getMethod("update"); | ||
|
|
||
| if (update) { | ||
| update.call(interpreter, copiedFields, BrsBoolean.True); | ||
| } | ||
|
|
||
| // A deep clone also copies children. | ||
| if (isDeepCopy) { | ||
| let appendChild = copy.getMethod("appendchild"); | ||
anyatokar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let getChildren = toBeCloned.getMethod("getchildren"); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code would be a little cleaner if we exposed |
||
|
|
||
| if (getChildren && appendChild) { | ||
| let children = getChildren.call(interpreter, new Int32(-1), new Int32(0)); | ||
|
|
||
| if (children instanceof RoArray) { | ||
| for (let child of children.getElements()) { | ||
| if (child instanceof RoSGNode) { | ||
| let childCopy = cloneNode(interpreter, child, isDeepCopy); | ||
| appendChild.call(interpreter, childCopy); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return copy; | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.