Skip to content

Commit

Permalink
Refactored view parser into plugin decomposition
Browse files Browse the repository at this point in the history
  • Loading branch information
mrigankmg committed Jul 24, 2024
1 parent d80fdac commit 0ed9b29
Show file tree
Hide file tree
Showing 25 changed files with 1,022 additions and 848 deletions.
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);

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

0 comments on commit 0ed9b29

Please sign in to comment.