HuolalaTech / hll-wp-therouter-android

A framework for assisting in the renovation of Android componentization(帮助 App 进行组件化改造的动态路由框架)
https://therouter.cn/
Apache License 2.0
1.07k stars 128 forks source link

修改Navigator.with(Bundle)方法实现, 使其更符合该api签名的第一印象. #157

Closed CodeIdeal closed 3 months ago

CodeIdeal commented 3 months ago

这个方法给人的第一印象就是把bundle中的参数按Bundle.putAll(Bundle)的方式放到extras中. 如下:

fun with(value: Bundle?): Navigator {
    extras.putAll(value)
    return this
}

但其内部实现却是在内部定义了一个KEY把Bundle入参, 存到了这个KEY下. 如下:

const val KEY_BUNDLE = "therouter_bundle"

fun with(value: Bundle?) = = withBundle(KEY_BUNDLE, value)

fun withBundle(key: String?, value: Bundle?): Navigator {
    extras.putBundle(key, value)
    return this
}

对于外部调用者来说, 一般情况下并不知道有这个KEY_BUNDLE的键值对. 所以放到extras中的KEY_BUNDLE键值对基本上都是用不到的.

而第一种实现方式, 比较一目了然. 对于外部调用者来说也更加符合自然心理预期.

kymjs commented 3 months ago

需要兼容老版本,不考虑API实现上的变更。 可以通过fillParams实现

TheRouter.build("").fillParams { bundle ->
         bundle.putAll(yourBundle)
     }.navigation()
CodeIdeal commented 3 months ago

首先对您的开源工作表达感谢~

我也是最近组件化改造一个项目用到了therouter, 想当然的用到这个api的时候发现跟我想的实现不太一样. 再参考issue里也有一样疑惑的开发者, 所以有了这个pr.

https://github.com/HuolalaTech/hll-wp-therouter-android/issues/29 https://github.com/HuolalaTech/hll-wp-therouter-android/issues/56 https://github.com/HuolalaTech/hll-wp-therouter-android/issues/80

@kymjs 关于therouter现在的实现(存在KEY_BUNDLE键值对中)的逻辑, 请问是基于什么考虑才这样设计的呢?

这种可能给开发者带来疑惑的api设计是不是可以改一下呢?