Skip to content

Commit 20796b5

Browse files
committed
Refactor JS plugin loading with constants
Introduced constants for JS file names and extensions to avoid repeated string literals. Improved plugin path loading and dependency configuration for better maintainability and clarity.
1 parent f6a5896 commit 20796b5

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

AAInfographics-ProDemo/Demo/AAPlugins/AAStageSeries/AACustomStageChartVC.swift

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,36 @@ class AACustomStageChartVC: UIViewController {
5252
NSString *jsPath = [[NSBundle mainBundle] pathForResource:@"AADrilldown" ofType:@"js"];
5353
self.aaChartView.pluginsArray = @[jsPath];
5454
*/
55-
// 使用正确的Bundle路径和目录结构来加载JS文件
55+
56+
// 定义JS文件名常量,避免重复拼写
57+
let xrangeFileName = "AAXrange"
58+
let customStageFileName = "AACustom-Stage"
59+
let jsExtension = "js"
60+
61+
// 使用正确的 Bundle 路径和目录结构来加载 AAXrange.js 文件
5662
let jsPathXrange: String = BundlePathLoader().path(
57-
forResource: "AAXrange",
58-
ofType: "js",
63+
forResource: xrangeFileName,
64+
ofType: jsExtension,
5965
inDirectory: "AAJSFiles.bundle/AAModules"
6066
) ?? ""
6167

62-
// AACustom-Stage.js位于项目Demo目录中,使用Bundle.main加载
63-
guard let jsPathCustom_Stage = Bundle.main.path(forResource: "AACustom-Stage", ofType: "js") else {
64-
print("Error: Could not find AACustom-Stage.js")
68+
// 使用 Bundle.main 加载位于项目 Demo 目录中的 AACustom-Stage.js 文件
69+
guard let jsPathCustom_Stage = Bundle.main.path(forResource: customStageFileName, ofType: jsExtension) else {
70+
print("Error: Could not find \(customStageFileName).\(jsExtension)")
6571
return
6672
}
6773

74+
// 配置需要加载的插件JS文件路径数组
6875
aaChartView.userPluginPaths = [
6976
jsPathXrange,
7077
jsPathCustom_Stage,
7178
]
7279

73-
// 配置它们的依赖关系
80+
// 配置它们的依赖关系 - 使用文件名常量构建完整文件名
81+
//此处的依赖关系配置非常重要, 关系到 JS 插件的加载顺序
82+
// 例如: AAXrange.js 必须在 AACustom-Stage.js 之前加载
7483
aaChartView.dependencies = [
75-
AADependency("AACustom-Stage.js", on: "AAXrange.js"),
84+
AADependency("\(customStageFileName).\(jsExtension)", on: "\(xrangeFileName).\(jsExtension)"),
7685
// 如果还有其他依赖, 继续在这里添加
7786
// AADependency("pluginC.js", on: "pluginA.js")
7887
]

0 commit comments

Comments
 (0)