Skip to content

Conversation

@Blueeye1015
Copy link
Contributor

No description provided.

@cssmagic
Copy link
Owner

我想先问个题外话,你觉得什么时候会用到 template.remove() 这个 API?

Copy link
Owner

Choose a reason for hiding this comment

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

至少这一行 todo 是可以删掉的。

@cssmagic
Copy link
Owner

好的,现在可以合了。不过还是想听听你的回答:

我想先问个题外话,你觉得什么时候会用到 template.remove() 这个 API?

@Blueeye1015
Copy link
Contributor Author

@cssmagic 其实这个问题我上个礼拜思考了很久。我一开始完善这个API的目的只是因为这个API留出来了却没有实现,我觉得有add就应该有remove就去做了。之后又深入思考了一下,觉得现在的代码是每次add和render之后会将数据添加到_cacheTemplate和_cacheCompiledTemplate之中,然后就不管它们了,用户无法操作或者修改cache中的数据,cache中的数据势必会越来越多(我觉得会影响性能)。所以无论是用来释放cache中的数据,还是用来让用户在必要时修改模板数据,我觉得增加一个remove的API还是有必要的。

@cssmagic
Copy link
Owner

从 API 的对称性上来说,似乎需要有一个 .remove()。但我又不是很确定它是否存在真实的使用场景。

比如,用户无法直接修改 cache,但可以通过重复 .add() 来覆盖同名模板(说到这里,我刚发现了 .add()一个 bug,无法做到完全覆盖,这个要修);用户无法清除 cache,可能导致性能问题——确实有这种可能,但我不确定什么量级才会出现性能问题。

在想清楚这些疑问之前,我没有实现 .remove() 这个 API。所以在合并这个 PR 之前,我也希望你可以想得更深入一些——找到足够的证据说服我,或说服你自己。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants