Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
该 PR 将新增 modifier,可以用来控制「将捕获内容写入结果」的过程,能够配合已有的 filter,增强数据捕获的表达能力。
modifier 的一个典型用例如下(参考了 #33 ):
上述例子中
whenFalsy
的含义是「捕获新的 (key, value) 时,若该字段已有值对应布尔假,则将新的值写入到捕获结果中」。modifier 的语法和用法:
$foo!modifer
$!modifer
DEFAULT_CAPTURE_KEY
(一个字符串常量,可以从 temme 导出)@arrayCapture!modifier
$field!modifier = true;
$bar|someFilter!modifier
$foo!modifier(arg)
$foo!mod1!mod2
$foo!modifier|filter
用 modifier 来解释目前的默认行为
有了 modifier 这个概念之后,目前默认的行为也可以用 modifier 来进行解释,目前默认行为分为两类:
第一类对应值捕获和数组捕获的情况,其 modifier 可以用下面的 add 函数来表示:
另一类对应赋值的情况,其 modifier 可以用下面的 forceAdd 函数来表示:
该 PR 将新增两种内置的 modifier:
add
/forceAdd
(这两个 modifier 的行为都和目前保持一致)。当用户没有显式地指定 modifier 时,将默认使用 add 或 forceAdd 作为 modifier。