在已发布的 Flutter/Dart 包中重构参数名称时如何保持向后兼容性?
How to maintain backwards compabiliby when refactoring param name in published Flutter/Dart package?
我正在为我的第一个开源 flutter 库做贡献,不得不更改一些变量名以使项目连贯。
库所有者指出重构的参数会破坏人们从以前版本更新的应用程序。
他让我使用别名,并将旧变量设置为弃用,以便开发人员可以将其更改为下一个主要版本。
我进行了一些谷歌搜索,但找不到有关如何以专业方式执行此类操作的教程。
我实际上根本找不到有关别名的信息。
有人可以帮助我帮助社区吗?
编辑:构造函数前后
之前:
CarouselSlider({
@required
this.items,
this.viewportFraction: 0.8,
this.initialPage: 0,
this.aspectRatio: 16/9,
this.height,
this.realPage: 10000,
this.autoPlay: false,
this.interval: const Duration(seconds: 4),
this.reverse: false,
this.autoPlayCurve: Curves.fastOutSlowIn,
this.autoPlayDuration: const Duration(milliseconds: 800),
this.updateCallback,
this.distortion: true,
})
之后:
CarouselSlider({
@required
this.items,
this.height,
this.aspectRatio: 16/9,
this.viewportFraction: 0.8,
this.initialPage: 0,
this.realPage: 10000,
this.reverse: false,
this.autoPlay: false,
this.autoPlayInterval: const Duration(seconds: 4),
this.autoPlayAnimationDuration: const Duration(milliseconds: 800),
this.autoPlayCurve: Curves.fastOutSlowIn,
this.enlargeCenterPage: false,
this.pauseAutoPlayOnTouch,
this.onPageChangedCallback,
})
重构名称:
interval --> autoPlayInterval
distortion --> enlargeCenterPage
autoPlayDuration --> autoPlayAnimationDuration
updateCallback --> onPageChanged
interval
属性
的示例
CarouselSlider({
@required
this.items,
this.viewportFraction: 0.8,
this.initialPage: 0,
this.aspectRatio: 16/9,
this.height,
this.realPage: 10000,
this.autoPlay: false,
@Deprecated('use "autoplayInterval" instead')
Duration interval: const Duration(seconds: 4),
Duration autoplayInterval,
this.reverse: false,
this.autoPlayCurve: Curves.fastOutSlowIn,
this.autoPlayDuration: const Duration(milliseconds: 800),
this.updateCallback,
this.distortion: true,
}) : assert(interval == null || autoplayInterval == null, 'Use either "interval" or "autoPlayInterval", but not both.'), autoplayInterval = autoplayInterval ?? interval;
我正在为我的第一个开源 flutter 库做贡献,不得不更改一些变量名以使项目连贯。
库所有者指出重构的参数会破坏人们从以前版本更新的应用程序。 他让我使用别名,并将旧变量设置为弃用,以便开发人员可以将其更改为下一个主要版本。
我进行了一些谷歌搜索,但找不到有关如何以专业方式执行此类操作的教程。 我实际上根本找不到有关别名的信息。
有人可以帮助我帮助社区吗?
编辑:构造函数前后
之前:
CarouselSlider({
@required
this.items,
this.viewportFraction: 0.8,
this.initialPage: 0,
this.aspectRatio: 16/9,
this.height,
this.realPage: 10000,
this.autoPlay: false,
this.interval: const Duration(seconds: 4),
this.reverse: false,
this.autoPlayCurve: Curves.fastOutSlowIn,
this.autoPlayDuration: const Duration(milliseconds: 800),
this.updateCallback,
this.distortion: true,
})
之后:
CarouselSlider({
@required
this.items,
this.height,
this.aspectRatio: 16/9,
this.viewportFraction: 0.8,
this.initialPage: 0,
this.realPage: 10000,
this.reverse: false,
this.autoPlay: false,
this.autoPlayInterval: const Duration(seconds: 4),
this.autoPlayAnimationDuration: const Duration(milliseconds: 800),
this.autoPlayCurve: Curves.fastOutSlowIn,
this.enlargeCenterPage: false,
this.pauseAutoPlayOnTouch,
this.onPageChangedCallback,
})
重构名称:
interval --> autoPlayInterval
distortion --> enlargeCenterPage
autoPlayDuration --> autoPlayAnimationDuration
updateCallback --> onPageChanged
interval
属性
CarouselSlider({
@required
this.items,
this.viewportFraction: 0.8,
this.initialPage: 0,
this.aspectRatio: 16/9,
this.height,
this.realPage: 10000,
this.autoPlay: false,
@Deprecated('use "autoplayInterval" instead')
Duration interval: const Duration(seconds: 4),
Duration autoplayInterval,
this.reverse: false,
this.autoPlayCurve: Curves.fastOutSlowIn,
this.autoPlayDuration: const Duration(milliseconds: 800),
this.updateCallback,
this.distortion: true,
}) : assert(interval == null || autoplayInterval == null, 'Use either "interval" or "autoPlayInterval", but not both.'), autoplayInterval = autoplayInterval ?? interval;