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

View Parser Plugin Decomposition #413

Merged
merged 2 commits into from
Jul 29, 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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -535,4 +535,4 @@ workflows:
requires:
- android_test
- coverage
- build_ios
- build_ios
4 changes: 4 additions & 0 deletions core/player/src/plugins/default-view-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { Player, PlayerPlugin } from "../player";
import {
ApplicabilityPlugin,
AssetPlugin,
MultiNodePlugin,
StringResolverPlugin,
SwitchPlugin,
TemplatePlugin,
Expand All @@ -17,12 +19,14 @@ export class DefaultViewPlugin implements PlayerPlugin {
player.hooks.viewController.tap(this.name, (viewController) => {
viewController.hooks.view.tap(this.name, (view) => {
const pluginOptions = toNodeResolveOptions(view.resolverOptions);
new AssetPlugin().apply(view);
new SwitchPlugin(pluginOptions).apply(view);
new ApplicabilityPlugin().apply(view);
new StringResolverPlugin().apply(view);
const templatePlugin = new TemplatePlugin(pluginOptions);
templatePlugin.apply(view);
view.hooks.onTemplatePluginCreated.call(templatePlugin);
new MultiNodePlugin().apply(view);
});
});
}
Expand Down
9 changes: 8 additions & 1 deletion core/player/src/view/__tests__/view.immutable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import { LocalModel, withParser, PipelinedDataModel } from "../../data";
import { ExpressionEvaluator } from "../../expressions";
import { BindingParser } from "../../binding";
import { SchemaController } from "../../schema";
import { ApplicabilityPlugin, StringResolverPlugin, ViewInstance } from "..";
import {
ApplicabilityPlugin,
AssetPlugin,
StringResolverPlugin,
ViewInstance,
} from "..";
import { NodeType } from "../parser";

const parseBinding = new BindingParser().parse;
Expand Down Expand Up @@ -34,6 +39,7 @@ test("uses the exact same object if nothing changes", () => {
);

new StringResolverPlugin().apply(view);
new AssetPlugin().apply(view);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a lot of these tests have these new plugins added in, it's because these (Multinode + Asset) used to come for free with the parser, right?
Is there appetite in consolidating them to some test util to some default plugin setup like DefaultViewPlugin to avoid having to remember which ones you need to apply in every test

Copy link
Contributor Author

@mrigankmg mrigankmg Jul 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to create a separate test util plugin? Could we not use the DefaultViewPlugin itself?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ya that's possibly fine, it's probably registering more plugins than you need for a lot of tests that are very targeted.
Maybe @KetanReddy can chime in here


view.hooks.resolver.tap("input", (resolver) => {
resolver.hooks.resolve.tap("input", (value, astNode, options) => {
Expand Down Expand Up @@ -205,6 +211,7 @@ test("hardcore immutability", () => {
);

new StringResolverPlugin().apply(view);
new AssetPlugin().apply(view);

const resolved = view.update();

Expand Down
4 changes: 4 additions & 0 deletions core/player/src/view/__tests__/view.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ExpressionEvaluator } from "../../expressions";
import { BindingParser } from "../../binding";
import { SchemaController } from "../../schema";
import {
MultiNodePlugin,
StringResolverPlugin,
SwitchPlugin,
ViewInstance,
Expand Down Expand Up @@ -122,6 +123,7 @@ describe("view", () => {

const pluginOptions = toNodeResolveOptions(view.resolverOptions);
new SwitchPlugin(pluginOptions).apply(view);
new MultiNodePlugin().apply(view);
new StringResolverPlugin().apply(view);

const resolved = view.update();
Expand Down Expand Up @@ -381,6 +383,7 @@ describe("view", () => {

const pluginOptions = toNodeResolveOptions(view.resolverOptions);
new SwitchPlugin(pluginOptions).apply(view);
new MultiNodePlugin().apply(view);
new StringResolverPlugin().apply(view);

const resolved = view.update();
Expand Down Expand Up @@ -735,6 +738,7 @@ describe("view", () => {

const pluginOptions = toNodeResolveOptions(view.resolverOptions);
new SwitchPlugin(pluginOptions).apply(view);
new MultiNodePlugin().apply(view);
new StringResolverPlugin().apply(view);

const resolved = view.update();
Expand Down
17 changes: 16 additions & 1 deletion core/player/src/view/parser/__tests__/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import { BindingParser } from "../../../binding";
import { LocalModel, withParser } from "../../../data";
import { SchemaController } from "../../../schema";
import { NodeType, Parser } from "../index";
import { SwitchPlugin, ApplicabilityPlugin, TemplatePlugin } from "../..";
import {
SwitchPlugin,
ApplicabilityPlugin,
TemplatePlugin,
MultiNodePlugin,
AssetPlugin,
} from "../..";
import type { Options } from "../../plugins/options";
import { ExpressionEvaluator } from "../../../expressions";
import type { DataModelWithParser } from "../../../data";
Expand All @@ -30,9 +36,11 @@ describe("generates the correct AST", () => {
model,
},
};
new AssetPlugin().applyParser(parser);
new TemplatePlugin(options).applyParser(parser);
new ApplicabilityPlugin().applyParser(parser);
new SwitchPlugin(options).applyParser(parser);
new MultiNodePlugin().applyParser(parser);
});

test("works with basic objects", () => {
Expand Down Expand Up @@ -154,8 +162,10 @@ describe("parseView", () => {
model,
},
};
new AssetPlugin().applyParser(parser);
new TemplatePlugin(options).applyParser(parser);
new ApplicabilityPlugin().applyParser(parser);
new MultiNodePlugin().applyParser(parser);
new SwitchPlugin(options).applyParser(parser);
});

Expand Down Expand Up @@ -249,8 +259,13 @@ describe("generates the correct AST when using switch plugin", () => {
return true;
},
} as any);
const multiNodePlugin = new MultiNodePlugin();
const assetPlugin = new AssetPlugin();

const parser = new Parser();
switchPlugin.applyParser(parser);
multiNodePlugin.applyParser(parser);
assetPlugin.applyParser(parser);

test("works with asset wrapped objects", () => {
expect(parser.parseObject(toughStaticSwitchView)).toMatchSnapshot();
Expand Down
Loading