Skip to content
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

revert async node flatten #512

Merged
merged 5 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions core/player/src/view/resolver/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ import { DependencyModel, withParser } from "../../data";
import type { Logger } from "../../logger";
import type { Node } from "../parser";
import { NodeType } from "../parser";
import {
caresAboutDataChanges,
toNodeResolveOptions,
unpackAndPush,
} from "./utils";
import { caresAboutDataChanges, toNodeResolveOptions } from "./utils";
import type { Resolve } from "./types";
import { getNodeID } from "../parser/utils";

Expand Down Expand Up @@ -412,16 +408,7 @@ export class Resolver {
);

if (mTree.value !== undefined && mTree.value !== null) {
if (
mTree.node.parent?.type === NodeType.MultiNode &&
Array.isArray(mTree.value)
) {
mTree.value.forEach((v: any) => {
unpackAndPush(v, childValue);
});
} else {
childValue.push(mTree.value);
}
childValue.push(mTree.value);
}

mTree.dependencies.forEach((bindingDep) =>
Expand Down
18 changes: 9 additions & 9 deletions plugins/async-node/core/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ describe("view", () => {
?.lastUpdate;

expect(view?.actions[0].asset.type).toBe("action");
expect(view?.actions[1].asset.type).toBe("text");
expect(view?.actions[2].asset.type).toBe("text");
expect(view?.actions[1][0].asset.type).toBe("text");
expect(view?.actions[1][1].asset.type).toBe("text");
});

test("replaces async nodes with chained multiNodes", async () => {
Expand Down Expand Up @@ -400,7 +400,7 @@ describe("view", () => {
?.lastUpdate;

expect(view?.actions[0].asset.type).toBe("action");
expect(view?.actions[1].asset.type).toBe("text");
expect(view?.actions[1][0].asset.type).toBe("text");
expect(view?.actions[2]).toBeUndefined();
expect(updateNumber).toBe(2);

Expand Down Expand Up @@ -431,9 +431,9 @@ describe("view", () => {
?.lastUpdate;

expect(view?.actions[0].asset.type).toBe("action");
expect(view?.actions[1].asset.type).toBe("text");
expect(view?.actions[2].asset.type).toBe("text");
expect(view?.actions[3].asset.type).toBe("text");
expect(view?.actions[1][0].asset.type).toBe("text");
expect(view?.actions[1][1][0].asset.type).toBe("text");
expect(view?.actions[1][1][1].asset.type).toBe("text");
});

test("replaces async nodes with chained multiNodes singular", async () => {
Expand Down Expand Up @@ -497,7 +497,7 @@ describe("view", () => {
?.lastUpdate;

expect(view?.actions[0].asset.type).toBe("action");
expect(view?.actions[1].asset.type).toBe("text");
expect(view?.actions[1][0].asset.type).toBe("text");
expect(view?.actions[2]).toBeUndefined();

if (deferredResolve) {
Expand All @@ -518,8 +518,8 @@ describe("view", () => {
?.lastUpdate;

expect(view?.actions[0].asset.type).toBe("action");
expect(view?.actions[1].asset.type).toBe("text");
expect(view?.actions[2].asset.type).toBe("text");
expect(view?.actions[1][0].asset.type).toBe("text");
expect(view?.actions[1][1].asset.type).toBe("text");
});

test("should call onAsyncNode hook when async node is encountered", async () => {
Expand Down
14 changes: 11 additions & 3 deletions plugins/async-node/ios/Tests/AsynNodePluginTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class AsyncNodePluginTests: XCTestCase {
let newText1 = val
.objectForKeyedSubscript("values")
.objectAtIndexedSubscript(1)
.objectAtIndexedSubscript(0)
.objectForKeyedSubscript("asset")
.objectForKeyedSubscript("value")
guard let textString1 = newText1?.toString() else { return XCTFail("newText1 was not a string") }
Expand Down Expand Up @@ -152,6 +153,7 @@ class AsyncNodePluginTests: XCTestCase {
let newText1 = val
.objectForKeyedSubscript("values")
.objectAtIndexedSubscript(1)
.objectAtIndexedSubscript(0)
.objectForKeyedSubscript("asset")
.objectForKeyedSubscript("value")
guard let textString1 = newText1?.toString() else { return XCTFail("newText was not a string") }
Expand All @@ -163,7 +165,9 @@ class AsyncNodePluginTests: XCTestCase {
if count == 3 {
let newText2 = val
.objectForKeyedSubscript("values")
.objectAtIndexedSubscript(2)
.objectAtIndexedSubscript(1)
.objectAtIndexedSubscript(1)
.objectAtIndexedSubscript(0)
.objectForKeyedSubscript("asset")
.objectForKeyedSubscript("value")
guard let textString2 = newText2?.toString() else { return XCTFail("newText was not a string") }
Expand All @@ -176,7 +180,9 @@ class AsyncNodePluginTests: XCTestCase {
if count == 4 {
let newText3 = val
.objectForKeyedSubscript("values")
.objectAtIndexedSubscript(3)
.objectAtIndexedSubscript(1)
.objectAtIndexedSubscript(1)
.objectAtIndexedSubscript(1)
.objectForKeyedSubscript("asset")
.objectForKeyedSubscript("value")
guard let textString3 = newText3?.toString() else { return XCTFail("newText was not a string") }
Expand Down Expand Up @@ -256,6 +262,7 @@ class AsyncNodePluginTests: XCTestCase {
let newText1 = val
.objectForKeyedSubscript("values")
.objectAtIndexedSubscript(1)
.objectAtIndexedSubscript(0)
.objectForKeyedSubscript("asset")
.objectForKeyedSubscript("value")
guard let textString1 = newText1?.toString() else { return XCTFail("newText was not a string") }
Expand All @@ -267,7 +274,8 @@ class AsyncNodePluginTests: XCTestCase {
if count == 3 {
let newText2 = val
.objectForKeyedSubscript("values")
.objectAtIndexedSubscript(2)
.objectAtIndexedSubscript(1)
.objectAtIndexedSubscript(1)
.objectForKeyedSubscript("asset")
.objectForKeyedSubscript("value")
guard let textString2 = newText2?.toString() else { return XCTFail("newText was not a string") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ internal class AsyncNodePluginTest : PlayerTest() {
if (count == 2) cont.resume(true) {}
}
}

player.start(asyncNodeFlowSimple)
}
Assertions.assertTrue(count == 2)
Expand Down Expand Up @@ -144,7 +145,9 @@ internal class AsyncNodePluginTest : PlayerTest() {
player.start(asyncNodeFlowSimple)
}
Assertions.assertTrue(count == 2)
Assertions.assertEquals(3, update?.getList("actions")?.size)
print(update?.get("actions"))
Assertions.assertEquals(2, update?.getList("actions")?.size)
cehan-Chloe marked this conversation as resolved.
Show resolved Hide resolved
Assertions.assertEquals(2, update?.getList("actions")?.filterIsInstance<ArrayList<Node>>()?.get(0)?.size)
}

@TestTemplate
Expand Down Expand Up @@ -290,15 +293,14 @@ internal class AsyncNodePluginTest : PlayerTest() {
Assertions.assertEquals(1, count)

view = player.inProgressState?.lastViewUpdate

Assertions.assertNotNull(view)
Assertions.assertEquals(
"action",
view!!.getList("actions")?.filterIsInstance<Node>()?.get(0)?.getObject("asset")?.get("type"),
)
Assertions.assertEquals(
"action",
view.getList("actions")?.filterIsInstance<Node>()?.get(1)?.getObject("asset")?.get("type"),
view.getList("actions")?.filterIsInstance<ArrayList<Node>>()?.get(0)?.get(0)?.getObject("asset")?.get("type"),
)
Assertions.assertEquals(2, view.getList("actions")?.size)
Assertions.assertEquals(2, count)
Expand Down